XMCLib CAN config

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

cross mob
User9605
Level 1
Level 1
Hi,
I'm looking for a complete example for the CAN-configuration with real outputs. All what I found here was for the loopback-mode.
I use a XMC4200 with CAN0 on P1.4/1.5.
I tryed this but nothing happens on P1.5 (before CAN-transceiver):

XMC_CAN_Init(CAN,80000000);
XMC_CAN_NODE_NominalBitTimeConfigure(CAN_NODE0,&baud);
XMC_CAN_NODE_EnableConfigurationChange(CAN_NODE0);
XMC_CAN_NODE_SetReceiveInput(CAN_NODE0,XMC_CAN_NODE_RECEIVE_INPUT_RXDCA);
XMC_CAN_NODE_DisableLoopBack(CAN_NODE0);
XMC_GPIO_SetMode(XMC_GPIO_PORT1, 5, XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1);
XMC_CAN_NODE_DisableConfigurationChange(CAN_NODE0);
XMC_CAN_NODE_ResetInitBit(CAN_NODE0);
XMC_CAN_MO_Config(&CAN_message_4);
XMC_CAN_AllocateMOtoNodeList(CAN, 0, 4);
XMC_CAN_MO_Transmit(&CAN_message_4);

structure of baud and MO are all set.
Does somebody has any idea what missing?

Thanks
Bernd
0 Likes
21 Replies
DRubeša
Employee
Employee
First solution authored First like received
Hi,

first that caught my eye is that you don´t have "XMC_CAN_NODE_SetInitBit(CAN_NODE0)" but you have "XMC_CAN_NODE_ResetInitBit(CAN_NODE0)". They usual go in pair. Place the "XMC_CAN_NODE_SetInitBit(CAN_NODE0)" after "XMC_CAN_NODE_EnableConfigurationChange(CAN_NODE0)".
Also try to switch the position of "XMC_CAN_MO_Config(&CAN_message_4)" and "XMC_CAN_AllocateMOtoNodeList(CAN, 0, 4)". First we want to allocate the MO to the node and then configure it. Maybe it won´t have an impact maybe it will.

Try these suggestions and let me know how it went...if necessary, I will give it second, more thorough look. But also please post next time whole code (including baudrate and MO structures).

P.S I hope you set the GPIO pins properly....above I only see the setting mode for the TX pin. What is lacking is the RX pin, but I don´t know do you have this defined somewhere else.

Best regards,
Deni
0 Likes
User12373
Level 1
Level 1
Hi Bernd,

I ran into the exact same problem last week. I was implementing CAN communication support in the OpenBLT bootloader. I use the XMC4700 Relax Kit, so that might be slightly different from a pinning point of view, but this is what I had to
do from a pin configuration point of view, after the CAN controller was initialized:

XMC_GPIO_CONFIG_t rx_can_config;
XMC_GPIO_CONFIG_t tx_can_config;

/* configure CAN receive pin */
rx_can_config.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
XMC_GPIO_Init(P1_13, &rx_can_config);
/* configure CAN transmit pin */
tx_can_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT2;
tx_can_config.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
tx_can_config.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SOFT_EDGE;
XMC_GPIO_Init(P1_12, &tx_can_config);
/* select CAN Receive Input C (N1_RXDC) to map P1_13 to CAN_NODE1 */
XMC_CAN_NODE_EnableConfigurationChange(CAN_NODE1);
XMC_CAN_NODE_SetReceiveInput(CAN_NODE1, XMC_CAN_NODE_RECEIVE_INPUT_RXDCC);
XMC_CAN_NODE_DisableConfigurationChange(CAN_NODE1);

You can download the OpenBLT bootloader package from https://sourceforge.net/projects/openblt/ for the full example.

Good luck!

-Frank
0 Likes
User9605
Level 1
Level 1
Thanks for the comments. I'll try it and report the result here.

Bernd
0 Likes
User9605
Level 1
Level 1
I tried a lot but without result. Here is a snapshot of the MO-register after transmit:
2383.attach
The tx-pending-flag keep clear. It looks as if a condition is missing but which?
My whole code:

