Serial Communications using the Internal Clock
Dave Hein
Posts: 6,347
The internal clock is not very accurate, which causes problems with serial communication. I am able to get serial communications to work with the internal clock by first measuring the actual clock rate generated. I do this by running a program that toggles an LED every 10 seconds, and then measure the actual time between toggles using a stop-watch. I normally run this for 10 toggles to get a more accurate measurement.
I measured a frequency of 4.48 MHz for the SX chip I am using when I set it for 4 MHz. I then derive the number of clock cycles per bit as follows:
CLOCK_RATE = 4480000
BAUD_RATE = 9600
SERIAL_CYCLES = ((CLOCK_RATE+(BAUD_RATE/2))/BAUD_RATE)
My serial I/O routines use the value of SERIAL_CYCLES to generate a delay between each bit. Once I implemented this scheme I haven't seen a problem with serial communications. The drawback to this method is that you have to determine a new value for CLOCK_RATE for each chip that is used.
Dave Hein
I measured a frequency of 4.48 MHz for the SX chip I am using when I set it for 4 MHz. I then derive the number of clock cycles per bit as follows:
CLOCK_RATE = 4480000
BAUD_RATE = 9600
SERIAL_CYCLES = ((CLOCK_RATE+(BAUD_RATE/2))/BAUD_RATE)
My serial I/O routines use the value of SERIAL_CYCLES to generate a delay between each bit. Once I implemented this scheme I haven't seen a problem with serial communications. The drawback to this method is that you have to determine a new value for CLOCK_RATE for each chip that is used.
Dave Hein
Comments
·· One other potential problem I see is that you could experience issue during thermal changes.· I can't see the internal RC being stable at different temperature extremes...Say going from a refrigerated condition to the area warming up to say 80 degrees.· Have you tested it in similar conditions?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Tech Support
csavage@parallax.com
Dave
where each message has a few preamble bytes·to determine the baud rate.
A source with autobaud detection is here:
http://www.sxlist.com/techref/scenix/lib/io/osi2/serial/duart_0412.src?key=autobaud&from=%2Ftechref%2Fscenix%2Findex%2Ehtm
regards peter
For non-critical application that is a good idea.
If your using SX/B it would be really easy just do:
Bean
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Cheap 4-digit LED display with driver IC·www.hc4led.com
Low power SD Data Logger www.sddatalogger.com
"You're braver than you believe, stronger than you seem, and smarter than you think" Christopher Robin to Pooh
·