Hi,
I am using TCAN4550 with NXP i.MX 8M NANO board to transmit and receive the CAN messages. In normal mode,i am able to receive the CAN messages sent from TCAN4550 to NXP board. Now my aim is to set the message filters for the messages(I am using the drivers provided by TI and i have made few changes according to my requirement in configurations).
Here are the changes i have made-
1)In init_CAN()-
TCAN4x5x_MCAN_SID_Filter SID_ID = {0};
SID_ID.SFT = TCAN4x5x_SID_SFT_RANGE;
//SID_ID.SFT = TCAN4x5x_SID_SFT_CLASSIC; // SFT: Standard filter type. Configured as a classic filter
//SID_ID.SFEC = TCAN4x5x_SID_SFEC_PRIORITYSTORERX0; // Standard filter element configuration, store it in RX fifo 0 as a priority message
SID_ID.SFEC = TCAN4x5x_SID_SFEC_STORERX0;
SID_ID.SFID1 = 0x101;
SID_ID.SFID2 = 0x110;
TCAN4x5x_MCAN_WriteSIDFilter(0, &SID_ID);
As per above configurations,my understanding is ,filters are enabled to receive the CAN messages in range of 0x101 to 0x110 and will be stored in RX FIFO 0.
2)TCAN4x5x_MCAN_WriteSIDFilter()-
TCAN4x5x_MCAN_WriteSIDFilter(uint8_t filterIndex, TCAN4x5x_MCAN_SID_Filter *filter)
{
uint32_t readData;
uint16_t startAddress;
uint8_t getIndex;
#ifdef TCAN4x5x_MCAN_CACHE_CONFIGURATION
readData = TCAN4x5x_MCAN_CACHE[TCAN4x5x_MCAN_CACHE_SIDFC];
#else
readData = AHB_READ_32(REG_MCAN_SIDFC);
#endif
PRINTF("read data in TCAN4x5x_MCAN_CACHE_SIDFC 0x%x\r\n",readData);
getIndex = (readData & 0x00FF0000) >> 16;
if (filterIndex > getIndex) // Check if the fifo number is valid and within range. If not, then fail
return false;
else
getIndex = filterIndex;
PRINTF("getIndex %d\r\n",getIndex);
startAddress = (uint16_t)(readData & 0x0000FFFF) + REG_MRAM;
PRINTF("startaddress 0x%x\r\n",startAddress);
// Calculate the actual start address for the latest index
startAddress += (getIndex << 2); // Multiply by 4 and add to start address
PRINTF("Actual start address=0x%x\r\n",startAddress);
PRINTF("filter->word=0x%x\r\n",filter->word);
AHB_WRITE_32(startAddress, filter->word); // Write the value to the register
#ifdef TCAN4x5x_DEVICE_VERIFY_CONFIGURATION_WRITES
// Verify that write was successful
readData = AHB_READ_32(startAddress);
if (readData != filter->word)
return false;
#endif
return true;
}
Here the startaddress is 0x8000 in TCAN4x5x_MCAN_WriteSIDFilter.
3)My can message receiving logic-
TCAN4x5x_Device_Interrupts dev_ir = {0};// Define a new Device IR object for device (non-CAN) interrupt checking
TCAN4x5x_MCAN_Interrupts mcan_ir = {0}; // Setup a new MCAN IR object for easy interrupt checking
TCAN4x5x_Device_ReadInterrupts(&dev_ir);// Read the device interrupt register
TCAN4x5x_MCAN_ReadInterrupts(&mcan_ir); // Read the interrupt register
if (dev_ir.SPIERR) // If the SPIERR flag is set
{
TCAN4x5x_Device_ClearSPIERR(); // Clear the SPIERR flag
TCAN4x5x_Device_ReadInterrupts(&dev_ir);// Read the device interrupt register
}
if (mcan_ir.RF0N) // If a new message in RX FIFO 0
{
PRINTF("\r\nnew message in fifo");
TCAN4x5x_MCAN_RX_Header MsgHeader = {0}; // Initialize to 0 or you'll get garbage
uint8_t numBytes = 0; // Used since the ReadNextFIFO function will return how many bytes of data were read
uint8_t dataPayload[64] ={0}; // Used to store the received data
TCAN4x5x_MCAN_ClearInterrupts(&mcan_ir); // Clear any of the interrupt bits that are set.
TCAN4x5x_MCAN_ClearInterruptsAll();
numBytes = TCAN4x5x_MCAN_ReadNextFIFO( RXFIFO0, &MsgHeader, dataPayload); // This will read the next element in the RX FIFO 0
{
//printing message data here
}
}
Now my problem is even if i am sending CAN message ID 0x555 from PCAN-View simulator,I am getting that message on NXP board,but it should not be received as i have set the filter in range ox101 to 0x110. is something that i am missing here in configuration?
please explain me this .
Thanks in Advance.
Regards,
Bipin