With the latest GCB supplied rs232.h software serial library, the normal / invert does not work as expected. When "normal" is used the data is always incorrect because the idle state is not set and the start and stop bits are inverted. The only way to get correct "normal" rs232 data output is program as in the example below:
#define SendAHigh Set PORTB.6 on
#define SendALow Set PORTB.6 off
dir portb.6 out
InitSer 1, r9600, 1, 8, 1, none, invert 'must be invert!
Note that "invert" must be used to get "normal" data.
This will send data in "normal" or non-inverted RS232 where the data line idles high, the start bit is low, a data "1" is high, and a data "0" is low. The stop bit returns the data line to its high data state.
With the current rs232.h, in order to send RS232 data "inverted" the defines must be swapped and the normal/ invert remains "invert" as in the example below:
#define SendAHigh Set PORTB.6 off
#define SendALow Set PORTB.6 on
dir portb.6 out
InitSer 1, r9600, 1, 8, 1, none, invert 'must be invert!
This will send inverted RS232 data correctly, where data line idles low, the start bit is a high, a data "1" is low and a data "0" is a high. The stop bit returns the data line to its low idle state.
In the attached library, I have corrected the problem with "invert". Now the defines do not need to be swapped, and "invert" and "normal" will work as expected.
The bit delays for PICs were changed for better tx accuracy. TX accuracy is now within about 2% or less.
To use this library the defines must be:
#define SendAHigh Set PORTB.6 on ;do not change (use invert or normal in InitSer)
#define SendALow Set PORTB.6 off ;do not change (use invert or normal in InitSer)
These defines should really not be needed in the main program, as the user should not have to define the data bit states. These should ideally be done in the library. The only define that should be needed is for the TX pin. However, at this point I have kept them in the main program.
A problem could arise with older programs where the defines were swapped in order to get correct data. I am working on ways around that for compatibility with older programs, but that may not be possible as older programs had to use "invert" to get correct "normal" data.
No changes were made to the receive timings or to any AVR timings. Timings were only changed for PIC.
I am submitting this library for peer review and testing, and await feedback before I continue with further changes.
@Hugh. What is the best method to throw an error message to handle this type of backwards compatibility issue? Can we force an error message if a certain condition occurs?
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
With the latest GCB supplied rs232.h software serial library, the normal / invert does not work as expected. When "normal" is used the data is always incorrect because the idle state is not set and the start and stop bits are inverted. The only way to get correct "normal" rs232 data output is program as in the example below:
Note that "invert" must be used to get "normal" data.
This will send data in "normal" or non-inverted RS232 where the data line idles high, the start bit is low, a data "1" is high, and a data "0" is low. The stop bit returns the data line to its high data state.
With the current rs232.h, in order to send RS232 data "inverted" the defines must be swapped and the normal/ invert remains "invert" as in the example below:
This will send inverted RS232 data correctly, where data line idles low, the start bit is a high, a data "1" is low and a data "0" is a high. The stop bit returns the data line to its low idle state.
In the attached library, I have corrected the problem with "invert". Now the defines do not need to be swapped, and "invert" and "normal" will work as expected.
The bit delays for PICs were changed for better tx accuracy. TX accuracy is now within about 2% or less.
To use this library the defines must be:
These defines should really not be needed in the main program, as the user should not have to define the data bit states. These should ideally be done in the library. The only define that should be needed is for the TX pin. However, at this point I have kept them in the main program.
A problem could arise with older programs where the defines were swapped in order to get correct data. I am working on ways around that for compatibility with older programs, but that may not be possible as older programs had to use "invert" to get correct "normal" data.
No changes were made to the receive timings or to any AVR timings. Timings were only changed for PIC.
I am submitting this library for peer review and testing, and await feedback before I continue with further changes.
Last edit: William Roth 2014-07-19
Good stuff.
@William. I can test after my vacation.
@Hugh. What is the best method to throw an error message to handle this type of backwards compatibility issue? Can we force an error message if a certain condition occurs?