Thursday 22 September 2016

arduino - Speed problems in homemade RS232-to-TTL converter board


I'm still trying to debug this RS232-to-TTL converter board that I've made, shown below.



My RS232-to-TTL board and my setup


Now I think I've narrowed down the problem to speed:



  • it works fine at 57,600 baud;

  • but it inserts some errors during comm at 115,200 baud.


This time I tested the board with a simple echo firmware below, which basically echos back whatever comes into the serial port.


void setup() { 
Serial.begin(57600);
}

void loop() {
if (Serial.available() > 0) {
Serial.write(Serial.read());
}
}

At 57,600 baud, it returns a series of B chars without errors, as below.


BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB

BBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBBB

At 115,200 baud, a few errors make into the output.


BBÂBBBBBBBBBBBBBBBBBBBBBBBBBBBBBÂBBBBBBBBBBBBBBBBÂBBBBBBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBÂBBBBBBBBBBBBBBBBÂBBBBBBBBBBBBBBBBÂBBBBBBBBBBBBÂBBBBBBBBBBBBBBBBBBBBBBB
BBBBBBBBBBBBBBBBÂBBBBBBBBBBBBBBBBÂBBBBBBBBBBBBÂBBBBBBBBBBBBBBBBÂBBBBBBBBBBBBBB
BBBBBBBBÂBBBBBBBBBBBBBBBBBBBBBBBBBBBBBÂBBBBBBBBBBBBBBBBÂBBBBBBBBBBBBBBBBBBBBBB

The error rate seems to be fairly constant and it's always the same. Note that the difference between B and  ASCII char codes is just one bit negated and another one shifted one position left.


B - 01000001

 - 11000010
^ ^

The MAX232 datasheet says it works up to 120 kbps, so I think my board is causing the problem.


So, that's the new evidence I've got so far. My question is: What would be the likely reason for the problems with my converter?


Here's a picture of my board design, if that helps. Disregard the TX and RX LEDs, I've disconnected them.


enter image description here



Answer



It is probably the crystal on your target board.


A 16 MHz rock probably can't generate a clock for 115200 baud exactly enough. Over a long enough continuous stream of characters, the clocks on the two devices will slide out of sync. Eventually, you will get a framing error and a bad character, and the devices will resynchronize on the next falling edge (START bit).



The fact that your errors are roughly periodic tends to support this hypothesis. I saw a similar problem (at much lower speed) on a modem line to a minicomputer many, many years ago.


If you can feed your UART with a clock that is exactly correct for 115200, do that, and see what happens. (If you have access to a really good, EXPENSIVE, signal generator, use that.)


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...