cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to receive CAN data

ebommer
Associate II
Posted on September 08, 2014 at 23:47

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-can
10 REPLIES 10
jpeacock
Associate III
Posted on September 09, 2014 at 14:12

How do you set up the filtering?

  Jack Peacock

ebommer
Associate II
Posted on September 09, 2014 at 15:25

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);

}

   

ebommer
Associate II
Posted on September 09, 2014 at 15:40

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);

jpeacock
Associate III
Posted on September 10, 2014 at 13:55

Did you check the error registers?

  Jack Peacock
Posted on September 10, 2014 at 15:07

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 

http://www.st.com/web/en/catalog/tools/PF259243#

 under the STM32CubeF4 firmware package.

PS: Please use code block Format when posting your code.

Regards.

ebommer
Associate II
Posted on September 10, 2014 at 15:54

The original post was too long to process during our migration. Please click on the provided URL to read the original post. https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I6eI&d=%2Fa%2F0X0000000bsR%2FCXMont4Hflksp5oYpi.LkeAyb3xGYEVn9VGQO02Ow3Y&asPdf=false
Posted on September 10, 2014 at 16:49

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.
ebommer
Associate II
Posted on September 10, 2014 at 17:01

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.

ebommer
Associate II
Posted on September 10, 2014 at 20:51

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.