1

I'm working with an ATMEGA328 chip on a breadboard. I'm using the Arduino library for easy coding within Atmel Studio (and an ISP MKii for programming). I have no way to easily debug my code, so I came up with the idea to use the RX and TX pins of the 328 to print out feedback and plug them into my Arduino Mega, since it has multiple UARTs, which I can then listen on port 3 and output the results through 0 to the serial monitor. Only one problem... I'm only getting garbage back...


Here's my code on the Atmega328 - just send a simple hello

#include <Arduino.h>

int testLED = 2;

void setup() {
   Serial.begin(9600);
   delay(3000);
   pinMode(testLED, OUTPUT);
}

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

...And this is the Arduino Mega - receive the hello and print it to the serial monitor

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

Ready...
bytes available: 12
⸮TY)⸮TY)⸮TY)
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)

Some extra details.

  • ATMega328 chip on a breadboard 16MHz External Crystal
  • Fuses: Extended 0xFF, High 0xD9, Low 0xE7
  • Pin 3 of ATMega328 connected to pin 15 of Arduino Mega
  • 9600 baud rate selected on serial monitor

Question: Why am I receiving garbage instead of the expected 'hello'?

  • Turns out the 16MHz crystal was actually a 25MHz crystal.... – bwoogie Dec 23 '17 at 5:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.