#include
#include

#define CAN_FREQUENCY 80000000

#define CAN0_RX P1_4
#define CAN0_TX P1_5

#define LED1 P1_2
#define LED2 P1_3

#define TICKS_PER_SECOND 2000
#define TICKS_WAIT 1000


/*CAN Bit time*/
XMC_CAN_NODE_NOMINAL_BIT_TIME_CONFIG_t baud =
{
.can_frequency = CAN_FREQUENCY,
.baudrate = 125000,
.sample_point = 8000,
.sjw = 1,
};

// MO4 Transmit
XMC_CAN_MO_t CAN_message_4 =
{
.can_mo_ptr = CAN_MO4,
.can_priority = XMC_CAN_ARBITRATION_MODE_IDE_DIR_BASED_PRIO_2,
.can_identifier = 0x200,
.can_id_mask= 0xff,
.can_id_mode = XMC_CAN_FRAME_TYPE_STANDARD_11BITS,
.can_ide_mask = 1,
.can_data_length = 8,
.can_data = {0x11223344, 0x55667788},
.can_mo_type = XMC_CAN_MO_TYPE_TRANSMSGOBJ
};
// MO2 receive
XMC_CAN_MO_t CAN_message_2 =
{
.can_mo_ptr = CAN_MO2,
.can_priority = XMC_CAN_ARBITRATION_MODE_IDE_DIR_BASED_PRIO_2,
.can_identifier = 0x300,
.can_id_mask = 0xff,
.can_id_mode = XMC_CAN_FRAME_TYPE_STANDARD_11BITS,
.can_ide_mask = 1,
.can_data_length = 8,
.can_mo_type = XMC_CAN_MO_TYPE_RECMSGOBJ
};

void SysTick_Handler(void)
{
uint32_t index;
static uint32_t ticks = 0;

ticks++;
if (ticks == TICKS_WAIT)
{

// XMC_CAN_MO_Transmit(&CAN_message_4);
XMC_GPIO_ToggleOutput(LED1);
XMC_GPIO_ToggleOutput(LED2);

ticks = 0;
}
}
//###################################################################################
int main(void)
{
XMC_GPIO_CONFIG_t config;
config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL;
config.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
config.output_strength = XMC_GPIO_OUTPUT_STRENGTH_MEDIUM;
XMC_GPIO_Init(LED1, &config);
XMC_GPIO_Init(LED2, &config);
//
XMC_GPIO_CONFIG_t rx_can_config;
XMC_GPIO_CONFIG_t tx_can_config;

/* configure CAN receive pin */
rx_can_config.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
XMC_GPIO_Init(P1_4, &rx_can_config);
/* configure CAN transmit pin */
tx_can_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1;
tx_can_config.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
tx_can_config.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SOFT_EDGE;
XMC_GPIO_Init(P1_5, &tx_can_config);

XMC_CAN_NODE_EnableConfigurationChange(CAN_NODE0);
XMC_CAN_NODE_SetInitBit(CAN_NODE0);

XMC_CAN_Init(CAN,CAN_FREQUENCY);
XMC_CAN_NODE_NominalBitTimeConfigure(CAN_NODE0,&baud);
XMC_CAN_NODE_SetReceiveInput(CAN_NODE0,XMC_CAN_NODE_RECEIVE_INPUT_RXDCA);
XMC_CAN_NODE_DisableLoopBack(CAN_NODE0);
XMC_CAN_AllocateMOtoNodeList(CAN, 0, 4);
XMC_CAN_MO_Config(&CAN_message_4);
XMC_CAN_MO_SetEventNodePointer(&CAN_message_4, XMC_CAN_MO_POINTER_EVENT_TRANSMIT, 7);
XMC_CAN_MO_EnableEvent(&CAN_message_4, XMC_CAN_MO_EVENT_TRANSMIT);

XMC_CAN_NODE_DisableConfigurationChange(CAN_NODE0);
XMC_CAN_NODE_ResetInitBit(CAN_NODE0);

NVIC_EnableIRQ(CAN0_7_IRQn);

SysTick_Config(SystemCoreClock / TICKS_PER_SECOND);


/*Send data in CAN_message_4*/

XMC_CAN_MO_UpdateData(&CAN_message_4);
XMC_CAN_MO_ResetStatus(&CAN_message_4, XMC_CAN_MO_RESET_STATUS_TX_PENDING);
XMC_CAN_MO_Transmit(&CAN_message_4);
while ((XMC_CAN_MO_GetStatus(&CAN_message_4) & XMC_CAN_MO_STATUS_TX_PENDING) != 0)
{
XMC_GPIO_ToggleOutput(LED1);
}
while(1);
}
//-----------------------------------------------------------------
void CAN0_7_IRQHandler(void)
{
XMC_GPIO_ToggleOutput(LED1);
XMC_GPIO_ToggleOutput(LED2);
}
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi,

