Transmit and Receive CAN Bus in same node - TC297 Kit

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
User21869
Level 1
Level 1
Hai,

I am working on project using TC297 kit. In this project i have to communicated with other devices using CAN bus.
I already initialize CAN peripheral (using CAN0 X202 on kit), I can transmit messages on CAN bus (validated using logic analyzer) but
have a problem to receiving CAN bus messages, never enter CAN rx handler. In transmit and receiving process, interrupt being used to handle this.
But interrupts seems not active. Can someone help my problem. Here the snippet code.




IFX_INTERRUPT(canIsrTxHandler, 0, ISR_PRIORITY_CAN_TX);
IFX_INTERRUPT(canIsrRxHandler, 0, ISR_PRIORITY_CAN_RX);

void canIsrTxHandler(void)
{
/* Just to indicate that the CAN message has been transmitted by turning on LED1 */
IfxPort_setPinState(&MODULE_P13, 0, IfxPort_State_toggled);
}

void canIsrRxHandler(void)
{
IfxMultican_Status readStatus;

/* Read the received CAN message and store the status of the operation */
readStatus = IfxMultican_Can_MsgObj_readMessage(&g_multican.canRxMsgObj, &g_multican.rxMsg);

/* If no new data has been received, report an error */
if( !( readStatus & IfxMultican_Status_newData ) )
{
while(1)
{
}
}

/* If new data has been received but with one message lost, report an error */
if( readStatus == IfxMultican_Status_newDataButOneLost )
{
while(1)
{
}
}

IfxPort_setPinState(&MODULE_P13, 2, IfxPort_State_toggled);

/* Finally, check if the received data matches with the transmitted one */
if( ( g_multican.rxMsg.data[0] == g_multican.txMsg.data[0] ) &&
( g_multican.rxMsg.data[1] == g_multican.txMsg.data[1] ) &&
( g_multican.rxMsg.id == g_multican.txMsg.id ) )
{
/* Turn on the LED2 to indicate correctness of the received message */
IfxPort_setPinLow(&MODULE_P13, 1);
}
}

void initMultican_Network(void)
{
/* ==========================================================================================
* CAN module configuration and initialization:
* ==========================================================================================
* - load default CAN module configuration into configuration structure
*
* - define the interrupt priority for both interrupt node pointers used in the example
*
* - initialize CAN module with the modified configuration
* ==========================================================================================
*/
IfxMultican_Can_initModuleConfig(&g_multican.canConfig, &MODULE_CAN);

g_multican.canConfig.nodePointer[TX_INTERRUPT_SRC_ID].priority = ISR_PRIORITY_CAN_TX;
g_multican.canConfig.nodePointer[TX_INTERRUPT_SRC_ID].typeOfService = IfxSrc_Tos_cpu0;
g_multican.canConfig.nodePointer[RX_INTERRUPT_SRC_ID].priority = ISR_PRIORITY_CAN_RX;
g_multican.canConfig.nodePointer[RX_INTERRUPT_SRC_ID].typeOfService = IfxSrc_Tos_cpu0;

IfxMultican_Can_initModule(&g_multican.can, &g_multican.canConfig);

/* ==========================================================================================
* Source CAN node configuration and initialization:
* ==========================================================================================
* - load default CAN node configuration into configuration structure
*
* - set source CAN node in the "Loop-Back" mode (no external pins will be used)
* - assign source CAN node to CAN node 0
*
* - initialize the source CAN node with the modified configuration
* ==========================================================================================
*/
IfxMultican_Can_Node_initConfig(&g_multican.canNodeConfig, &g_multican.can);

IfxPort_PadDriver pinDriver;
g_multican.canNodeConfig.loopBackMode = FALSE;
g_multican.canNodeConfig.rxPin = &IfxMultican_RXD0B_P20_7_IN;
g_multican.canNodeConfig.txPin = &IfxMultican_TXD0_P20_8_OUT;
g_multican.canNodeConfig.nodeId = IfxMultican_NodeId_0;
g_multican.canNodeConfig.baudrate = 250000;

IfxMultican_Can_Node_init(&g_multican.canSrcNode, &g_multican.canNodeConfig);
/* ==========================================================================================
* Source message object configuration and initialization:
* ==========================================================================================
* - load default CAN message object configuration into configuration structure
*
* - define the message object ID
* - define the CAN message ID used during arbitration phase
* - define the message object as a transmit message object
* - enable interrupt generation in case of CAN message transmission
* - define interrupt node pointer to be used
*
* - initialize the source CAN message object with the modified configuration
* ==========================================================================================
*/
IfxMultican_Can_MsgObj_initConfig(&g_multican.canMsgObjConfig, &g_multican.canSrcNode);

g_multican.canMsgObjConfig.msgObjId = 0;
g_multican.canMsgObjConfig.messageId = 0x123;
g_multican.canMsgObjConfig.frame = IfxMultican_Frame_transmit;
g_multican.canMsgObjConfig.txInterrupt.enabled = TRUE;
g_multican.canMsgObjConfig.txInterrupt.srcId = TX_INTERRUPT_SRC_ID;
g_multican.canMsgObjConfig.control.extendedFrame = FALSE;
g_multican.canMsgObjConfig.control.singleDataTransfer = TRUE;
g_multican.canMsgObjConfig.control.singleTransmitTrial = TRUE;

IfxMultican_Can_MsgObj_init(&g_multican.canTxMsgObj, &g_multican.canMsgObjConfig);

IfxMultican_Can_MsgObj_initConfig(&g_multican.canMsgObjConfig, &g_multican.canSrcNode);
g_multican.canMsgObjConfig.msgObjId = 1;
g_multican.canMsgObjConfig.messageId = 0x7E8;
g_multican.canMsgObjConfig.frame = IfxMultican_Frame_receive;
g_multican.canMsgObjConfig.acceptanceMask = 0x7FFFFFFFUL;
g_multican.canMsgObjConfig.frame = IfxMultican_Frame_receive;
g_multican.canMsgObjConfig.control.messageLen = IfxMultican_DataLengthCode_8;
g_multican.canMsgObjConfig.control.extendedFrame = FALSE;
g_multican.canMsgObjConfig.control.matchingId = FALSE;
g_multican.canMsgObjConfig.gatewayTransfers = FALSE;
g_multican.canMsgObjConfig.rxInterrupt.enabled = TRUE;
g_multican.canMsgObjConfig.rxInterrupt.srcId = RX_INTERRUPT_SRC_ID;
g_multican.canMsgObjConfig.control.extendedFrame = 0;
IfxMultican_Can_MsgObj_init(&g_multican.canRxMsgObj, &g_multican.canMsgObjConfig);
}
0 Likes
2 Replies
User21869
Level 1
Level 1
I have solve the problem, but got another problem.
My previous code works well if I only need to capture frame with 1 ID.
But I have to receive many diffrent CAN Bus ID, how do i configure this?

Really apprecite any help
0 Likes
User21869
Level 1
Level 1
Finally solved,
I was set acceptanceMask = 0x7FFFFFFFUL, it means only match ID will be trigger interrupt.
Set this parameter to 0UL, will passing all frame that entered to message object.
0 Likes