Hi all,
So I'm having some problems reading serial data from an Atmega328 (from Sparkfun's Razor 9DoF IMU) through a logic level converter into an Arduino Mega. I loaded the Atmega328 with some basic code to continuously print 1 through 100 over serial (I hooked it directly up to the computer and the data looks fine, I don't think the problem is here).
void setup(){
Serial.begin(19200);
}
void loop(){
for(int i = 0; i<100; i++){
Serial.println(i);
}
}
The Atmega328 runs at 3.3v so I route the serial data through Sparkfun's logic level converter (
http://www.sparkfun.com/products/8745). On the logic level converter I connected the grounds together (everything is on a common ground), the LV pin to the 3.3v output on the Arduino Mega, the HV pin to the 5v output on the Arduino Mega, and I connected all the TX/RX pins up to their respective ports (everything is connected correctly on this board so I don't think the problem is here either).
On the Arduino Mega I put code to just retransmit all the data from Serial3 to Serial:
void setup(){
Serial3.begin(19200);
Serial.begin(57600);
}
void loop(){
if(Serial3.available() > 0)
{
Serial.write(Serial3.read());
}
if(Serial.available() > 0)
{
Serial3.write(Serial.read());
}
}
I originally had the Atmega328 transmitting at 57600 baud but all I got was a bunch of garbage (and a few numbers). In the comments on the logic level converter product page, someone said something about it attenuating signals so I lowered the baud to 19200 and now the data looks alright, except, approximately every 195 numbers (565 bytes with the newline characters?) I get a load of garbage:
76
77
78
79
80
x×ô
Þ}_¼¾lòæ·Ýÿù¿úúþ:Kû¿r÷ñ
ç·ç¾ûãýû¼öëÚ¿Mß¿?~N~sû®ÏÇ¿~ãçýî=]î~ôë¯w³ny¿¿Ýiááõ{wzó|Ïçç³ÏÏÝt~ýï&w¯=Oý¶n~\þý2ÿüÓ~g¿~ôûî6ÿßùç}éÛ~ú÷nùïûGæÏnÃç×îv§ëÇ÷¯·ßÓöÏõîm·~wÜþxï×÷w®/íÓ÷Þ]ûiEÕ}-÷Ï'ÿÏwߨý}ùþ=«çå^·òîûGíîxûã7£ÝC¡SH¨ºj
58
59
60
61
62
It's odd because it does this really consistently at around every 195 numbers. I don't think i'm overrunning the buffers in the Arduino Mega because I'm printing to the computer at 57600 baud and the Atmega328 is only printing at 19200 baud.
If anyone's had experience with logic level converters, is there a maximum baud i can transmit at over them? I can't really pinpoint the problem to hardware or software so if anyone has any ideas, they'd be much appreciated!
Thanks,