2

I've been trying to set up a USART on an ATSAMD21E18A-MU and have been running into issues.

Currently, I've narrowed the problem down to the fact that CTRLB.RXEN and CTRLB.TXEN never go high after enabling the USART.

My hardware has TX on PA04 and RX on PA06. I'm trying to use OSC8M as a source for Generator 3, and Generator 3 for SERCOM0_CORE. Trying to get everything relevant running at 8MHz.

I'm trying to set up 8n1, asynchronous mode, fractional baud rate, 16x oversampling, etc.

See this gist for the full example.

From the datasheet, info on CTRLB.RXEN reads:

Writing '1' to CTRLB.RXEN when the USART is disabled will set CTRLB.RXEN immediately. When the USART is enabled, CTRLB.RXEN will be cleared, and SYNCBUSY.CTRLB will be set and remain set until the receiver is enabled. When the receiver is enabled, CTRLB.RXEN will read back as '1'.

(There is similar text for CTRLB.TXEN.)

I spin check these flags after I enable the USART (line 115 and 116 in the gist) but they never go high.

Simple question: what am I missing?

I feel like I picked over the datasheet with a fine toothed comb...

Any and all help appreciated.

EDIT: discovered an issue with my use of PORT_WRCONFIG_PINMASK in the example code (e.g. PORT_WRCONFIG_PINMASK(4) vs. PORT_WRCONFIG_PINMASK(1<<4)) but currently does not resolve the issue.

jkiv
  • 182
  • 1
  • 1
  • 8
  • My guess is there's some clock enable or peripheral enable bit that was missed. Usually these digital comm peripherals need you to feed it a clock signal, and/or turn on some enable bit. – gregb212 May 01 '20 at 21:06

2 Answers2

3

Digging deeper, the issue was that CTRLA.MODE was set to external clock source (i.e. XCK on PAD[2] where no clock is connected), rather than an internal clock source.

Additionally, CTRLA.DORD was set to MSB-first, whereas my linux endpoint prefers LSB-first.

The gist has been updated for a working "Hello, World!"

jkiv
  • 182
  • 1
  • 1
  • 8
  • I'm glad you posted the solution. I looked through the code but couldn't see what the issue was. – JYelton May 03 '20 at 03:35
-2

Almost all microcontroller have the ADC input pins set as analog by default, you need to set the pins that you need for the uart as digital.