can you also please post the figure of the CAN_NODE0 NSR register after you try to transmit the MO? From the MO status register I see that message is not transmitted successfully (meaning it´s probably sent correctly but it wasn´t acknowledged by the another node). Can you please also post the code for the receiver side or at least can you be sure that the receiver side is set properly (I don´t know what you connected to the other side of the CAN bus)?

When I have more information, it will make things much more easier to debug.

Best regards,
Deni
0 Likes
User9605
Level 1
Level 1
I've further tested...The Init-Bit is set automaticly. That means an error has ocurred. The LEC-Field said "5"
2389.attach
I still have no receiver on the bus. Tx und Rx-pin are connected direct to the driver-ic (ISO1050). The bus is terminated by 120Ohm. I have an "Oszi" on the Tx-pin. But I can't see a "low".
The rx-pin is high too.

What means this error? I can't interpret the description in the datasheet.

Thanks
Bernd
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi,

so what I can tell you currently is that you have one bug (at least). The problem is that even when I fix that issue is still cannot get proper CAN transmission (I´m not using your code; I wanted to develop similar application using your board but also a receiver on another side. I´m using CAN_NODE APPs and also an example using CAN CMSIS driver).

But what I can tell you is that you need to change the node you´re using. You currently use node 0, while you should be using node 1 while the pins 1.4 and 1.5 are connected to node 1 not 0.

2391.attach

Unfortunately, I cannot say this is the only mistake while I´m still trying to get example running...but you can also try to change this node value and see do you have some changes. But I must tell you that successful CAN transmission you´ll achieve once you connect receiver side. The problem is that transmitting CAN node needs to receive ACK bit to consider transmission successful. In your current configuration there isn´t any node which can confirm successful receive. So, I guess you´ll get LEC error code 3, meaning transmitting node was transmitting but there wasn´t ACK bit. You will also note in register bitfield NECNT.TEC value 0x80 (128). This means that TX node attempted to send M0 128 times but there wasn´t any ACK bit, so TX node become passive (it disconnected itself from the CAN bus). If you get that error, that´s a good sign...then you just need to connect receiving side.

Best regards,
Deni
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi,

I took additional look at your code and I found some additional bugs...this version will at least try to transmit the message to the CAN bus but as I said, you need other side to be connected also.

#include 
#include

#define CAN_FREQUENCY 80000000

#define CAN0_RX P1_4
#define CAN0_TX P1_5

#define LED1 P1_2
#define LED2 P1_3

#define TICKS_PER_SECOND 2000
#define TICKS_WAIT 1000


/*CAN Bit time*/
XMC_CAN_NODE_NOMINAL_BIT_TIME_CONFIG_t baud =
{
.can_frequency = CAN_FREQUENCY,
.baudrate = 125000,
.sample_point = 8000,
.sjw = 1,
};

