Skip to main content
l90mehdi
Associate III
August 30, 2016
Question

RECIVE MESSAGE IN FIFO1 ON CAN BUS

  • August 30, 2016
  • 11 replies
  • 2471 views
Posted on August 30, 2016 at 16:45

hi evry one

i working on CAN protocol with stm32f103rbt6.it working so good.

now problem is here: when i reading mailboxs of FIFO0 ،all think is ok but i can not receive the message from FIFO1.

please tell me how to do this

thank you

    This topic has been closed for replies.

    11 replies

    l90mehdi
    l90mehdiAuthor
    Associate III
    September 3, 2016
    Posted on September 03, 2016 at 13:14

    Hi every body

    i checked my code again. I use STM32 CUBE MX for generate code and KEIL for compile code and i configure CAN parameter by HAL driver. if you want to receive the message in Both FIFOs(0,1) you should type 

    HAL_CAN_Receive_IT(&hcan,CAN_FIFO0);

    HAL_CAN_Receive_IT(&hcan,CAN_FIFO1);

    in your code.

    then when you configure filters you can define that which message pass from which filter and receive by which FIFO.for example :

    sFilterConfig.FilterNumber = 0;

    sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;

    sFilterConfig.FilterScale = CAN_FILTERSCALE_16BIT;

    sFilterConfig.FilterIdHigh = 0x0200;         

    sFilterConfig.FilterIdLow = 0x220;           

    sFilterConfig.FilterMaskIdHigh = 0xFFFF;

    sFilterConfig.FilterMaskIdLow = 0xFFFF;

    sFilterConfig.FilterFIFOAssignment = CAN_FIFO0; //  message can receive in FIFO0

    sFilterConfig.FilterActivation = ENABLE;

    sFilterConfig.FilterNumber = 1;

    sFilterConfig.FilterMode = CAN_FILTERMODE_IDMASK;

    sFilterConfig.FilterScale = CAN_FILTERSCALE_32BIT;

    sFilterConfig.FilterIdHigh = 0x250;//

    sFilterConfig.FilterIdLow = 0x00;

    sFilterConfig.FilterMaskIdHigh = 0xFFFF;

    sFilterConfig.FilterMaskIdLow = 0x0000;

    sFilterConfig.FilterFIFOAssignment = CAN_FIFO1; message can receive in FIFO1

    sFilterConfig.FilterActivation = ENABLE;

    in this case you can receive messages in FIFO0 and FIFO1.

    but this is very important that both FIFO(0,1) interrupt should be enable. you can add this line to end of

     HAL_StatusTypeDef HAL_CAN_Receive_IT(CAN_HandleTypeDef* hcan, uint8_t FIFONumber)

    function like as this line:

    //    if(FIFONumber == CAN_FIFO0)

    //    {

    //      /* Enable FIFO 0 message pending Interrupt */

    //      __HAL_CAN_ENABLE_IT(hcan, CAN_IT_FMP0);

    //    }

    //    else

    //    {

    //      /* Enable FIFO 1 message pending Interrupt */

    //      __HAL_CAN_ENABLE_IT(hcan, CAN_IT_FMP1);

    //    }

        

    //  }

      else

      {

        return HAL_BUSY;

      }

      

      /* Return function status */

    __HAL_CAN_ENABLE_IT(hcan, CAN_IT_FMP0);// added by user 

    __HAL_CAN_ENABLE_IT(hcan, CAN_IT_FMP1);// added by user

      return HAL_OK;

    i hope that my post can help you.