I have two CANs used in my PCB. CAN1, CAN3.
I am using message buffers for TX and RX.
#define RX_MESSAGE_BUFFER_NUM (9)
#define TX_MESSAGE_BUFFER_NUM (8)
#define USE_CANFD (0)
** I am trying to take any Classical Standard or Extended CAN message with interrupt and send it back with +1 increment for coming id and each received can data.
** I am using interrupt for only receiving. For transmitting, I do not use interrupt. I sent it with "FLEXCAN_WriteTxMb" non blocking- method.
** Even though I am sending only one time, FLEXCAN sends continously data. I disabled "loopback" disabled at init procedure. However, it behaves as I stated.
Here is my simple code important areas :
/*
#define EXAMPLE_CAN CAN1
#define EXAMPLE_FLEXCAN_IRQn CAN1_IRQn
#define EXAMPLE_FLEXCAN_IRQHandler CAN1_IRQHandler
*/
#define EXAMPLE_CAN CAN3
#define EXAMPLE_FLEXCAN_IRQn CAN3_IRQn
#define EXAMPLE_FLEXCAN_IRQHandler CAN3_IRQHandler
void EXAMPLE_FLEXCAN_IRQHandler(void){
uint64_t flag = 1U;
if (0U != FLEXCAN_GetMbStatusFlags(EXAMPLE_CAN, flag << RX_MESSAGE_BUFFER_NUM))
{
FLEXCAN_ClearMbStatusFlags(EXAMPLE_CAN, flag << RX_MESSAGE_BUFFER_NUM);
(void)FLEXCAN_ReadRxMb(EXAMPLE_CAN, RX_MESSAGE_BUFFER_NUM, &rxFrame);
rxComplete = true;
}
SDK_ISR_EXIT_BARRIER;
}
flexcan_config_t flexcanConfig;
flexcan_rx_mb_config_t mbConfig;
clock_root_config_t rootCfg = {0};
rootCfg.mux = FLEXCAN_CLOCK_SOURCE_SELECT;
rootCfg.div = FLEXCAN_CLOCK_SOURCE_DIVIDER;
/* CLOCK_SetRootClock(kCLOCK_Root_Can1, &rootCfg);*/
CLOCK_SetRootClock(kCLOCK_Root_Can3, &rootCfg);
FLEXCAN_GetDefaultConfig(&flexcanConfig);
flexcanConfig.bitRate = 250000U;
flexcanConfig.enableLoopBack = false;
FLEXCAN_Init(EXAMPLE_CAN, &flexcanConfig, EXAMPLE_CAN_CLK_FREQ);
mbConfig.format = kFLEXCAN_FrameFormatExtend;
mbConfig.type = kFLEXCAN_FrameTypeData;
mbConfig.id = FLEXCAN_ID_EXT(0x00000000);
FLEXCAN_SetRxMbConfig(EXAMPLE_CAN, RX_MESSAGE_BUFFER_NUM, &mbConfig, true);
FLEXCAN_SetTxMbConfig(EXAMPLE_CAN, TX_MESSAGE_BUFFER_NUM, true);
FLEXCAN_EnableMbInterrupts(EXAMPLE_CAN, flag << RX_MESSAGE_BUFFER_NUM);
(void)EnableIRQ(EXAMPLE_FLEXCAN_IRQn);
while (true)
{
rxComplete = false;
while (!rxComplete)
{
}
rxFrame.id = FLEXCAN_ID_EXT(rxFrame.id) + 0x01;
rxFrame.dataByte0 += 1;
rxFrame.dataByte1 += 1;
rxFrame.dataByte2 += 1;
rxFrame.dataByte3 += 1;
rxFrame.dataByte4 += 1;
rxFrame.dataByte5 += 1;
rxFrame.dataByte6 += 1;
rxFrame.dataByte7 += 1;
if (kStatus_Success == FLEXCAN_WriteTxMb(EXAMPLE_CAN, TX_MESSAGE_BUFFER_NUM, &rxFrame))
{;}
** I have one data logger with sending capability. I am also using debugger to find the problem. What I see is that; as soon as I send such as 0x18aabbcc id message, it produces continously interrupt and that is why I am taking 0x18aabbcd, 0x18aabbce, 0x18aabbcf...
** I read with debugger in interrupt handler, there is always "1" in RX_MESSAGE_BUFFER_NUM place in IFLAG register. So it continously produces interrupt. I do not understand where I am missing?
Solved! Go to Solution.
Hi,
exact setting is hidden here, but it seems you can have self-reception enabled. Check MCR[SRXDIS] bit.
BR, Petr
Hi @PetrS, I see the you replied most questions on FLEXCAN for MPC and S32 series. I am using IMXRT1176 but thinks flexcan structure is similiar. Can you please help me my above issue regarding CAN?
Thank you
Hi,
exact setting is hidden here, but it seems you can have self-reception enabled. Check MCR[SRXDIS] bit.
BR, Petr
Many thanks @PetrS for your very quick response.
You are right. MCR[SRXDIS] was 0 means self reception enabled.
After your guide, I noticed that disableSelfReception flag controls SRXDIS bit. After changing it, everything now works as accepted. Thanks a lot again.
flexcanConfig.enableLoopBack = false;
flexcanConfig.disableSelfReception =true;