cancel
Showing results for 
Search instead for 
Did you mean: 

STMF105RC CAN1 can't receive Message sometime on low CANID

shen songyan
Associate II
Posted on July 18, 2017 at 07:43

Hi everyone,

I use CAN interrupt to receive CAN message, the CAN ID is 0x500 that is lower than other CAN IDs what I received.

but this CAN message can not received frequency. sometimes it will loss.

So I don't know where is wrong. could you help me?

thanks!

for My Initial code & CAN interrupt code is below:

u8 CAN_Mode_Init(u8 tsjw,u8 tbs2,u8 tbs1,u16 brp,u8 mode)

{

   CAN_InitTypeDef            CAN_InitStructure;

   CAN_FilterInitTypeDef      CAN_FilterInitStructure;

   /*init can */

   CAN_InitStructure.CAN_TTCM=DISABLE;            

   CAN_InitStructure.CAN_ABOM=ENABLE;            

   CAN_InitStructure.CAN_AWUM=DISABLE;            

   CAN_InitStructure.CAN_NART=DISABLE;            

   CAN_InitStructure.CAN_RFLM=DISABLE;             

   CAN_InitStructure.CAN_TXFP=DISABLE;            

   CAN_InitStructure.CAN_Mode= mode;         

   

   /*set baud rate*/

   CAN_InitStructure.CAN_SJW=tsjw;    

   CAN_InitStructure.CAN_BS1=tbs1;

   CAN_InitStructure.CAN_BS2=tbs2;                

   CAN_InitStructure.CAN_Prescaler=brp;       

   CAN_Init(CAN1, &CAN_InitStructure);   

   

   /*init filter/mask*/

   CAN_FilterInitStructure.CAN_FilterNumber=0;    //filter 0

   CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdList;     //mask mode

   CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_16bit;     //filter scale

   

   /*id list is id1 id2 id3 id4*/

   CAN_FilterInitStructure.CAN_FilterIdHigh=VCU_HMI_ID1<<FILTER_MASK_STDID_SHIFT;    

   CAN_FilterInitStructure.CAN_FilterIdLow=VCU_HMI_ID2<<FILTER_MASK_STDID_SHIFT;

   CAN_FilterInitStructure.CAN_FilterMaskIdHigh=VCU_HMI_ID3<<FILTER_MASK_STDID_SHIFT;

   CAN_FilterInitStructure.CAN_FilterMaskIdLow=VCU_HMI_ID4<<FILTER_MASK_STDID_SHIFT;

   CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_Filter_FIFO0;

   CAN_FilterInitStructure.CAN_FilterActivation=ENABLE;

   CAN_FilterInit(&CAN_FilterInitStructure);    

   /*id list is id5 id6 id7 */

   CAN_FilterInitStructure.CAN_FilterNumber=1;    //filter 1

   CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdList;     //mask mode

   CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_16bit;     //filter scale

   CAN_FilterInitStructure.CAN_FilterIdHigh=VCU_HMI_ID5<<FILTER_MASK_STDID_SHIFT;    

   CAN_FilterInitStructure.CAN_FilterIdLow=VCU_HMI_ID6<<FILTER_MASK_STDID_SHIFT;

   CAN_FilterInitStructure.CAN_FilterMaskIdHigh=VCU_HMI_ID7<<FILTER_MASK_STDID_SHIFT;

   CAN_FilterInitStructure.CAN_FilterMaskIdLow=VCU_HMI_DIAGNOSE<<FILTER_MASK_STDID_SHIFT;

   CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_Filter_FIFO0;

   CAN_FilterInit(&CAN_FilterInitStructure);    

   CAN_FilterInitStructure.CAN_FilterNumber=2;    //filter 2

   CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdList;     //mask mode

   CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_16bit;     //filter scale

   CAN_FilterInitStructure.CAN_FilterIdHigh=ABS_INFO<<FILTER_MASK_STDID_SHIFT;    

   CAN_FilterInitStructure.CAN_FilterIdLow=VCU_HMI_ID8<<FILTER_MASK_STDID_SHIFT;

   CAN_FilterInitStructure.CAN_FilterMaskIdHigh=UDS_TESTER_ID<<FILTER_MASK_STDID_SHIFT;

   CAN_FilterInitStructure.CAN_FilterMaskIdLow=UDS_VCU_ID<<FILTER_MASK_STDID_SHIFT;

   CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_Filter_FIFO0;

    

     CAN_FilterInit(&CAN_FilterInitStructure);    

   CAN_FilterInitStructure.CAN_FilterNumber=3;    //filter 3

   CAN_FilterInitStructure.CAN_FilterMode=CAN_FilterMode_IdList;     //mask mode

   CAN_FilterInitStructure.CAN_FilterScale=CAN_FilterScale_16bit;     //filter scale

   CAN_FilterInitStructure.CAN_FilterIdHigh=NETWORK_STATE<<FILTER_MASK_STDID_SHIFT;    

   CAN_FilterInitStructure.CAN_FilterIdLow=BMS_VCU_07<<FILTER_MASK_STDID_SHIFT;

   CAN_FilterInitStructure.CAN_FilterMaskIdHigh=ENCRYPTION_VCU_HMI<<FILTER_MASK_STDID_SHIFT;

   CAN_FilterInitStructure.CAN_FilterMaskIdLow=NULL<<FILTER_MASK_STDID_SHIFT;

   CAN_FilterInitStructure.CAN_FilterFIFOAssignment=CAN_Filter_FIFO0;

   CAN_FilterInit(&CAN_FilterInitStructure);   

   return 0;

}   

/*************************************************

Function: CanIsrRx0_0

Description: recv intterrupt

Called By: N A

Input: recv message

Output: can data & can id

Return: NA

Others: NA

*************************************************/

void CanIsrRx0_0(void)

{

   CanRxMsg rxMessage;

       

   if(CAN_GetITStatus(CAN1,CAN_IT_FF0))//fifo full

   {

      CAN_ClearITPendingBit(CAN1,CAN_IT_FF0);//clear fifo full

   }

   else if(CAN_GetITStatus(CAN1,CAN_IT_FOV0))//overflow flag

   {

      CAN_ClearITPendingBit(CAN1,CAN_IT_FOV0);//clear overflow

   }

   else

   {

      CAN_Receive(CAN1,CAN_FIFO0, &rxMessage);

      CAN_ClearITPendingBit(CAN1,CAN_IT_FMP0);

      CAN_FIFORelease(CAN1,CAN_FIFO0);

      /*rx process*/

      CanMessageSendRxQueue(&rxMessage);      

   }

   

}
1 REPLY 1
Jeroen3
Senior
Posted on July 18, 2017 at 15:39

You mention 'sometimes it will loss'. What do the CAN_RF0R - FOVR0 bits tell you?