cancel
Showing results for 
Search instead for 
Did you mean: 

How can I handle FIFO0 pending bit interruption ? How can I clear the flag correctly ?

AVida.1
Associate

Hi all, I'm using a stm32f10x connected to a CANalyzer in order to verify the integrity of the CAN bus. The implemented process is simple, I have transmitted a CAN trace ( 11 bit ID + 8 bytes of DATA ) to the CANalyzer and it responses automatically with another CAN trace ( different ID and DATA values, but still using 11 bit ID ). The CAPL script is correct and the trace is received properly through CAN1, but only if I DISABLE the FIFO0 pending bit interruption.

 // Enable CAN interrupt

CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE); // Q: If I DISABLE it, my code works.

How can I handle this interruption ?

I checked with :

CAN_GetITStatus(CAN1, CAN_IT_FMP0);

and it triggered in :

 /* Check CAN_RF0R_FMP0 bit */

 itstatus = CheckITStatus(CANx->RF0R, CAN_RF0R_FMP0);

being the status :

 if ((CAN_Reg & It_Bit) != (uint32_t)RESET)

 {

  /* CAN_IT is set */

  pendingbitstatus = SET; // This one. How can I lower this flag ?

 }

--- My CAN configuration code is this one : ---

void CAN_Configuration(void)

 GPIO_InitTypeDef GPIO_InitStructure;

CAN_InitTypeDef CAN_InitStructure;

CAN_FilterInitTypeDef CAN_FilterInitStructure;

 NVIC_InitTypeDef NVIC_InitStructure;

  

 RCC_APB2PeriphClockCmd(RCC_APB2Periph_AFIO | RCC_APB2Periph_GPIOA, ENABLE);

 /* Configure CAN pin: RX */

 GPIO_InitStructure.GPIO_Pin = RX_CAN_PIN;

 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; 

 GPIO_Init(CAN_GPIO, &GPIO_InitStructure);

  

 /* Configure CAN pin: TX */

 GPIO_InitStructure.GPIO_Pin = TX_CAN_PIN;

 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP;

 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

 GPIO_Init(CAN_GPIO, &GPIO_InitStructure);

/* 'WKUP_EXP' */

GPIO_InitStructure.GPIO_Pin = WAKEUP_CAN_PIN;  

GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;

GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;

GPIO_Init(CAN_WAKEUP_GPIO, &GPIO_InitStructure);

 /* CANx Periph clock enable */

 RCC_APB1PeriphClockCmd(RCC_APB1Periph_CAN1, ENABLE);

  

 /* CAN register init */

 CAN_DeInit(CAN1);

 CAN_StructInit(&CAN_InitStructure);

 /* CAN cell init */

 CAN_InitStructure.CAN_TTCM = DISABLE;

 CAN_InitStructure.CAN_ABOM = DISABLE;

 CAN_InitStructure.CAN_AWUM = DISABLE;

 CAN_InitStructure.CAN_NART = DISABLE;

 CAN_InitStructure.CAN_RFLM = DISABLE;

 CAN_InitStructure.CAN_TXFP = DISABLE;

 CAN_InitStructure.CAN_Mode = CAN_Mode_Normal;

  

 /* CAN Baudrate = 125kBps*/

 CAN_InitStructure.CAN_SJW = CAN_SJW_1tq;

 CAN_InitStructure.CAN_BS1 = CAN_BS1_3tq;

 CAN_InitStructure.CAN_BS2 = CAN_BS2_5tq;

 CAN_InitStructure.CAN_Prescaler = 32;

 CAN_Init(CAN1, &CAN_InitStructure);

 /* CAN filter init */

 CAN_FilterInitStructure.CAN_FilterNumber = 0; // Filter 0 for CAN1.

 CAN_FilterInitStructure.CAN_FilterMode = CAN_FilterMode_IdMask;

 CAN_FilterInitStructure.CAN_FilterScale = CAN_FilterScale_32bit;

 CAN_FilterInitStructure.CAN_FilterIdHigh = 0x206 << 5; // This ID is the received one.

 CAN_FilterInitStructure.CAN_FilterIdLow = 0x0000;

 CAN_FilterInitStructure.CAN_FilterMaskIdHigh = 0x7FF << 5; // Check all bits form ID.

 CAN_FilterInitStructure.CAN_FilterMaskIdLow = 0x0000;

 CAN_FilterInitStructure.CAN_FilterFIFOAssignment = CAN_FIFO0; // Use FIFO0.

 CAN_FilterInitStructure.CAN_FilterActivation = ENABLE;

 CAN_FilterInit(&CAN_FilterInitStructure);

  

 NVIC_InitStructure.NVIC_IRQChannel = USB_LP_CAN1_RX0_IRQn;

 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 5;

 NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x0;

 NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;

 NVIC_Init(&NVIC_InitStructure);

 // Enable CAN interrupt

CAN_ITConfig(CAN1, CAN_IT_FMP0, ENABLE); // If I DISABLE it, my bellow code works.

}

--- My CAN Write then Read code is this one : --- ( Its a function returning the received CAN struct from CANalyzer using as input a predefined CAN struct )

 CanMsg_t FwMr13_SendCanMsg(const CanMsg_t *Msg)

{

CanTxMsg TxMessage;

CanRxMsg RxMessage;

uint8_t TxMailBox; 

uint8_t TxStatus;

CanMsg_t RxMsg;

ITStatus CANinterruptStatus;

TxMessage.IDE = CAN_Id_Standard;

TxMessage.StdId = Msg->Id;

TxMessage.DLC = Msg->Dlc;

memcpy(TxMessage.Data ,Msg->Data , 8);

TxMessage.RTR = CAN_RTR_Data;

TxMailBox = CAN_Transmit(CAN1, &TxMessage); // Transmit through CAN1.

TxStatus = CAN_TransmitStatus(CAN1, TxMailBox); // TxStatus is Ok.

CAN_CancelTransmit(CAN1, TxMailBox); 

CANinterruptStatus = CAN_GetITStatus(CAN1, CAN_IT_FMP0); // Here triggers.

CAN_Receive(CAN1, CAN_FIFO0, &RxMessage); // Read CAN1.

RxMsg.Id = RxMessage.StdId;

RxMsg.Dlc = RxMessage.DLC;

memcpy(RxMsg.Data, RxMessage.Data, 8);

if(CAN_MessagePending(CAN1, CAN_FIFO0) != 0 )

CAN_FIFORelease(CAN1, CAN_FIFO0);

CAN_GetLastErrorCode(CAN1);

return RxMsg;

}

Thanks in advance,

0 REPLIES 0