// MO4 Transmit
XMC_CAN_MO_t CAN_message_4 =
{
.can_mo_ptr = CAN_MO4,
.can_priority = XMC_CAN_ARBITRATION_MODE_IDE_DIR_BASED_PRIO_2,
.can_identifier = 0x200,
.can_id_mask= 0xff,
.can_id_mode = XMC_CAN_FRAME_TYPE_STANDARD_11BITS,
.can_ide_mask = 1,
.can_data_length = 8,
.can_data = {0x11223344, 0x55667788}, // <--- be aware that means that lower part of data will be 0x55667788, and higher 0x11223344
.can_mo_type = XMC_CAN_MO_TYPE_TRANSMSGOBJ
};
// MO2 receive
XMC_CAN_MO_t CAN_message_2 =
{
.can_mo_ptr = CAN_MO2,
.can_priority = XMC_CAN_ARBITRATION_MODE_IDE_DIR_BASED_PRIO_2,
.can_identifier = 0x300,
.can_id_mask = 0xff,
.can_id_mode = XMC_CAN_FRAME_TYPE_STANDARD_11BITS,
.can_ide_mask = 1,
.can_data_length = 8,
.can_mo_type = XMC_CAN_MO_TYPE_RECMSGOBJ
};

void SysTick_Handler(void)
{
uint32_t index;
static uint32_t ticks = 0;

ticks++;
if (ticks == TICKS_WAIT)
{

// XMC_CAN_MO_Transmit(&CAN_message_4);
XMC_GPIO_ToggleOutput(LED1);
XMC_GPIO_ToggleOutput(LED2);

ticks = 0;
}
}
//################################################## #################################
int main(void)
{
XMC_GPIO_CONFIG_t config;
config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL;
config.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
config.output_strength = XMC_GPIO_OUTPUT_STRENGTH_MEDIUM;
XMC_GPIO_Init(LED1, &config);
XMC_GPIO_Init(LED2, &config);
//
XMC_GPIO_CONFIG_t rx_can_config;
XMC_GPIO_CONFIG_t tx_can_config;

/* initialize CAN module */
XMC_CAN_Init(CAN,CAN_FREQUENCY); // <- first enabling of the CAN module then everything else

/* configure CAN receive pin */
rx_can_config.mode = XMC_GPIO_MODE_INPUT_TRISTATE;
XMC_GPIO_Init(P1_4, &rx_can_config);

/* configure CAN transmit pin */
tx_can_config.mode = XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1;
tx_can_config.output_level = XMC_GPIO_OUTPUT_LEVEL_HIGH;
tx_can_config.output_strength = XMC_GPIO_OUTPUT_STRENGTH_STRONG_SOFT_EDGE;
XMC_GPIO_Init(P1_5, &tx_can_config);

/* define baudrate */
XMC_CAN_NODE_NominalBitTimeConfigure(CAN_NODE1,&baud);

/* enable configuration changes and keep the node disconnected from the bus */
XMC_CAN_NODE_EnableConfigurationChange(CAN_NODE1);
XMC_CAN_NODE_SetInitBit(CAN_NODE1);

/* set receive input */
XMC_CAN_NODE_SetReceiveInput(CAN_NODE1, XMC_CAN_NODE_RECEIVE_INPUT_RXDCD); // <--- change here: XMC_CAN_NODE_RECEIVE_INPUT_RXDCD

/* allocate message object to node list */
XMC_CAN_AllocateMOtoNodeList(CAN, 1, 4); // <--- change here: 1

/* configure message object*/
XMC_CAN_MO_Config(&CAN_message_4);

/* set interrupt node pointer */
XMC_CAN_MO_SetEventNodePointer(&CAN_message_4, XMC_CAN_MO_POINTER_EVENT_TRANSMIT, 7);

/* define interrupt trigger event */
XMC_CAN_MO_EnableEvent(&CAN_message_4, XMC_CAN_MO_EVENT_TRANSMIT);

/* reset CCE and INIT bit NCR for node configuration */
XMC_CAN_NODE_DisableConfigurationChange(CAN_NODE1) ;
XMC_CAN_NODE_ResetInitBit(CAN_NODE1);

/* setting interrupt priority */
NVIC_SetPriority(CAN0_7_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 63U, 0U)); // <--- change here: add this line

