2024-06-13 07:10 AM
Dear all,
i have a custom pcb with a STM32H753XIHx.
I want to use CAN1 Interface to receive PDO and SDOs (Baudrate: 125k, CANopen).
My receive routine looks like this:
// CAN 1 receive interrupt callback
void HAL_FDCAN_RxFifo0Callback(FDCAN_HandleTypeDef *hfdcan, uint32_t RxFifo0ITs)
{
// static allocation saves instantiation time during interrupt
static struct canMsg *rxmsg = NULL;
static FDCAN_RxHeaderTypeDef rxheader;
char temp = 0;
if(hfdcan == &hfdcan1)
{
// CAN element available ?
if ( FREE_EMPTY() == 0 )
{
// Element aus freeRx-Puffer holen
if((rxmsg = FREE_PULL())!= NULL )
{
// retrieve rx message from fifo
if( HAL_FDCAN_GetRxMessage(hfdcan, FDCAN_RX_FIFO0, &rxheader, (uint8_t*) rxmsg->Data.Values.c ) == HAL_OK )
{
2024-06-13 07:19 AM
Hello and welcome to the community.
You didn't attach the ioc file but just a screenshot of a part of FDCAN peripheral config and I don't think it's helpful.
Could you please share your ioc file?
Are you sure rxmsg->Data.Values.c is not overwritten by something else like DMA for example?
2024-06-13 10:05 PM
2024-06-14 07:08 AM - edited 2024-06-14 07:26 AM
Hello,
Looking at your ioc file, I don't see issues with neither your clock source of FDCAN nor the FDCAN bitrate config. Meanwhile, I prefer to be sure there is no issue with the sampling of the CAN bit:
I used this site http://www.bittiming.can-wiki.info/ to fit your needs as you're using CANopen:
Bitrate is 125kb/s and the sample point is selected to be at 87.5 % as indicated.
So the prescaler = 4, SEG1 = 139 and SEG2 = 20.
I prefer to select the lowest prescaler value with highest SEG1/SEG2 values (for a best bit sampling resolution) fitting a given sample point:
Regarding your question about DMA, are you already using it? to verify if rxmsg is affected by DMA, disable CAN reception, set rxmsg to a random value and see if it will change over time. Note that it could be also the CPU itself overwriting your data.
2024-06-17 12:36 AM
Thank you for your feedback.
But from my point of view, the prescaler/timing settings shall not effect my problems:
I assume, that the CAN Hardware interface will receive a valid CANopen message and validate each message by unique CRC of each CAN message. If it's not valid -> message will be thrown away. If it's valid -> message will be put into FiFo which will be available inside CAN Callback function.
So normally I would be able to receive only valid can messages.
Actually I have CAN1 and CAN2 Interface both on Fifo0 - but I only have traffic on CAN1 - will this be an issue?
Any further suggestions?
2024-06-18 05:25 AM
Hello,
But from my point of view, the prescaler/timing settings shall not effect my problems:
I assume, that the CAN Hardware interface will receive a valid CANopen message and validate each message by unique CRC of each CAN message. If it's not valid -> message will be thrown away. If it's valid -> message will be put into FiFo which will be available inside CAN Callback function.
I know.. but who knows?
Also you didn't confirm about my previous check about data overwrite? did you check that point?
Actually I have CAN1 and CAN2 Interface both on Fifo0 - but I only have traffic on CAN1 - will this be an issue?
I don't think so .. but to double check, could you please disable CAN2 and see what happens?