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

XMC™ Forum Discussions

ipek
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked
Hi,

I have a setup with 2 XMC1400 boot kits. I connect their CAN transceiver pins to each other to form a CAN bus. I wrote a code. It sends CAN messages periodically and there is an interrupt handler triggered by the receiption of this
messages. I am running this code in both XMC's and they are working perfectly with a certain configuration(can node1, rxpin: P4_8, txpin P4_9).
But when I change can node ( node 1 to node 0 by using rxpin: P0_4, txpin P0_5) or change directions of the pins in the same node ( rxpin: P4_9, txpin P4_8 ) or use some other pins in the same node (can node1, rxpin: P1_2, txpin P1_3),
communication fails. LEDs indicating a message is received are not blinking. When I did debug, I saw that trasmint function returns with XMC_CAN_STATUS_BUSY after first round( at first round it returns XMC_CAN_STATUS_SUCCESS).
I did the required changes after changing the pin or node. My hardwares or cannections cannot be faulty because they work with the first configuration. So I am adding my code in here. I will be glad if anyone can take a look to find out
what am I missing.
I have a main and also a wrapper that wraps xmc can lib functionality. (My wrapper is reaaly primitive and wrote in a hurry. It is not perfect)I am adding the both of them. Commented lines represents the working configuration.

main:


/*
* main.c
*
* Created on: Feb 3, 2020
* Author: ip
*/

#include "XMC1400.h"
#include "CAN.h"
#include "Utilities.h"

#define TICKS_PER_SECOND 1000
#define LED0 P4_0
#define LED1 P4_1
#define LED2 P4_2
#define LED3 P4_3
#define RESET_PIN P3_4


#define CAN0_RXD P0_4
#define CAN0_TXD P0_5

//#define CAN1_RXD P4_8
//#define CAN1_TXD P4_9

#define MESSAGE_ID 0x700

XMC_CAN_MO_t rxMessage, rxMessage2;
XMC_CAN_MO_t txMessage, txMessage2;
uint8_t nodeID = 5;

static XMC_CAN_STATUS_t ret = 0;

int main(void)
{

//configure tick interrupt
SysTick_Config(SystemCoreClock /TICKS_PER_SECOND);

//initialize leds
configureGPIO(LED0, XMC_GPIO_MODE_OUTPUT_PUSH_PULL,XMC_GPIO_OUTPUT_LEVEL_HIGH);
configureGPIO(LED1, XMC_GPIO_MODE_OUTPUT_PUSH_PULL,XMC_GPIO_OUTPUT_LEVEL_HIGH);
configureGPIO(LED2, XMC_GPIO_MODE_OUTPUT_PUSH_PULL,XMC_GPIO_OUTPUT_LEVEL_HIGH);
configureGPIO(LED3, XMC_GPIO_MODE_OUTPUT_PUSH_PULL,XMC_GPIO_OUTPUT_LEVEL_HIGH);

//create message objects
rxMessage = createCAN_RxMessageObject(CAN_MO2, MESSAGE_ID + nodeID, 0xf, 8);
rxMessage2 = createCAN_RxMessageObject(CAN_MO3, 0, 0xf, 2);
txMessage = createCAN_TxMessageObject(CAN_MO4, MESSAGE_ID + nodeID, 8);
txMessage2 = createCAN_TxMessageObject(CAN_MO5, 0, 2);

//set can baudrate
baud = setCANBaudRate(1000000);

//initialize rx and tx pins
//w bad pins
configureGPIO(CAN0_TXD, XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT9,XMC_GPIO_OUTPUT_LEVEL_HIGH);
configureGPIO(CAN0_RXD, XMC_GPIO_MODE_INPUT_TRISTATE,XMC_GPIO_OUTPUT_LEVEL_HIGH);
//w good pins
// configureGPIO(CAN1_TXD, XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT9,XMC_GPIO_OUTPUT_LEVEL_HIGH);
// configureGPIO(CAN1_RXD, XMC_GPIO_MODE_INPUT_TRISTATE,XMC_GPIO_OUTPUT_LEVEL_HIGH);

//initialize can, set receive input, configure nominal bit timing
configureCANModule(NODE0, XMC_CAN_NODE_RECEIVE_INPUT_RXDCC);
// configureCANModule(NODE1, XMC_CAN_NODE_RECEIVE_INPUT_RXDCC);

//configure message object and allocate mo in the node list
configureAndAllocateCAN_MessageObject(rxMessage, NODE0, 2);
configureAndAllocateCAN_MessageObject(rxMessage2, NODE0, 3);
configureAndAllocateCAN_MessageObject(txMessage, NODE0, 4);
configureAndAllocateCAN_MessageObject(txMessage2, NODE0, 5);
// configureAndAllocateCAN_MessageObject(rxMessage, NODE1, 2);
// configureAndAllocateCAN_MessageObject(rxMessage2, NODE1, 3);
// configureAndAllocateCAN_MessageObject(txMessage, NODE1, 4);
// configureAndAllocateCAN_MessageObject(txMessage2, NODE1, 5);

//interrupt and stuff
XMC_CAN_MO_EnableEvent(&rxMessage, XMC_CAN_MO_EVENT_RECEIVE);
XMC_CAN_MO_EnableEvent(&rxMessage2, XMC_CAN_MO_EVENT_RECEIVE);
XMC_SCU_SetInterruptControl(6, XMC_SCU_IRQCTRL_CAN0_SR3_IRQ6);
XMC_CAN_MO_SetEventNodePointer(&rxMessage, XMC_CAN_MO_POINTER_EVENT_RECEIVE, 3);
XMC_CAN_MO_SetEventNodePointer(&rxMessage2, XMC_CAN_MO_POINTER_EVENT_RECEIVE, 3);
NVIC_SetPriority(6, 1);
NVIC_EnableIRQ(6);

//start
startCAN_Node(NODE0);
// startCAN_Node(NODE1);
while(1);
return ret;
}

