Using an Arduino Mega as a Debug Tool


hi, not sure if hardware or programming issue, i'll put here now...

i'm working atmega328 chip on breadboard. i'm using arduino library easy coding within atmel studio (and isp mkii programming). have no way debug code short of flashing led, came idea use rx , tx pins of atmega328 print out feedback , plug them arduino mega, since has multiple uarts, can listen on port 3 , output results through 0 serial monitor. 1 problem... i'm getting garbage back...

here's code on atmega328 - send simple hello

code: [select]
#include <arduino.h>

int testled = 2;

void setup() {
   serial.begin(9600);
   delay(3000);
   pinmode(testled, output);
}

void loop() {
  serial.println("hello");
  delay(1000);
}


...and arduino mega - receive hello , print serial monitor

code: [select]
void setup() {
serial.begin(9600);
serial3.begin(9600);
delay(1000);
serial3.settimeout(500);
delay(1000);
serial.println("ready...");

}

void loop() {
  serial.print("bytes available: ");
  serial.println(serial3.available());
    if(serial3.available() > 0) {
      string s = serial3.readstring();
      serial.println(s);
    }

  delay(3000);
}


the output

code: [select]
ready...
bytes available: 20
⸮ty)⸮ty)⸮ty)⸮t[)⸮t[)⸮t[)
bytes available: 20
⸮t[)⸮t[)⸮ty)⸮ty)⸮ty)⸮ty)
bytes available: 20
⸮ty)⸮t[)⸮t[)⸮t[)⸮t[)⸮ty)
bytes available: 20
⸮t[)⸮ty)⸮t[)⸮ty)⸮ty)⸮ty)
bytes available: 20
⸮t[)⸮ty)⸮t[)⸮t[)⸮t[)⸮t[)
bytes available: 20
⸮ty)⸮t[)⸮ty)⸮t[)⸮ty)⸮t[)
bytes available: 20
⸮ty)⸮t[)⸮ty)⸮t[)⸮ty)⸮ty)

etc...


some details:
  • atmega328 chip on breadboard
  • 16mhz external crystal
  • fuses: extended 0xff, high 0xd9, low 0xe7
  • pin 3 of atmega328 connected pin 15 of arduino mega
  • 9600 baud rate selected on serial monitor



things i've tried:
connect atmega328 chip serial ports 1-3 on mega
other baud rates (faster , slower)
10k pullup resistors on tx/rx lines
softwareserial (on atmega328 side)
using 8mhz internal osc (with , without div8)
make sure vcc has bypass caps
power arduino / power separately (yes ground connected between both)


question: why receiving garbage instead of expected 'hello'?

seems obvious better ask did not mention : have crossed wires?
rx --> tx , tx --> rx

(edit - sorry did pin3 pin 15. there no pullup needed. yes gnd needs connected)

as side note - best way handle serial not using readstring nor delay() (you might saturate receive buffer)  see serial input basics


Arduino Forum > Using Arduino > Programming Questions > Using an Arduino Mega as a Debug Tool


arduino

Comments

Popular posts from this blog

Error compiling for board Arduino/Genuino Uno.

Installation database is corrupt

esp8266 (nodemcu 0.9) client.write très lent ???