2023-10-17 12:08 AM
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.
2023-10-17 12:12 AM
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.
2023-10-17 02:00 AM
Can you maybe send me in the right direction to start with? Because I have no idea where to start.