/* enable interrupt */
NVIC_EnableIRQ(CAN0_7_IRQn);

SysTick_Config(SystemCoreClock / TICKS_PER_SECOND);

/*Send data in CAN_message_4*/
XMC_CAN_MO_Transmit(&CAN_message_4);

while ((XMC_CAN_MO_GetStatus(&CAN_message_4) & XMC_CAN_MO_STATUS_TX_PENDING) != 0)
{
XMC_GPIO_ToggleOutput(LED1);
}

while(1);
}
//-----------------------------------------------------------------
void CAN0_7_IRQHandler(void)
{
XMC_GPIO_ToggleOutput(LED1);
XMC_GPIO_ToggleOutput(LED2);
}


Try to run this code on your board and verify that you got at least LEC error code 3 instead of 5 🙂 it´s still an error but it´s better error 😄

Best regards,
Deni
0 Likes
User9605
Level 1
Level 1
Hi Deni,
at first a big thanks for your patience with my problem. The wrong node number was a big mistake but unfortunatly not the solution. I tried your code with same result, no reaction on Tx-pin and LEC error is still 5.
Today I've installed a second board as receiver with same code (but the Id's are adjusted). As I expected nothing happens. Before I can receive an ACK must I send a frame correctly.
As next step I created the code with DAVE4 (without interrupts; with a single transmit). The result is endless traffic on the tx-pin an bus. It becomes mysterious 🙂
But my board seems to be ok.
Many thanks!
Bernd
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
Hi Bernd,

hm hm...So it´s really strange that example didn´t work for you and that you also have issues with the DAVE APPs (I guess you used CAN_NODE APP; I have also example for it so if you need I can send it to you). So, this leads to suspect that there are some hardware relevant issues. I see you´re using ISO1050 as a CAN transceiver. This is means that you´re not using XMC4200 Boot kit but standalone XMC4200 on the PCB you developed? Can you please check the logical level on the TX and RX pins BEFORE transmitting the message. The M0 cannot be transmitted if the bus is not in recessive state (meaning it should be in logical "1"). Can you please verify this is a case with your board?

Also, have you considered this note given in ISO1050 documentation:
TXD is very weakly internally pulled up to VCC1. An external pullup resistor should be used
to make sure that TXD is biased to recessive (high) level to avoid issues on the bus if the
microprocessor doesn't control the pin and TXD floats. TXD pullup strength and CAN bit
timing require special consideration when the device is used with an open-drain TXD
output on the CAN controller of the microprocessor. An adequate external pullup resistor
must be used to ensure that the TXD output of the microprocessor maintains adequate bit
timing input to the input on the transceiver.


Best regards,
Deni
0 Likes
Not applicable
Hi Den,

I am also trying to set-up the CAN communication between two devices and using DAVE4 for XMC4500. I am transmitting a message from XMC4500 but not receiving anything at the other end.
Not sure how to debug it? As you mentioned if you have an example that you have tested, can you share it or suggest.
0 Likes
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi,

have a look to the examples in the XMClib, http://dave.infineon.com/Libraries/XMCLib/XMC_Peripheral_Library_v2.1.12.zip
Specifically at XMCLib\examples\XMC4500_series\CAN\CAN_RECEIVER and XMCLib\examples\XMC4500_series\CAN\CAN_TRANSMITTER

Regards,
Jesus
0 Likes
Not applicable
Thanks Jesus,

I will check these examples.
0 Likes
Not applicable
Hi Jesus,

I explored the examples sent by you. those were very helpful.
I am facing other problem now. I am using CAN app in DAVE. I am receiving the packet but want to access the data bytes received. Couldn't find the right parameter in the message object structure to do it. I want to copy the received bytes in unit8_t array for further processing.

Kindly suggest.
0 Likes
DRubeša
Employee
Employee
First solution authored First like received
HI Kaur,

