earlephilhower / arduino-pico

Raspberry Pi Pico Arduino core, for all RP2040 and RP2350 boards
GNU Lesser General Public License v2.1
2.06k stars 431 forks source link

UART1 prints garbage. #1693

Closed the-maldridge closed 1 year ago

the-maldridge commented 1 year ago

I'm troubleshooting a problem with using Serial2/UART1 to provide an extra serial port in a design. When using the following test program, I get garbage in my console that appears to be the right number of bytes. At this point I'm inclined to think that there's something wrong in the underlying code that drives Serial2, so I'm looking for any help in figuring out what went wrong here.

void setup() {
  pinMode(LED_BUILTIN, OUTPUT);
  Serial2.setTX(4);
  Serial2.setRX(5);
  Serial2.begin(300);
}

void loop() {
  digitalWrite(LED_BUILTIN, HIGH);
  delay(250);
  digitalWrite(LED_BUILTIN, LOW);
  delay(250);
  Serial2.println("A");
}
maxgerhardt commented 1 year ago

I can very easily check this with a logic analyzer on GP4 to see what's being output electrically. Maybe the small baudrate is a problem because it can't find a right clock divider or delay number of for it? Did you test with another one like 9600?

the-maldridge commented 1 year ago

The problem occurs with all baud rates I have yet tried. My preference of course would be to run at 9600 or higher, but when I encountered problems, I started clocking downwards to see if this was a speed related issue.

earlephilhower commented 1 year ago

I suggest you check your UART for proper configuration. Default is 8N1, and with your example at 300bps I get a nice, decoded A\r\n using my logic analyzer. Same at other baud rates:

image

maxgerhardt commented 1 year ago

I can confirm the same results, compiling and uploading your sketch and feeding the GP4 signal to the RX of a USB-UART adapter (with the same common GND) gives the expected results at 300 baud.

This may mean that your hardware or hardware connections are faulty instead.

grafik