cancel
Showing results for 
Search instead for 
Did you mean: 

How can I send more than 3 CAN messages in a row using HAL library

Posted on October 07, 2017 at 14:24

I am using the latest HAL library to transmit CAN messages using interrupts. I am aware of the 3 mailboxes limitation but I would like to know if someone had implemented a queue system that transmit most of the CAN messages.

I tried to follow the HAL_StatusTypeDef HAL_CAN_Transmit_IT(CAN_HandleTypeDef* hcan) function.

So putting counters on every return of this function equals 1 vs the TX interrupt, my counters are not matching.

To enable the TX interrupts, I simply set:

    HAL_NVIC_SetPriority(CAN1_TX_IRQn,3, 0);

    HAL_NVIC_EnableIRQ(CAN1_TX_IRQn);

Do I need to set another flag? from my understanding, using the HAL_CAN_Transmit_IT will generate an interrupt, is that correct?

#hal #can
12 REPLIES 12
Posted on October 11, 2017 at 06:36

I don't use the HAL transmitter software system itself, I just load the buffers and trigger the flags.

this leaves the interrupts in place and very little software overhead for every frame.

maybe you are looking for something like this ;

if (((CAN->TSR & CAN_TSR_TME0) == CAN_TSR_TME0) ||
 ((CAN->TSR & CAN_TSR_TME1) == CAN_TSR_TME1) ||
 ((CAN->TSR & CAN_TSR_TME2) == CAN_TSR_TME2)�?�?�?)
{
 if(HAL_CAN_Transmit_IT(&CanHandle) != HAL_OK)
 {
 
 cantx_counter++;
 return 0;
 }
 else
 {
 packetsend_counter++;
 return 1;
 }
}�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?�?

Posted on October 13, 2017 at 09:21

Thanks everybody. I found another function where I wasn't pushing the CAN message to the Queue, instead I was trying to transmit and that was causing the confusion on available Mailboxes.

My CAN TX Queue is working fine. Now that I have that I am dealing with my CAN RX Interrupt stops firing when I start sending CAN messages from another node too fast (every 4 ms) Interrupt works a short time and then it doesn't trigger.

I will need to open another post related to this issue

Posted on October 16, 2017 at 02:00

Hey

talledo.jean

‌,

looks like you're working on a C++ CANOpen stack? I might be interested in participating in my free time. Is the source open by any chance?

Cheers!