for this you can take a look at the MULTICAN_CONFIG_EXAMPLE_XMC47 (http://www.infineon.com/cms/en/product/promopages/aim-mc/dave_downloads.html), more precisely to "CAN_IRQHandler" function which reads-out the data and stores the data to an array.

But in summary, you use "CAN_NODE_MO_Receive(CAN_NODE_LMO_t *lmo_ptr)" or "XMC_CAN_MO_Receive(XMC_CAN_MO_t *can_mo)"...this will read the hardware RX buffer and store the value to the "can_mo->can_data[0/1]" array. Then all you need to do is to assign your "unit8_t array" to "can_data" member of the "XMC_CAN_MO" structure as shown in the mentioned example.

Best regards,
Deni
0 Likes
User14115
Level 1
Level 1
Hi

Any one has working sample code CAN bus for DAVE 4 not in loopback mode. I can received the message but i cannot make it to work to transmit data back.

Ed
0 Likes
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi,

See the examples in the XMCLib, i.e. XMCLib\examples\XMC4500_series\CAN\CAN_TRANSMITTER and XMCLib\examples\XMC4500_series\CAN\CAN_RECEIVER.

Regards,
Jesus
0 Likes
User20078
Level 1
Level 1
Hi, am new to Infineon, have been working with other Micro-controllers, have bought two xmc4200 Arduino platform2go, i want to connect the 2 boards and demonstrate CAN commutation, i want to send 0 to the receiving board and the
receiving board to send a 1 to the transmitting board as notification of the successfully commutation and then the transmitting board sends a 2 then a receiving sends a 3 as acknowledgment. and this continues, firstly i cant find how the
connection can be made between 2 boards secondly, can someone direct me to some example code that is at least close to what i want to achieve.

Thank you.
0 Likes
jferreira
Employee
Employee
10 sign-ins 5 sign-ins First like received
Hi,

Check the XMCLIb CAN_Receiver and CAN_Transmitter examples for XMC4800. They should be straight forward to port to XMC4200.

Regards,
Jesus
0 Likes
User20078
Level 1
Level 1
DRubeša wrote:
Hi Bernd,

hm hm...So it´s really strange that example didn´t work for you and that you also have issues with the DAVE APPs (I guess you used CAN_NODE APP; I have also example for it so if you need I can send it to you). So, this leads to suspect that there are some hardware relevant issues. I see you´re using ISO1050 as a CAN transceiver. This is means that you´re not using XMC4200 Boot kit but standalone XMC4200 on the PCB you developed? Can you please check the logical level on the TX and RX pins BEFORE transmitting the message. The M0 cannot be transmitted if the bus is not in recessive state (meaning it should be in logical "1"). Can you please verify this is a case with your board?

Also, have you considered this note given in ISO1050 documentation:
TXD is very weakly internally pulled up to VCC1. An external pullup resistor should be used
to make sure that TXD is biased to recessive (high) level to avoid issues on the bus if the
microprocessor doesn't control the pin and TXD floats. TXD pullup strength and CAN bit
timing require special consideration when the device is used with an open-drain TXD
output on the CAN controller of the microprocessor. An adequate external pullup resistor
must be used to ensure that the TXD output of the microprocessor maintains adequate bit
timing input to the input on the transceiver.


Best regards,
Deni


I have been looking for example codes for CAN transmit and receive but I can't find any. can some one point me to where I can find example codes specifically for XMC4200 PLATFORM 2GO.
ALSO I want connect two XMC4200 platform 2Go via CANBus, any recommendation resources because the data sheet doesn't have this information.
0 Likes
User19299
Level 2
Level 2
First solution authored
CEPHASKALEMBO wrote:
I have been looking for example codes for CAN transmit and receive but I can't find any. can some one point me to where I can find example codes specifically for XMC4200 PLATFORM 2GO.
ALSO I want connect two XMC4200 platform 2Go via CANBus, any recommendation resources because the data sheet doesn't have this information.


Check the Reference Manual of the XMC4200. The Data Sheet doesn't have everything.
0 Likes