STM32F303VET - issue in transmitting CAN messages
I am having an issue in transmitting CAN messages, my situation is the following:
There is an interrupt function for RX messages from CAN1, when a message is received, it sets a flag.
The baud rate of the RX message is 10ms and they are being sent over the software PCAN.
struct
{
volatile uint8_t transmit_data;
}Flags;
void can1_RxCallback()
{
Flags.transmit_data = 1;
}
In the main function in the while-loop, this flag is compared, if it is high, it executes a code to transmit data over CAN-Bus.
while (1)
{
if (1 == Flags.transmit_data)
{
tx_data();
}
}
void tx_data(void)
{
//delay(1); //Non interrupt delay in ms
can_transmit(&can, CanMessObj[nr].MessageID, 0, (uint8_t *)CANTrxBuffer[nr].Data, CanMessObj[nr].Length);
Flags.transmit_data = 0; //Reset Flag
}
void can_transmit(can_Interface_t* canInterface, uint32_t Id, uint32_t ide, uint8_t data[8], uint8_t length)
{
uint32_t mailbox;
canInterface->txMsg.IDE = ide;
canInterface->txMsg.StdId = Id;
canInterface->txMsg.ExtId = Id;
canInterface->txMsg.DLC = length;
HAL_CAN_AddTxMessage(canInterface->canChannel, &canInterface->txMsg, data, &mailbox);
}
The issue is some TX messages are not being sent, however, when I add the 1 ms delay, it works perfectly. But I want to avoid using delay.
So, to understand if the problem was in the transmission baud rate, I implemented a Timer interrupt for each 1ms and set the flag there instead of in the CAN interrupt and commented out the "delay(1)" in the function tx_data().
In this configuration, all TX messages were sent correctly.
void TIM7_IRQHandler(void)
{
Flags.transmit_data = 1;
}
As the Timer interrupt is 10x faster than the CAN interrupt, I concluded that the issue is not how often the CAN messages are being transmitted. However, at the current point, I have no idea what could be leading to this issue, basically, I just changed where the flag is being set, nothing else.
Someone could help me to understand what might be causing this issue for transmitting?
CAN baud rate is: 250Kb
MCU: STM32F303VET
For checking the CAN messages and transmitting the CAN messages to the MCU I am using the software PCAN