void IRQ6_Handler(void) //direct messages
{
XMC_CAN_MO_Receive(&rxMessage);
XMC_CAN_MO_Receive(&rxMessage2);
toggleGPIO(LED0);
clearInterrupt(6);
}

void SysTick_Handler(void)
{
static uint32_t tick = 0;
tick++;
if(tick == 200)
{
toggleGPIO(LED2);
txMessage.can_data_long++;
XMC_CAN_MO_UpdateData(&txMessage);
ret = XMC_CAN_MO_Transmit(&txMessage);
}
if(tick == 500)
{
toggleGPIO(LED3);
txMessage2.can_data_long++;
XMC_CAN_MO_UpdateData(&txMessage2);
ret = XMC_CAN_MO_Transmit(&txMessage2);
}
if(tick == 1000)
{
uint32_t ret = readGPIOPin(RESET_PIN);
if(ret)
{
XMC_SCU_RESET_AssertMasterReset();
}
tick = 0;
}
}


wrapper:


/*
* CAN.h
*
* Created on: Feb 3, 2020
* Author: ip
*/

#include "xmc_can.h"
XMC_CAN_NODE_NOMINAL_BIT_TIME_CONFIG_t baud;

typedef enum CAN_NODE_SELECT
{
CAN_NODE_SELECT_NODE0 = 0,
CAN_NODE_SELECT_NODE1 = 1
} CAN_NODE_SELECT_t;

#define NODE1 CAN_NODE_SELECT_NODE1
#define NODE0 CAN_NODE_SELECT_NODE0

XMC_CAN_NODE_NOMINAL_BIT_TIME_CONFIG_t setCANBaudRate(uint32_t speed)/*CAN Bit time*/
{
XMC_CAN_NODE_NOMINAL_BIT_TIME_CONFIG_t tempBaud =
{
.can_frequency = 11000000,
.baudrate = speed, //500000,
.sample_point = 6000,
.sjw=3,
};
return tempBaud;
}

XMC_CAN_MO_t createCAN_RxMessageObject(CAN_MO_TypeDef* messageObject, uint32_t messageID, uint32_t messageID_Mask, uint8_t DLC)
{
XMC_CAN_MO_t temp =
{
.can_mo_ptr = messageObject,
.can_priority = XMC_CAN_ARBITRATION_MODE_IDE_DIR_BASED_PRIO_2,
.can_identifier = messageID,
.can_id_mask = messageID_Mask,
.can_id_mode = XMC_CAN_FRAME_TYPE_STANDARD_11BITS,
.can_ide_mask = 1,
.can_data_length = DLC,
.can_mo_type = XMC_CAN_MO_TYPE_RECMSGOBJ
};
return temp;
}
XMC_CAN_MO_t createCAN_TxMessageObject(CAN_MO_TypeDef* messageObject, uint32_t messageID, uint8_t DLC)
{
XMC_CAN_MO_t temp =
{
.can_mo_ptr = messageObject,
.can_priority = XMC_CAN_ARBITRATION_MODE_IDE_DIR_BASED_PRIO_2,
.can_identifier = messageID,
.can_id_mask= 0x7ff,
.can_id_mode = XMC_CAN_FRAME_TYPE_STANDARD_11BITS,
.can_ide_mask = 1,
.can_data_length = DLC,
.can_data = {0, 0},
.can_mo_type= XMC_CAN_MO_TYPE_TRANSMSGOBJ
};
return temp;
}
void configureCANModule(CAN_NODE_SELECT_t nodeNumber, XMC_CAN_NODE_RECEIVE_INPUT_t inputSource)
{
if(nodeNumber == CAN_NODE_SELECT_NODE1)
{
XMC_CAN_Init(CAN, XMC_CAN_CANCLKSRC_MCLK, 11000000);
XMC_CAN_NODE_EnableConfigurationChange(CAN_NODE1);
XMC_CAN_NODE_SetReceiveInput(CAN_NODE1, inputSource);
XMC_CAN_NODE_DisableConfigurationChange(CAN_NODE1);

/*NODE 1 initialization*/
XMC_CAN_NODE_EnableConfigurationChange(CAN_NODE1);
XMC_CAN_NODE_NominalBitTimeConfigure(CAN_NODE1, &baud);
XMC_CAN_NODE_DisableConfigurationChange(CAN_NODE1);
}
else
{
XMC_CAN_Init(CAN, XMC_CAN_CANCLKSRC_MCLK, 11000000);
XMC_CAN_NODE_EnableConfigurationChange(CAN_NODE0);
XMC_CAN_NODE_SetReceiveInput(CAN_NODE0, inputSource);
XMC_CAN_NODE_DisableConfigurationChange(CAN_NODE0);

/*NODE 0 initialization*/
XMC_CAN_NODE_EnableConfigurationChange(CAN_NODE0);
XMC_CAN_NODE_NominalBitTimeConfigure(CAN_NODE0, &baud);
XMC_CAN_NODE_DisableConfigurationChange(CAN_NODE0);
}
}

