2017-06-14 03:45 AM
I'm using an STM32F4 Discovery and an MCP2562 transceiver. I have CAN working using the CAN2 port.
In my implementation, I'm sending several CAN messages inside a timer interrupt. I'm using the HAL function HAL_CAN_TRANSMIT_IT. It works fine until I try to send 3 or more messages in a row, in that case HAL_CAN_TRANSMIT_IT returns an error. How should I work around this?
I thought about using HAL_CAN_TRANSMIT, which has the option to use a timeout, but since this is called inside an interrupt, this should be avoided.
Any help will be greatly appreciated.
#hal #can #stm32f4-discovery2017-06-14 04:23 AM
Hi
Loureiro.Rui
, Did you try to see some exmples on theSTM32_F4_*** files, wich probably has projects using the CAN communication ?Regards ,
Nicolas2017-06-14 04:34 AM
Hi !
I can't comment on the F4 but if the peripheral is the same as F0, then you have only 3 Tx mailboxes. So if you want to send more than 3 CAN messages in a row, you can either poll the mailboxes until one becomes free again or use a circular buffer with interrupts if you don't want to waste CPU cycles.
2017-06-14 06:55 AM
I'm using the STM32F1 family and it's the same things (3 Tx Mailboxes), so maybe the STM32 F4 has the same abilities.
2017-06-14 07:24 AM
Didn't check it, but I'm pretty sure it's the same peripheral.
IMHO another case where the Cube SW structure clashes with the application requirements.
I would organize CAN send receive and send in a SW queue, and just trigger the send from an interrupt (i.e. setting a flag for the queue to start the send).
The queue could be polled/processed at regular intervals (timer interrupt), or event driven, depending on your requirements.
Advantage is, this SW queue can be arbitrary long, not restricted to the implemented hardware.
I have no implementation for STM32 here, though.
2017-06-15 12:31 AM
Add more mailboxes in software. See if there are any software mailboxes marked for transmit on tx complete irq.