Oct 24, 2016
02:19 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 24, 2016
02:19 PM
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
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
Labels
21 Replies
Oct 25, 2016
02:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 25, 2016
02:18 AM
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
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
Oct 25, 2016
01:56 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 25, 2016
01:56 PM
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
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
Oct 25, 2016
03:45 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 25, 2016
03:45 PM
Thanks for the comments. I'll try it and report the result here.
Bernd
Bernd
Oct 26, 2016
04:15 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 26, 2016
04:15 PM
I tried a lot but without result. Here is a snapshot of the MO-register after transmit:
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);
}
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);
}
Oct 27, 2016
02:34 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 27, 2016
02:34 AM
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
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
Oct 27, 2016
01:35 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 27, 2016
01:35 PM
I've further tested...The Init-Bit is set automaticly. That means an error has ocurred. The LEC-Field said "5"
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
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
Oct 28, 2016
07:49 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 28, 2016
07:49 AM
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.
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
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.
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
Oct 28, 2016
09:23 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 28, 2016
09:23 AM
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.
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
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
Oct 31, 2016
12:23 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Oct 31, 2016
12:23 PM
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
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
Nov 03, 2016
06:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nov 03, 2016
06:36 AM
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:
Best regards,
Deni
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
Not applicable
May 09, 2017
06:09 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May 09, 2017
06:09 AM
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.
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.
May 10, 2017
04:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May 10, 2017
04:27 AM
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
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
Not applicable
May 12, 2017
01:21 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May 12, 2017
01:21 AM
Thanks Jesus,
I will check these examples.
I will check these examples.
Not applicable
May 17, 2017
04:18 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May 17, 2017
04:18 AM
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.
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.
May 17, 2017
07:47 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
May 17, 2017
07:47 AM
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
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
Nov 07, 2017
09:54 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nov 07, 2017
09:54 AM
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
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
Nov 08, 2017
01:51 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Nov 08, 2017
01:51 PM
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
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
Aug 18, 2020
08:31 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 18, 2020
08:31 PM
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.
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.
Aug 19, 2020
06:36 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 19, 2020
06:36 AM
Hi,
Check the XMCLIb CAN_Receiver and CAN_Transmitter examples for XMC4800. They should be straight forward to port to XMC4200.
Regards,
Jesus
Check the XMCLIb CAN_Receiver and CAN_Transmitter examples for XMC4800. They should be straight forward to port to XMC4200.
Regards,
Jesus
Aug 20, 2020
12:03 PM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 20, 2020
12:03 PM
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.
Aug 25, 2020
08:52 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Aug 25, 2020
08:52 AM
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.