void configureAndAllocateCAN_MessageObject(XMC_CAN_MO_t messageObject, CAN_NODE_SELECT_t nodeNumber, uint32_t messageObjectNumber)
{
/*Configure message objects*/
XMC_CAN_MO_Config(&messageObject);
/* Allocate MO in Node List*/
XMC_CAN_AllocateMOtoNodeList(CAN,nodeNumber,messageObjectNumber);
}

void startCAN_Node(CAN_NODE_SELECT_t nodeNumber)
{
if(nodeNumber == CAN_NODE_SELECT_NODE1)
{
XMC_CAN_NODE_ResetInitBit(CAN_NODE1);
}
else
{
XMC_CAN_NODE_ResetInitBit(CAN_NODE0);
}
}

void clearInterrupt(IRQn_Type interruptNumer)
{
NVIC_ClearPendingIRQ(interruptNumer);
}



Edit: I have another wrapper that I use for GPIO stuff. Don't worry about configureGPIO(..) and toggleGPIO(..) they are tested. I am not adding their wrapper, I don't think it is necessary
0 Likes
3 Replies
User11996
Level 3
Level 3
Hi.

Did you change the input configuration for the new pin config.

I see in your code: configureCANModule(NODE0, XMC_CAN_NODE_RECEIVE_INPUT_RXDCC);

Here is a table for Node0:

// Pin-Config XMC14xx Node0:
/*

RX-A / 1: P0.4
RX-B / 2: P0.5
RX-C / 3: P0.14
RX-D / 4: P0.15
RX-E / 5: P2.0
RX-F / 6: P2.1
RX-G / 7: P1.0
RX-H / 8: P1.1

TX-A / 1: P0.5
TX-B / 2: P0.4
TX-C / 3: P0.15
TX-D / 4: P0.14
TX-E / 5: P2.1
TX-F / 6: P2.0
TX-G / 7: P1.1
TX-H / 8: P1.0

*/

And for Node1:


// Pin-Config XMC14xx Node1:
/*

RX-A / 1: P0.12.
RX-B / 2: P0.13.
RX-C / 3: P4.8.
RX-D / 4: P4.9.
RX-E / 5: P2.10.
RX-F / 6: P2.11.
RX-G / 7: P1.2.
RX-H / 8: P1.3.

TX-A / 1: P0.13
TX-B / 2: P0.12
TX-C / 3: P4.9
TX-D / 4: P4.8
TX-E / 5: P2.11
TX-F / 6: P2.10
TX-G / 7: P1.3
TX-H / 8: P1.2


*/
0 Likes
ipek
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked
Thanks for your answer 🙂

I change input configuration for new node as you suggested:


configureCANModule(NODE0, XMC_CAN_NODE_RECEIVE_INPUT_RXDCA);


But this didn't solve the problem unfortunately 😕 Still getting the same error.

And also I don't understand one thing, this configuration is about input but I shall configure tx too ? Correct me If I am wrong but tx is output right?
I sweep the xmc can library but I cannot find any function to configure output ilke this.. And I am not doing such configuration for other pin set but it works fine so, is that really necessary ?
0 Likes
User11996
Level 3
Level 3
Right.
For the TX - pin, no configuration is necessary for the TX pin at the XMC1400.
The only is the alternate function of the port pin, but on the xmc1400 all tx-pin's have the same alternat function: ALT9 for all konfigurations.

The combination of RX and TX pin is defined via the XMC_CAN_NODE_SetReceiveInput(CAN_NODEx , inputSource) function and also applies to the TX pin.

Example:
configureCANModule(NODE1, XMC_CAN_NODE_RECEIVE_INPUT_RXDCC) RX-Pin is P4.8; TX-Pin is P4.9
configureCANModule(NODE1, XMC_CAN_NODE_RECEIVE_INPUT_RXDCB) RX-Pin is P0.13; TX-Pin is P0.12

Have a look at my table.

You use for example: can node1, rxpin: P1_2, txpin P1_3
Than you have to use configureCANModule(NODE1, XMC_CAN_NODE_RECEIVE_INPUT_RXDCG)
0 Likes