Announcements

Equip yourself to optimize AURIX™ MCUs for Evs at the EV Webinar. Click here to register.

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

AURIX™ Forum Discussions

SteveZhan
Level 1
Level 1
First solution authored First reply posted First question asked

Hello Infineon,

I'm tring a real CAN comunication test on KIT_A2G_TC397_3V3_TFT board, the receive hardware is ValueCAN3,  the KIT_A2G_TC397_3V3_TFT board send a CAN  message and the ValueCAN3 receive it, but when I ran the code, and set  ValueCAN3 the same baudrate, there is nothing received.  The code as below:

typedef struct
{
IfxCan_Can_Config canConfig; /* CAN module configuration structure */
IfxCan_Can canModule; /* CAN module handle */
IfxCan_Can_Node can02Node; /* CAN source node handle data structure */
IfxCan_Can_NodeConfig canNodeConfig; /* CAN node configuration structure */
IfxCan_Filter canFilter; /* CAN filter configuration structure */
IfxCan_Message txMsg; /* Transmitted CAN message structure */
IfxCan_Message rxMsg; /* Received CAN message structure */
uint32 txData[MAXIMUM_CAN_DATA_PAYLOAD]; /* Transmitted CAN data array */
uint32 rxData[MAXIMUM_CAN_DATA_PAYLOAD]; /* Received CAN data array */
} McmcanType;

 

#define ISR_PRIORITY_CAN_TX 1
#define ISR_PRIORITY_CAN_RX 2
#define ISR_PRIORITY_CAN_BUSOFF 3


#define MODEL_CAN0_RAM 0xF0200000
#define NODE0_RAM_OFFSET 0x0

#define CAN_ID_FILTER 0x50

IFX_CONST IfxCan_Can_Pins Can02_Pins =
{
&IfxCan_TXD02_P10_3_OUT, IfxPort_OutputMode_pushPull,
&IfxCan_RXD02E_P10_2_IN, IfxPort_InputMode_pullUp,
IfxPort_PadDriver_cmosAutomotiveSpeed2
};

McmcanType g_mcmcan;
IfxPort_Pin_Config g_led1;
IfxPort_Pin_Config g_led2;

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

void canIsrTxHandler(void)
{
/* Clear the "Transmission Completed" interrupt flag */
IfxCan_Node_clearInterruptFlag(g_mcmcan.can02Node.node, IfxCan_Interrupt_transmissionCompleted);

/* Just to indicate that the CAN message has been transmitted by turning on LED1 */
IfxPort_setPinLow(g_led1.port, g_led1.pinIndex);
}

void canIsrRxHandler(void)
{
/* Clear the "Message stored to Dedicated RX Buffer" interrupt flag */
IfxCan_Node_clearInterruptFlag(g_mcmcan.can02Node.node, IfxCan_Interrupt_messageStoredToDedicatedRxBuffer);

//IfxCan_Node_clearRxBufferNewDataFlag(g_mcmcan.can02Node.node, g_mcmcan.canFilter.rxBufferOffset);


/* Read the received CAN message */
IfxCan_Can_readMessage(&g_mcmcan.can02Node, &g_mcmcan.rxMsg, g_mcmcan.rxData);

/* Check if the received data matches with the transmitted one */
if( g_mcmcan.rxMsg.messageId == CAN_ID_FILTER )
{
/* Turn on the LED2 to indicate correctness of the received message */
IfxPort_setPinLow(g_led2.port, g_led2.pinIndex);
}
else
{
IfxPort_setPinHigh(g_led2.port, g_led2.pinIndex);
}
}

void canIsrBusoffHandler(void)
{
IfxCan_Node_clearInterruptFlag(g_mcmcan.can02Node.node, IfxCan_Interrupt_busOffStatus);
InitCan();
}

