There is Arduino Mega2560 and AT328P chip on a breadboard. I try to send and receive characters between them, but fail: the receiving program in Mega2560 waits forerver.
Mega2560 sends and receives succesfully, when rx0 is connected to tx0 of its own (digital pin 0 to pin1).
Breadboard chip sends and receives succesfully, when rx is connected to tx of its own (digital pin 0 to pin1).
There are the following connections between them:
- ground to ground
- 5V to 5V
- rx0 of mega to tx of breadboard chip
- tx0 of mega to rx of breadboard chip
Mega2560 gets its power from USB.
The echoing program in Mega2560 is like this:
// serial port echo
void setup(){
Serial.begin(115200);
}
void loop(){
char c1;
while(Serial.available() <= 0){}
c1 = Serial.read();
Serial.write(c1);
}
(actually there was some lead blinking code above, which I removed to make things simpler for readers)
The program in breadboard sends and receives the same character all the time:
// serial port feedback test. tx connected to rx
// if led remains on, nothing is received
// 1 sec blinking: wrong character received (and blink forever)
// fast blinking: ok
// tx and rx tied together or another mcu has serialecho pgm
long int baudrate = 115200; //2400;
const int ledpin1 = 8;
void setup(){
Serial.begin(115200);
pinMode(ledpin1, OUTPUT);
}
void loop(){
char c1 = 'a';
char c2;
digitalWrite(ledpin1, HIGH); // on, if reading ok
Serial.write(c1);
delayMicroseconds(100);
while(Serial.available() <= 0){}
digitalWrite(ledpin1, LOW);
c2 = Serial.read();
if(c1 != c2){
while(true){
//blink(1, 500);
}
}
}
The breadboard AT328P is on the left of the image (to the right there is Bluetooth circuits which are not receiving/sending during the test).
Similar programs work as expected, when the breadboard chip is replaced with an Arduino Uno. Even bluetooth-- Mega2560 work well .
The chip AT328P runs other programs well, blinks leds and does analog conversions as expected.
I have no real oscilloscope or logic analyzer available now and start feeling frustrated when I cannot even imagine, what could be wrong. Ideas?