trying to transmit via can

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

cross mob
Not applicable
Hello,
currently I have a problem with transmitting via can. Maybe some kind sole could spend some minutes and have a look at this small snipped:


void init()
{
CAN_message_4.can_mo_ptr = CAN_MO4;
CAN_message_4.can_priority = XMC_CAN_ARBITRATION_MODE_IDE_DIR_BASED_PRIO_2;
CAN_message_4.can_identifier = 0xff;
CAN_message_4.can_id_mask= 0xff;
CAN_message_4.can_id_mode = XMC_CAN_FRAME_TYPE_STANDARD_11BITS;
CAN_message_4.can_ide_mask = 1;
CAN_message_4.can_data_length = 8;
CAN_message_4.can_data[ 0 ] = 0x12345556;
CAN_message_4.can_data[ 1 ] = 0x12345556;
CAN_message_4.can_mo_type = XMC_CAN_MO_TYPE_TRANSMSGOBJ;

/* Configure CAN Module */
XMC_CAN_Init( CAN, can_frequency );

/* Configure Pinnin */
XMC_GPIO_SetMode( P1_5, XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1 );
XMC_CAN_NODE_SetReceiveInput( can_node, XMC_CAN_NODE_RECEIVE_INPUT_RXDCB );

/* Configure CAN Node baudrate */
XMC_CAN_NODE_NominalBitTimeConfigure( can_node, &baud );

/* NODE 1 initialization */
XMC_CAN_NODE_ResetInitBit( can_node );

/* Message 4 Configuration */
XMC_CAN_MO_Config( &CAN_message_4, can_node_nr, 4 );

/* Allocate MO in Node List */
XMC_CAN_AllocateMOtoNodeList( CAN, can_node_nr, 4 );

/*Enable nvic node*/
NVIC_EnableIRQ(CAN0_7_IRQn);
}

void test_send()
{
/*Send data in CAN_message_4*/
XMC_CAN_MO_Transmit( &CAN_message_4 );
}


I call the function init() once and the function test_send() periodically. XMC_CAN_MO_Transmit() returns XMC_CAN_STATUS_SUCCESS. can_node is equal to CAN_NODE1 and can_node_nr equal to 1. The code is running on a xmc4200 hexagon board. Looking at the transmission pin 1.5, I'm measuring a constant hight (~3.3V). What am I'm missing here? I'm unsure about the parameter to the XMC_CAN_MO_Config() function.

Kind regards,
Torsten
0 Likes
6 Replies
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
Hi Torsten,

Please hang on.. I will try to get you an example.

Best regards
Travis
0 Likes
Not applicable
Hi Travis,
that would be wonderful. Thank you very much.

kind regards,
Torsten
0 Likes
Not applicable
Hi Torsten,

I think, you must change your initial code. Firstly, You must add MO to Node and next reset init bit.


/* Allocate MO in Node List */
XMC_CAN_AllocateMOtoNodeList( CAN, can_node_nr, 4 );

/* NODE 1 initialization */
XMC_CAN_NODE_ResetInitBit( can_node );

/* Message 4 Configuration */
XMC_CAN_MO_Config( &CAN_message_4, can_node_nr, 4 );


Best regards
Blackom
0 Likes
lock attach
Attachments are accessible only for community members.
Travis
Employee
Employee
First solution authored Welcome! 500 replies posted
This is the CAN example using the DAVE4 LLD using loop back method.
0 Likes
Not applicable
Hallo Blackom, Hallo Travis,
thank you very much for your input. I've incorporated your input. I've changed the init code now to reset the Init bit as one of the last actions (like in the Dave example). In addition, I use the XMC_GPIO_Init() for Pin configuration (as in the Dave example).

In addition, I've enable frame counting to see if the hardware believes that it can transmit messages and only the pin setting is wrong.

Unfortunately there is still no output on the can bus. If I use a debugger to inspect the frame counter, I don't see the counter increasing:

