Skip to main content
ppati.9
Associate
September 6, 2018
Question

Not able to receive data over CAN

I am working on STM32F4-Discovery board with STM32F412ZG. Trying to work CAN communication between MCU and PC with the help of kvaser canking tool(SJW=1, bus speed=125 kbps). I got success in transmitting data to PC successfully and I am getting correct data without any error. But unable to receive data on same can bus. Whenever i send data from PC over CAN, I am not able to get any data in MCU's FIFO mailbox. I have checked CAN_RX and GND pins on DSO and i am getting pulses(data) till connector(CN12) of discovery board. i have checked schematic of discovery board and connection of that connector is directly gone to MCU pin. But still not able to receive data in FIFO mailbox.

I am attaching my code here. Please suggest if i missed anything in order to receive data successfully.

    This topic has been closed for replies.

    4 replies

    T J
    Senior III
    September 6, 2018

    did you enable the interrupts?

    there are 2 fifos.

    		
    	
     __HAL_CAN_ENABLE_IT(&hcan, CAN_IT_FMP1);
     __HAL_CAN_ENABLE_IT(&hcan, CAN_IT_FMP0);

    ppati.9
    ppati.9Author
    Associate
    September 10, 2018

    I got my answer. Actually, filter initialization was a problem. Now, I am able to both transmit and receive the data. Thanks.

    T J
    Senior III
    September 10, 2018
    Can you show the code for the fix ?
    We would all appreciate it.
    ppati.9
    ppati.9Author
    Associate
    September 12, 2018

    sFilterConfig.FilterNumber=0;//filter 0 will be initialized

    sFilterConfig.FilterMode=CAN_FILTERMODE_IDMASK;//Identifier mask mode 

    // sFilterConfig.FilterMode=CAN_FILTERMODE_IDLIST;//Identifier list mode 

    sFilterConfig.FilterScale=CAN_FILTERSCALE_32BIT;//One 32-bit filter

    sFilterConfig.FilterIdHigh=0x00;//filter identification number - MSBs for a 32-bit configuration               

    sFilterConfig.FilterIdLow=0x00;//filter identification number - LSBs for a 32-bit configuration 

    sFilterConfig.FilterMaskIdHigh=0x00;//filter mask number or identification number,according to the mode - MSBs for a 32-bit configuration                    

    sFilterConfig.FilterMaskIdLow=0xFF;//filter mask number or identification number,according to the mode - LSBs for a 32-bit configuration

    sFilterConfig.FilterFIFOAssignment=CAN_FIFO0;//FIFO 0 will be assigned to the filter.

    sFilterConfig.FilterActivation=ENABLE;//Enable or disable the filter.

    HAL_CAN_ConfigFilter(&hcan1, &sFilterConfig);