Unreliable can wth STM32F0 and HAL, perfectly reliable with mbed
- June 21, 2020
- 3 replies
- 1450 views
I'm having trouble reliably sending CAN messages using the HAL functions (STM32CubeIde) in the way I found in some examples. In those, a message is sent by calling HAL_CAN_AddTxMessage(), but for me that causes nothing to be sent unless I manually clear the INRQ bit with
CLEAR_BIT(hcan.Instance->MCR, CAN_MCR_INRQ);This way the message gets sent, but soon enough I start getting transmission errors in all mailboxes (TERR bits in CAN_TSR) and message sending stops. It'll occasionally recover with ABOM but still, I must be missing something as this can't be the right way to do it.
My hardware consists of a nucleo-f042k6 connected to a MCP2562 tranciever which is talking to a USB-CAN adapter that is not in silent mode. The bus is terminated correctly, and with code generated using the mbed online IDE CAN is completely solid.
Can configuration (MCR + BTR) is the same for both the STM32Cube generated initialization and what I read from the registers when running the working mbed code. More info in the attached code.
Thanks for any hints to what I'm missing here. Do I need to manually twiddle some bits which the mbed code does automatically?
