Flexcan Receiving issue
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I’m using the MPC5775B microcontroller with FlexCAN. During runtime, the FlexCAN suddenly stops receiving standard CAN IDs, even though the CAN IDs are present on the bus. However, it can still receive extended CAN IDs and can send both standard and extended CAN IDs. The system returns to normal functionality after resetting the MCU. What could be causing this issue, and how can it be resolved?
Here’s how I’m initializing the transmit and receive message boxes:
// Configure Transmit box
FLEXCAN_DRV_ConfigTxMb(INST_FLEXCANC, 0, &FlexCAN_transmitMsgInfo, 0x69); FLEXCAN_DRV_ConfigTxMb(INST_FLEXCANC, 1, &FlexCAN_transmitMsgInfo, 0x69);
// Configure Receive box
FLEXCAN_DRV_ConfigRxMb(INST_FLEXCANC, 2, &FlexCAN_receiveMsgInfo, 0x210); FLEXCAN_DRV_ConfigRxMb(INST_FLEXCANC, 3, &FlexCAN_receiveMsgInfo, 0x210); FLEXCAN_DRV_ConfigRxMb(INST_FLEXCANC, 4, &FlexCAN_receiveMsgInfo, 0x210); FLEXCAN_DRV_ConfigRxMb(INST_FLEXCANC, 5, &FlexCAN_receiveMsgInfo_ext, DUMMY_CAN_ID_2);
FLEXCAN_DRV_ConfigRxMb(INST_FLEXCANC, 6, &FlexCAN_receiveMsgInfo_ext, 0x210);
i used global mask to accept to receive all the canids
Can you please help me out on how to resolve this.
#flexcan #Mpc5775b
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @PetrS ,
How can we determine if a message buffer (MB) is in an overrun state or any other state? Is there an interrupt to check the status in FlexCAN?
In my case, I’m using FlexCAN with a callback function to copy the received data triggered by the `FLEXCAN_EVENT_RX_COMPLETE` event. However, occasionally, my application fails to catch that interrupt and process the data in time. As a result, when a new message arrives in the same MB, the MB cannot receive the data.
How can I detect when the MB goes into an overrun state to service it appropriately? How should I address this issue?


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
overrun is only indicated by MB CODE field. So once MB interrupt is serviced the user RXbuffer is updated with MB content, RXbuffer.CS contains value of MB's CS word where CODE field can be read.
You should ensure MB is read in time. Try to set higher priority for FlexCAN module MB interrupts.
BR, Petr


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
from this piece of code it cannot be much commented regarding a root cause.
I can recommend to check in debugger for module's registers and MBs setting/content, if this is as expected. If the MB is still configured to receive given ID, then it would be updated if such message is received.
BR, Petr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Peter,
Actually, the issue occurs suddenly while the application is running on the MCU, and at that moment, we can’t check the register contents, correct? I’m also unable to recreate the issue.
I have another question: What is the global mask value to receive all CAN IDs without any filter?


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
refer to RXMGMASK register description.
If mask register is cleared then received ID is don't care. In that case first RX MB will be updated still if global mask scheme is used.
BR, Petr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi petrs
1.)Is there a feature in FlexCAN to stop receiving CAN data when the error counter for a particular message buffer (MB) reaches the threshold?
2.)or is there any condition to stop receiving?
3.) i used 0x69,0x210 as mask for MB0 ,1 what range of canid's it will receive?


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
1) no, there is no such functionality. Also there is no individual error counters for each MB. ECR register contains contains error counters for received and transmitted messages. The rules for
increasing and decreasing these counters are described in the CAN protocol and basic rules are listed in ECR description.
You can get warning interrupt, see TWRNINT/RWRNINT and user have to react as needed.
2) Reception is stopped if RX MBs are inactivated, or module is in Freeze mode
3) you have an ID and IDE bit configured in the MB and corresponding mask register, from that you can see which ID bits will be don't care.
BR, Petr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Petrs,
1. Under which situations are RX message buffers (MBs) deactivated?
2. When the RXERRCNT in the Error Counter Register (ECR) reaches its maximum value, what happens? Does the CAN controller enter any specific state? In this state, can it still receive or transmit CAN IDs?


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
HI,
1) to inactivate a message buffer, the CPU must update its CODE field to INACTIVE (either 0b or 1000b). see more in chapter 73.3.7.2 Message buffer inactivation
2) a module will continue to run in error passive state; It takes part in bus communication,
but when an error has been detected only a PASSIVE Error flag is sent. Also after a transmission,
an error-passive node will wait before initiating a further transmission.
BR, Petr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Petrs,
Could you please share a code snippet on how to inactivate the message buffer (MB) after initializing the FlexCAN module for the MPC5775B MCU?


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
SDK does not have function to inactivate RX MB, so if needed you need to write MB directly.
FLEXCAN_DRV_AbortTransfer can be the one you can refer to. For RX MB, it finally deactivates the MB, but then activate it again.
BR, Petr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Petrs,
I identified the issue behind the stop in receiving. After reading the code value of the MBs, I found that when it stops receiving the CAN IDs, it's in the OVERRUN state (0x6). Can you help me resolve this and get it back to a normal state where it can receive the CAN IDs again?
Here’s the code snippet I used for recovery:
`
static inline uint32_t FLEXCAN_GetMessageBufferCode(const CAN_Type *base, uint32_t mbIdx) {
if (mbIdx >= FEATURE_CAN_MAX_MB_NUM) {
return UINT32_MAX; // Invalid index
}
volatile uint32_t *flexcan_mb = FLEXCAN_GetMsgBuffRegion(base, mbIdx);
uint32_t flexcan_mb_config = *flexcan_mb; // Read the control/status register
uint32_t code = (flexcan_mb_config & FLEX_CAN_CS_CODE_MASK) >> 24; // Extract the CODE field
return code;
}
void UnlockOverrunMailbox(CAN_Type *base, uint32_t mbIdx) {
// Enter Freeze Mode to safely modify the mailbox
if (!FLEXCAN_EnterFreezeMode(base)) {
printf("Failed to enter Freeze Mode\n");
return;
}
// Check if the MB is in OVERRUN state
uint32_t mbCode = FLEXCAN_GetMessageBufferCode(base, mbIdx);
if (mbCode == FLEXCAN_RX_BUFFER_OVERRUN) {
printf("MB %u is in OVERRUN state. Unlocking it...\n", mbIdx);
// Reset the MB state to EMPTY (0x4) or INACTIVE (0x0)
base->RAMn[mbIdx * 4] = (base->RAMn[mbIdx * 4] & ~FLEX_CAN_CS_CODE_MASK) | (0b0100 << 24);
// Unlock the MB by reading the Free Running Timer
volatile uint32_t unlock = base->TIMER;
printf("MB %u unlocked and reset to EMPTY state.\n", mbIdx);
}
// Exit Freeze Mode
FLEXCAN_ExitFreezeMode(base);
}
```
However, the recovery is still not working.
I have a few questions related to this issue:
1. I configured three message buffers (MBs) for receiving, all filtered with the same CAN ID. In this case, the second MB went into the OVERRUN state, but why aren't the remaining two MBs receiving messages?
2. Is there any other process or method, apart from the code snippet above, to recover from this situation and resume receiving CAN IDs?
Thanks for your help!


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
if a code field is OVERRUN, still this MB is seen as free-to-receive during matching process, if the MB is not locked. So maybe in your case the second MB is recognized as matched and free-to-receive MB and so other are not updated.
If the driver is not able to read a MB (call MB interrupt, etc) you can try to check MB flag and interrupt mask bit and content of driver status variable for given MB.
To recover you can try to call AbortTransfer function and then Receive function again.
Not sure of the SDK version you have, but be sure you have the latest one (3.0.0 I think).
BR, Petr
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi @PetrS ,
Thank you for the prompt response. I will try to set the priority to high.
I have another question: In flexcan While configuring the RX buffers, we can apply individual masks to each buffer as required. Similarly, is it possible to configure TX buffers with individual masks? If not, how does the system handle multiple CAN IDs in the TX buffers?


- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
no mask is done for TX buffers. User configures MB with given ID for transmission. If more TX MBs are prepared for transmission, internal arbitration process is performed to select a winner, that is going to be send on first opportunity window on the bus. See more in Arbitration process chapter.
BR, Petr
