Itsy Bitsy M4 / SAMD51 inverted UART

I have a small project where I need an inverted UART signal and I wanted to solve it with my new Adafruit Itsy Bitsy M4 (SAMD51). I read that it should be possible to invert both RX and TX. I have found that this requires setting bit 10 (RXINV) of the CTRLA register to 1 and bit 9 (TXINV) of the CTRLA register to 1 as well.

Sounds easy, but I have no idea how to do it. I have never dealt with registers. After googling for a while I'm a bit desperate.

Does anyone have any experience with inverted UART on a SAMD51 or know how to change the CTRLA register?

Thanks a lot!

Hi @mandelo

The UART transmit and receive invert bit only invert the data, the start, parity and any stop bits remain unchanged.

To invert the transmit and receive data, it's first necessary to disable the UART, since the CTRLA registers is enable protected, for example on SERCOM2:

SERCOM2->USART.CTRLA.bit.ENABLE = 0;          // Disable the UART
while (SERCOM2->USART.SYNCBUSY.bit.ENABLE);   // Wait for synchronization
SERCOM2->USART.CTRLA.bit.TXINV = 1;           // Invert the Tx data
SERCOM2->USART.CTRLA.bit.RXINV = 1;           // Invert the Rx data
SERCOM2->USART.CTRLA.bit.ENABLE = 1;          // Enable the UART
while (SERCOM2->USART.SYNCBUSY.bit.ENABLE);   // Wait for synchronization
1 Like

Great!
Thank you!

Humph. That doesn't sound nearly as useful as I thought it was. :frowning:

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.