2014-09-08 02:47 PM
I am working on the STM32F302 Micro and I currently unable to receive data on the CAN bus, I have a break point set on the interrupt routine. I am able to transmit data. I am seeing the micro sends an acknowledge bit when I send data from my CAN tool, so I know the message is getting there, but when I look at the receive buffer I see nothing. I figure since my CAN tool receives the data from the micro without error I have all the timing set appropriately.
I am set for interrupt on Tx and Rx:
/* Transmit */
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
HAL_NVIC_SetPriority(USB_HP_CAN_TX_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USB_HP_CAN_TX_IRQn);
/* Receive */
HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0);
HAL_NVIC_SetPriority(USB_LP_CAN_RX0_IRQn, 0, 0);
HAL_NVIC_EnableIRQ(USB_LP_CAN_RX0_IRQn);
Interrupt routine:
void USB_LP_CAN_RX0_IRQHandler(void)
{
HAL_NVIC_ClearPendingIRQ(USB_LP_CAN_RX0_IRQn);
HAL_CAN_IRQHandler(&hcan);
}
I have F0R1 and F0R2 set to 0x04, I am using an extended ID.
I have CAN transmitting and receiving on a STM32F103 and I have compared my setup and see no difference. So I am running out of guesses.
#can #bxcan #filter #stm32 #stm32f2 #code #example #stm32-can2014-09-09 05:12 AM
How do you set up the filtering?
Jack Peacock2014-09-09 06:25 AM
I am using the HAL CAN libraries from the STM32 Cube application.
CAN_FilterConfTypeDef hcanFilter;CAN_HandleTypeDef hcan;MX_CAN_FilterInit(0x00,0x00004); void MX_CAN_FilterInit(char FilterNbr, uint32_t MessageBitMask){ hcanFilter.FilterNumber = FilterNbr; hcanFilter.FilterScale = CAN_FILTERSCALE_32BIT; hcanFilter.FilterMode = CAN_FILTERMODE_IDMASK; hcanFilter.FilterMaskIdLow = (0x0000FFFF & MessageBitMask); hcanFilter.FilterMaskIdHigh = ( MessageBitMask >> 16); HAL_CAN_ConfigFilter(&hcan, &hcanFilter);}2014-09-09 06:40 AM
Another thing I noticed that seems weird. STM32 Cube set up the IO as both outputs. Not sure if the alternate function 9 over rides the pin configuration.
GPIO_InitStruct.Pin = GPIO_PIN_11|GPIO_PIN_12; GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; GPIO_InitStruct.Pull = GPIO_NOPULL; GPIO_InitStruct.Speed = GPIO_SPEED_LOW; GPIO_InitStruct.Alternate = GPIO_AF9_CAN; HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);2014-09-10 04:55 AM
2014-09-10 06:07 AM
Hi ebommer,
Would you mind giving a little more information by posting your code for the full TX and RX operations ?To have enough insight into CAN projects, you can refer to Firmware\Projects\STM324xG_EVAL\Examples\CAN\CAN_Networking as a reference example, available under the STM32CubeF4 firmware package.PS: Please use code block Format when posting your code.Regards.2014-09-10 06:54 AM
2014-09-10 07:49 AM
Analysing your code, we remark that you're not really doing a reception operation. In fact, the approriate API to receive a correct CAN frame is not called within your code:
HAL_CAN_Receive_IT()
Regards.
2014-09-10 08:01 AM
Currently I am looking at the IRQ with a break point and its never being called. Do I need to do a ''
HAL_CAN_Receive_IT()
'' to setup the buffer to get the IRQ to work?I figured if the IRQ didn't work there was no reason to worry about the receive code.2014-09-10 11:51 AM
The CAN_ESR is ''0'', also RF0R and RF1R are also ''0''
I also added ''HAL_CAN_Receive_IT(&hcan,0);'' and poll it at 1 mSec. RI0R, RDTOR, RDLOR, and RDH0R all have junk data that doesn't change.But I am still transmitting an acknowledge bit after the CAN tool send the message.