(gdb) p/x *can_node
$2 = {NCR = 0x1, NSR = 0x25, NIPR = 0x0, NPCR = 0x1, NBTR = 0x1801, NECNT = 0x600000, NFCR = 0x400000}


I see one big difference between my setting and the Dave setting. I've set the can_frequency to 12E6 while in the Dave example it's 12E7. If I use 12E7, an assert in XMC_CAN_Init() fires, because the condition can_frequency < peripheral_frequency is not satisfied. My peripheral_frequency is 8E7. Could this be a problem?

Next on my list is, to check every register of the CAN_GLOBAL, the CAN_NODE and the Message Object. Any tipps, on what to inspect in addition?

Here is my current init function

void init()
{
CAN_message_4.can_mo_ptr = CAN_MO4;
CAN_message_4.can_priority = XMC_CAN_ARBITRATION_MODE_IDE_DIR_BASED_PRIO_2;
CAN_message_4.can_identifier = 0xff;
CAN_message_4.can_id_mask= 0xff;
CAN_message_4.can_id_mode = XMC_CAN_FRAME_TYPE_STANDARD_11BITS;
CAN_message_4.can_ide_mask = 1;
CAN_message_4.can_data_length = 8;
CAN_message_4.can_data[ 0 ] = 0x12345556;
CAN_message_4.can_data[ 1 ] = 0x12345556;
CAN_message_4.can_mo_type = XMC_CAN_MO_TYPE_TRANSMSGOBJ;

/* Configure CAN Module */
XMC_CAN_Init( CAN, can_frequency );

/* Configure CAN Node baudrate */
/* A valid CAN bit timing must be written to the CAN Node Bit Timing Register NBTR before
resetting the INIT bit in the Node Control Register, i.e. before enabling the operation of the CAN node. */
/* this function calls XMC_CAN_NODE_EnableConfigurationChange/XMC_CAN_NODE_DisableConfigurationChange on its own */
XMC_CAN_NODE_NominalBitTimeConfigure( can_node, &baud );

XMC_CAN_NODE_EnableConfigurationChange( can_node );
XMC_CAN_NODE_SetInitBit( can_node );

/* Configure Input Pin */
static const XMC_GPIO_CONFIG receive_pin_config = {
XMC_GPIO_MODE_INPUT_TRISTATE,
// a valid output level have to be set, even for input pins; otherwise XMC_GPIO_Init() will assert.
XMC_GPIO_OUTPUT_LEVEL_LOW };
XMC_GPIO_Init( P1_4, &receive_pin_config );
XMC_CAN_NODE_SetReceiveInput( can_node, XMC_CAN_NODE_RECEIVE_INPUT_RXDCB );

XMC_CAN_NODE_EnableEvent( can_node, XMC_CAN_NODE_EVENT_CFCIE );

/* Allocate MO in Node List */
XMC_CAN_AllocateMOtoNodeList( CAN, can_node_nr, 4 );

/* Message 4 Configuration */
XMC_CAN_MO_Config( &CAN_message_4, can_node_nr, 4 );

XMC_CAN_NODE_DisableConfigurationChange( can_node );

/* NODE initialization */
XMC_CAN_NODE_ResetInitBit( can_node );

/* Configure Output Pin */
static const XMC_GPIO_CONFIG_t transmit_pin_config = {
XMC_GPIO_MODE_OUTPUT_PUSH_PULL_ALT1,
XMC_GPIO_OUTPUT_LEVEL_HIGH,
XMC_GPIO_OUTPUT_STRENGTH_STRONG_SHARP_EDGE
};
XMC_GPIO_Init( P1_5, &transmit_pin_config );

/*Enable nvic node*/
NVIC_EnableIRQ(CAN0_7_IRQn);
}
0 Likes
Not applicable
I got it! Fantastic!!! Juhu 🙂 I got the receive Pin configuration wrong. I thought pin 1.4 was input B, as it was the 2 input in the table 22-12. But there is an addition table 15-14 that states, that P1.4 is CAN.CAN1_RXDC1D. So it's D, not B. Thank you all very much for your help.
0 Likes