void InitCan(void)
{

boolean iState = IfxCpu_disableInterrupts();

IfxCan_Can_initModuleConfig(&g_mcmcan.canConfig, &MODULE_CAN0);

IfxCan_Can_initModule(&g_mcmcan.canModule, &g_mcmcan.canConfig);

IfxCan_Can_initNodeConfig(&g_mcmcan.canNodeConfig, &g_mcmcan.canModule);

g_mcmcan.canNodeConfig.busLoopbackEnabled = FALSE;
g_mcmcan.canNodeConfig.nodeId = IfxCan_NodeId_0;
g_mcmcan.canNodeConfig.clockSource = IfxCan_ClockSource_both;
g_mcmcan.canNodeConfig.frame.type = IfxCan_FrameType_transmitAndReceive;
g_mcmcan.canNodeConfig.frame.mode = IfxCan_FrameMode_standard;

g_mcmcan.canNodeConfig.txConfig.txMode = IfxCan_TxMode_dedicatedBuffers;
g_mcmcan.canNodeConfig.txConfig.dedicatedTxBuffersNumber = 16;
g_mcmcan.canNodeConfig.txConfig.txBufferDataFieldSize = IfxCan_DataFieldSize_8;

g_mcmcan.canNodeConfig.rxConfig.rxMode = IfxCan_RxMode_dedicatedBuffers;
g_mcmcan.canNodeConfig.rxConfig.rxBufferDataFieldSize = IfxCan_DataFieldSize_8;

g_mcmcan.canNodeConfig.filterConfig.messageIdLength = IfxCan_MessageIdLength_standard;
g_mcmcan.canNodeConfig.filterConfig.standardListSize = 10;
g_mcmcan.canNodeConfig.filterConfig.extendedListSize = 0;
// g_mcmcan.canNodeConfig.filterConfig.standardFilterForNonMatchingFrames = IfxCan_NonMatchingFrame_reject;
// g_mcmcan.canNodeConfig.filterConfig.extendedFilterForNonMatchingFrames = IfxCan_NonMatchingFrame_reject;

g_mcmcan.canNodeConfig.messageRAM.standardFilterListStartAddress = 0x100;
g_mcmcan.canNodeConfig.messageRAM.rxBuffersStartAddress = 0x200;
g_mcmcan.canNodeConfig.messageRAM.txBuffersStartAddress = 0x400;
g_mcmcan.canNodeConfig.messageRAM.baseAddress = MODEL_CAN0_RAM + NODE0_RAM_OFFSET;

g_mcmcan.canNodeConfig.baudRate.baudrate = 250000;

g_mcmcan.canNodeConfig.interruptConfig.transmissionCompletedEnabled = TRUE;
g_mcmcan.canNodeConfig.interruptConfig.traco.priority = ISR_PRIORITY_CAN_TX;
g_mcmcan.canNodeConfig.interruptConfig.traco.interruptLine = IfxCan_InterruptLine_0;
g_mcmcan.canNodeConfig.interruptConfig.traco.typeOfService = IfxSrc_Tos_cpu0;


g_mcmcan.canNodeConfig.interruptConfig.messageStoredToDedicatedRxBufferEnabled = TRUE;
g_mcmcan.canNodeConfig.interruptConfig.reint.priority = ISR_PRIORITY_CAN_RX;
g_mcmcan.canNodeConfig.interruptConfig.reint.interruptLine = IfxCan_InterruptLine_1;
g_mcmcan.canNodeConfig.interruptConfig.reint.typeOfService = IfxSrc_Tos_cpu0;

g_mcmcan.canNodeConfig.pins = &Can02_Pins;

IfxCan_Can_initNode(&g_mcmcan.can02Node, &g_mcmcan.canNodeConfig);

g_mcmcan.canFilter.number = 1;
g_mcmcan.canFilter.elementConfiguration = IfxCan_FilterElementConfiguration_storeInRxBuffer;
g_mcmcan.canFilter.id1 = CAN_ID_FILTER;
g_mcmcan.canFilter.rxBufferOffset = IfxCan_RxBufferId_0;
IfxCan_Can_setExtendedFilter(&g_mcmcan.can02Node,&g_mcmcan.canFilter);

IfxCpu_restoreInterrupts(iState);
}


