Skip to main content
YAYAB.1
Visitor II
September 25, 2020
Question

Impossible to read Std ID from bxCAN bus

bxCAN problem.

Now sending data from STM32F407 to STM32F042 via bxCAN.

In STM32F042, it is possible

  • Rx interrupt
  • to read sending data (0x11, 0x22)
  • to read DLC (2 byte)

and oscilloscope that having CAN analyzing could read the sending ID/data correctly.

But, STM32F042 is impossible to read the standard ID. The reading ID is 0x000.

What is my mistake ?

Sending ID is 0x555.

/* receive interrupt */
void HAL_CAN_RxFifo0MsgPendingCallback(CAN_HandleTypeDef *hcan){
	CAN_RxHeaderTypeDef RxHeader;
	uint8_t 	RxData[2];
 
	if(HAL_CAN_GetRxMessage(hcan, CAN_RX_FIFO0, &RxHeader, RxData) == HAL_OK){
		id = RxHeader.StdId;
		dlc = RxHeader.DLC;
		ide = RxHeader.IDE;
		CANRxData[0] = RxData[0];
		CANRxData[1] = RxData[1];
 
		if(id == myID){
			HAL_GPIO_TogglePin(GPIOA, GPIO_PIN_0); // Just a test
		}
	}
 
}
 
 
void CAN_Init(void){
	CAN_FilterTypeDef	filter;
 
	filter.FilterIdHigh = 0;
	filter.FilterIdLow = 0;
	filter.FilterMaskIdHigh = 0;
	filter.FilterMaskIdLow = 0;
	filter.FilterScale = CAN_FILTERSCALE_32BIT;
	filter.FilterFIFOAssignment = CAN_FILTER_FIFO0;
	filter.FilterBank = 0;
	filter.FilterMode = CAN_FILTERMODE_IDMASK;
	filter.SlaveStartFilterBank = 14;
	filter.FilterActivation = ENABLE;
	HAL_CAN_ConfigFilter(&hcan, &filter);
 
}

Tx side code is

void CANTx(void){
 
	if(0 < HAL_CAN_GetTxMailboxesFreeLevel(&hcan1)){
		CAN1TxHeader.StdId = 0x555;
		CAN1TxHeader.RTR = CAN_RTR_DATA;
		CAN1TxHeader.IDE = CAN_ID_STD;
		CAN1TxHeader.DLC = 2;
		CAN1TxHeader.TransmitGlobalTime = DISABLE;
		CAN1TxData[0] = 0x11;
		CAN1TxData[1] = 0x22;
	 HAL_CAN_AddTxMessage(&hcan1, &CAN1TxHeader, CAN1TxData, &CAN1TxMailbox);
	}
 
}

regards.

This topic has been closed for replies.

1 reply

CMoeb.1
Associate
May 10, 2022

Today I got the same issue. After a lot of debugging with breakpoints I found the issue.

In the declaration of HAL_CAN_GetRxMessage in your ***.hal_can.c file you can see that the method want to have a data buffer of 8. If you are using less, the method overwrites your header data. So the simple fix for this issue was.

switch this line

uint8_t 	RxData[2];

to this line

uint8_t 	RxData[8];