UART on expansion board 1LC
-
Hi,
I'm trying to implement a serial communication on the TOOL1LC firmware (v3.5.3) using pins PA09 and PA12 (io0.in/out). So far, I managed to transmit what I want from the board, but I can't receive proper data and I don't understand why.
Regarding the ports configuration and serial initialization this is what I've done:
void SerialPortInit(AsyncSerial*) noexcept { SetPinFunction(PortAPin(9), GpioPinFunction::D); // Rx on PA09, sercom 2, pad 1 SetPinFunction(PortAPin(12), GpioPinFunction::C); // Tx on PA12, sercom 2, pad 0 } void SerialPortDeinit(AsyncSerial*) noexcept { pinMode(PortAPin(9), PinMode::PIN_MODE_NOT_CONFIGURED); pinMode(PortAPin(12), PinMode::PIN_MODE_NOT_CONFIGURED); } AsyncSerial uart0(2, 1, 128, 128, SerialPortInit, SerialPortDeinit); extern "C" void SERCOM2_Handler() { uart0.Interrupt(); }
Then,
uart0
is used in a handler to send and read data periodically (it is spinning in the heating task, so every 250ms).Sending data works perfectly with method
uart0.write(..)
, but when data isuart0.available()
I get only0s
(null) when Iuart0.read()
.I know uart is officially not supported on expansion boards, but this is the only option I have to communicate with the device I want to use. And I don't have the knowledge to build a completely new expansion board using a SammyC21, in terms of electronics.
Any help or hint would be greatly appreciated.
Thanks -
@JoA-RHU I don't know whether this is the cause of your issue, however you also need to set the priority of the UART interrupt to NvicPriorityUart. This is normally done in Platform::InitialiseInterupts.
-
@dc42 Indeed, this is done in
Platform::InitialiseInterupts
like that:... #elif SAMC21 NVIC_SetPriority(StepTcIRQn, NvicPriorityStep); NVIC_SetPriority(CAN0_IRQn, NvicPriorityCan); # if NUM_SERIAL_PORTS >= 1 NVIC_SetPriority(Serial0_IRQn, NvicPriorityUart); # endif ...
And I've defined
Serial0_IRQn
asSERCOM2_IRQn
. -
@JoA-RHU What baud rate are you using? There is a 10K/2n2 deglitch filter formed by R4 and C28 on IO0_IN. The time constant is 22us so baud rates above 9600 or perhaps 19200 are unlikely to work.
-
@dc42 I see... I was trying to use the default baud rate of the device I communicate with, which is 57600. I tested with 9600 and it seems much better!
Thank you very much! I would never have thought of such a thing...