void TransmitCanData(void)
{
IfxCan_Can_initMessage(&g_mcmcan.txMsg);

g_mcmcan.txMsg.messageId = 0x60;
//g_mcmcan.txMsg.bufferNumber = 0;
g_mcmcan.txMsg.dataLengthCode = IfxCan_DataLengthCode_8;
g_mcmcan.txMsg.frameMode = IfxCan_FrameMode_standard;
g_mcmcan.txMsg.messageIdLength = IfxCan_MessageIdLength_standard;

/* Define the content of the data to be transmitted */
g_mcmcan.txData[0] = 0x11223344;
g_mcmcan.txData[1] = 0x55667788;

/* Send the CAN message with the previously defined TX message content */
while( IfxCan_Status_notSentBusy ==
IfxCan_Can_sendMessage(&g_mcmcan.can02Node, &g_mcmcan.txMsg, &g_mcmcan.txData[0]) )
{
}

}

void InitLeds(void)
{
g_led1.port = &MODULE_P13;
g_led1.pinIndex = PIN0;
g_led1.mode = IfxPort_OutputIdx_general;
g_led1.padDriver = IfxPort_PadDriver_cmosAutomotiveSpeed1;

g_led2.port = &MODULE_P13;
g_led2.pinIndex = PIN1;
g_led2.mode = IfxPort_OutputIdx_general;
g_led2.padDriver = IfxPort_PadDriver_cmosAutomotiveSpeed1;

/* Initialize the pins connected to LEDs to level "HIGH", which keep the LEDs turned off as default state */
IfxPort_setPinHigh(g_led1.port, g_led1.pinIndex);
IfxPort_setPinHigh(g_led2.port, g_led2.pinIndex);

/* Set the pin input/output mode for both pins connected to the LEDs */
IfxPort_setPinModeOutput(g_led1.port, g_led1.pinIndex, IfxPort_OutputMode_pushPull, g_led1.mode);
IfxPort_setPinModeOutput(g_led2.port, g_led2.pinIndex, IfxPort_OutputMode_pushPull, g_led2.mode);

/* Set the pad driver mode for both pins connected to the LEDs */
IfxPort_setPinPadDriver(g_led1.port, g_led1.pinIndex, g_led1.padDriver);
IfxPort_setPinPadDriver(g_led2.port, g_led2.pinIndex, g_led2.padDriver);
}

void Delay(void)
{
uint32 a = 10000;

while(a!= 0)
{
a--;
}

 

void core0_main(void)
{
IfxCpu_enableInterrupts();

/* !!WATCHDOG0 AND SAFETY WATCHDOG ARE DISABLED HERE!!
* Enable the watchdogs and service them periodically if it is required
*/
IfxScuWdt_disableCpuWatchdog(IfxScuWdt_getCpuWatchdogPassword());
IfxScuWdt_disableSafetyWatchdog(IfxScuWdt_getSafetyWatchdogPassword());

/* Wait for CPU sync event */
IfxCpu_emitEvent(&g_cpuSyncEvent);
IfxCpu_waitEvent(&g_cpuSyncEvent, 1);

InitCan();
InitLeds();

while(1)
{
TransmitCanData();
Delay();
}
}

please help me find the wrong settings in my code.

0 Likes
1 Solution

Thanks, I have solved this problem. I set the wrong noed ID.

  

View solution in original post

0 Likes
2 Replies
Nambi
Moderator
Moderator
Moderator
First like given 25 likes received 50 solutions authored

Hi,

1. From the section "3.10 MultiCAN" in the Kit User-Manual(https://www.infineon.com/dgdl/Infineon-ApplicationKitManual_TC3X7-UM-v02_00-EN.pdf?fileId=5546d46269...), Could you confirm that the  CAN pins you have configured are the ones that are connected to the CAN Transceiver?

2. Could you monitor the CANH and CANL pins to see if there is any traffic on these pins in the TFT kit?

Best Regards.

0 Likes

Thanks, I have solved this problem. I set the wrong noed ID.

  

0 Likes