cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 CAN bus 2.0B

Smdeint
Associate III

Hello, I'm working on a project where I need to read the CAN bus messages that are coming from an ECU. I'm using the STM3210E-EVAL that has the STM32f103ZGT6. I'm reading the CAN bus messages with the following function:

 

void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan1)  {

if (HAL_CAN_GetRxMessage(hcan1, CAN_RX_FIFO0, &can_rxheader, can_rx) !=HAL_OK) {

can_error_handler();

}

printf("\r\n______________________________________________\r\n");

printf("Received CAN frame with extended ID: 0x%lX\r\n", can_rxheader.ExtId);

 

printf("Data: ");

for (int i = 0; i < 8; i++) {

 printf("%d ", can_rx[i]);

 }

}

 

The CAN bus is set to 250kbps and interrupt Rx0 is used.

In this code the FIFO0 is used to store the CAN bus incoming messages. I read somewhere on a form that the STM32f103 series has a FIFO size of 3, which means that if it overruns you lose data. When I read the CAN bus I can see all the messages coming in and the data in the message is changing. Does this mean that the FIFO is updated or that it is overrun? And if so how CAN I manage the CAN FIFO0 so that data is not lost? I have not much experience with embedded programming and registers, so if someone CAN explain how this should/can work that will be great.

2 REPLIES 2

Focus on recovering and buffering data off the wire, at wire speeds. Don't be printing the content real-time to a serial terminal in ASCII at some fractional speed of the input stream..

The Peripheral has flags, errors and status, should be able to determine if you're losing packets because you're not sinking data fast enough.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Smdeint
Associate III

Can you maybe send me in the right direction to start with? Because I have no idea where to start.