LPC4337 CAN0, CAN1: stuck in Chip_CCAN_Send

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC4337 CAN0, CAN1: stuck in Chip_CCAN_Send

1,126 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by monnoliv on Thu Jun 18 04:41:51 MST 2015
Hi,

I'm using the LPC4337 for a while now. Since I have some problem with the CANs peripherals in mycode, I finally decided to use and test the lpcopen periph_can example.
The problem is that the periph_can example stay stuck with the Chip_CCAN_GetTxRQST() function (called in a while loop by Chip_CCAN_Send() ).
This function always return 1 instead of 0 then the Chip_CCAN_Send() function never return.

I can see with a scope that a frame is sent (however I don't know if this frame is complete).

Is someone has encountered this kind of problem?

Regards,

Olivier


For info, example code:
CCAN_MSG_OBJ_T send_obj;
SystemCoreClockUpdate();
Board_Init();
set_pinmux();
//DEBUGOUT(WelcomeMenu);
/* Set CCAN peripheral clock under 100Mhz for working stable */
Chip_Clock_SetBaseClock(CLK_BASE_APB3, CLKIN_IDIVC, true, false);
Chip_CCAN_Init(LPC_C_CAN0);
Chip_CCAN_SetBitRate(LPC_C_CAN0, 500000);
Chip_CCAN_EnableInt(LPC_C_CAN0, (CCAN_CTRL_IE | CCAN_CTRL_SIE | CCAN_CTRL_EIE));

send_obj.id = CCAN_TX_MSG_ID;
send_obj.dlc = 4;
send_obj.data[0] = 'A';
send_obj.data[1] = 'B';
send_obj.data[2] = 'C';
send_obj.data[3] = 'D';
Chip_CCAN_Send(LPC_C_CAN0, CCAN_MSG_IF2, FALSE, &send_obj);  <----- STUCK HERE
Chip_CCAN_ClearStatus(LPC_C_CAN0, CCAN_STAT_TXOK);
Labels (1)
0 Kudos
12 Replies

951 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Orac on Fri Jun 26 06:58:53 MST 2015
Great, I'm glad it is now working, and thank you for updating the thread with your success.

Have fun

Regards
Pete
0 Kudos

951 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by monnoliv on Fri Jun 26 06:58:19 MST 2015
Sorry, tks also to starblue for his answers.
:-)
0 Kudos

951 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by monnoliv on Fri Jun 26 06:37:11 MST 2015
Thank you Pete, I just got it!
On the OM13070 board, Pin 3.1 is muxed with others outputs. At first glance, I didn't noticed that P3.1 is not connected by default to J6Pin2. I had to desolder a solder jump (JS9) and solder another one (JS10).
Now it works :-)

I would like to thank you for your support (you put me on the right track).
Regards,

Olivier
0 Kudos

951 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Orac on Fri Jun 26 06:13:08 MST 2015
The only thing I can think is that for some reason the clocks are wrong or not clocking.

During my debugging I added an awful lot of extra code and I'm not sure what is and isn't relavent but for the APB3 clock settings i've used:

Chip_Clock_SetDivider(CLKIN_IDIVC, CLKIN_MAINPLL, 6);
Chip_Clock_EnableBaseClock(CLK_BASE_APB3);
Chip_Clock_EnableBaseClock(CLK_BASE_APB1);
Chip_Clock_SetBaseClock(CLK_BASE_APB3, CLKIN_IDIVC, true, false);
Chip_Clock_SetBaseClock(CLK_BASE_APB1, CLKIN_IDIVC, true, false);


APB1 for CAN 1 and APB3 for CAN0

From your scope trace your pulses are not at 500kbaud so I don't think you are getting a whole CAN frame out.

The code above assumes a core clock of 204MHz and CLKIN_IDIVC is set to 6 giving a PCLK for the CCAN at 34MHz.

I have a LPC4357 eval board at home which is probably closer to your LPC4337 board which I'll try this on if the above doesn't help.

Regards
Pete
0 Kudos

951 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by monnoliv on Fri Jun 26 05:49:01 MST 2015
Hi Pete,

Thank you for your answer, I really appreciate your help.

I didn't take care about the transceiver, then I probed TD and RD to see if feedback was performed and it is (see snapshot)
Concerning pinmux I've checked everywhere in the code (including board.c) and the only pinmux is on the example code:
static void set_pinmux(void)
{
#if defined(BOARD_NXP_LPCXPRESSO_4337)
Chip_SCU_PinMuxSet(0x3, 1, (SCU_MODE_INACT | SCU_MODE_INBUFF_EN | SCU_MODE_FUNC2)); /* CAN RD */
Chip_SCU_PinMuxSet(0x3, 2, (SCU_MODE_INACT | SCU_MODE_FUNC2)); /* CAN TD */
#else
#warning "No pin muxing set for this board"
#endif
}

I connected the transceiver on the pin 2 (P3.1) and 4(P3.2) of the J6 connector (LPCXpresso4337 OM13070 board).
Since I have a spare part of the same board, I've uploaded the example on it and had the same result. The code hang at Chip_CCAN_Send, more precisely in
STATIC INLINE uint32_t Chip_CCAN_GetTxRQST(LPC_CCAN_T *pCCAN)
{
return pCCAN->TXREQ1 | (pCCAN->TXREQ2 << 16);
}

This function is embedded in a while loop, it seems that pCCAN->TXREQ1 stay at 1 instead of returning to 0

I've made also some tests with LPC11C24 chip as a second node, this one works perfectly with the LPCOpen example.

I really don't know where to dig now.

If someone has a working example for the OM13070 board (then with a LPC4337 chip), please give it to me!

Thank you,

Olivier
0 Kudos

951 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Orac on Thu Jun 25 04:29:12 MST 2015
Hi,

I've been having the same problems with a custom LPC4370 design. They've been solved now both for CAN0 and CAN1.

Our issue was for CAN0 we had an isolated CAN transceiver which didn't have its isolated side powered, this meant (I think) the LPC4370 couldn't assert the bus and read it back on the RX pin. Powering the isolated side fixed the problem.

For CAN1, the issue was the PIN MUX was the wrong way round so the TX pin was having its input buffer enabled and the RX pin not having its input buffer enabled. This was fixed by getting the settings the right way round.

In both cases our code was hanging in the Chip_CCAN_Send routine...

Hope this helps people with the same problem.

Regards
Pete
0 Kudos

951 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by monnoliv on Mon Jun 22 02:13:56 MST 2015
Hello,

Always with my CAN problem,
Here is my code and a scope snapshot of the TD pin. This snapshot never change whatever the kind and the number of bytes transmitted. Help
uint32_t freq;
CCAN_MSG_OBJ_T send_obj;
SystemCoreClockUpdate();
Board_Init();
set_pinmux();
DEBUGOUT(WelcomeMenu);

freq = Chip_Clock_GetBaseClocktHz(CLK_BASE_APB3);

// FREQ IS 204 MHz HERE

/* Set CCAN peripheral clock under 50Mhz for working stable */
Chip_Clock_SetBaseClock(CLK_BASE_APB3, CLKIN_IDIVE, TRUE, FALSE);

freq = Chip_Clock_GetBaseClocktHz(CLK_BASE_APB3); // Frequency verification

// FREQ IS 12 MHZ HERE

Chip_CCAN_Init(LPC_C_CAN0);
Chip_CCAN_SetBitRate(LPC_C_CAN0, 50000);
Chip_CCAN_EnableInt(LPC_C_CAN0, (CCAN_CTRL_IE | CCAN_CTRL_SIE | CCAN_CTRL_EIE));


send_obj.id = CCAN_TX_MSG_ID;
send_obj.dlc = 2;
send_obj.data[0] = 'A';
send_obj.data[1] = 'B';

Chip_CCAN_Send(LPC_C_CAN0, CCAN_MSG_IF1, false, &send_obj);  // <--- ALWAYS STUCK HERE

0 Kudos

951 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by monnoliv on Fri Jun 19 01:19:46 MST 2015
Can someone give me a simple CAN example that works ?
I've two boards: the LPCXpresso4337 and the NGX one
0 Kudos

951 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by monnoliv on Thu Jun 18 06:48:33 MST 2015
Sorry but to be sure, I just downloaded the lpcopen zip file (lpcopen_2_16_lpcxpresso_nxp_lpcxpresso_4337.zip) and extract to a new workspace (I'm using LPCXpresso) then run the "periph_ccan" example, and the program stuck at the same line of code.
To be sure about the clock, I put
Chip_Clock_SetBaseClock(CLK_BASE_APB3, CLKIN_IDIVE, true, false);
, hence CLKIN_IDIVE as a new clock divider. The Chip_Clock_GetRate return 12MHz that seems to be in spec.
But no way...

(BTW: I've just downloaded the new UM, wasn't aware of an update)
0 Kudos

951 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by starblue on Thu Jun 18 06:25:49 MST 2015

Quote: monnoliv
If not, how to know the frequency the can engine use? I measured a 500kbit/s at the output, but internal ?


I would check the various divisors (all of them, and make sure everything is consistent).

If I were really motivated and/or desperate I would put the clock on a pin and measure it.

Though I don't think a wrong clock is the cause of your problems, for us a 200MHz clock just caused some flakiness.  I would guess it is just some ordinary bug.
0 Kudos

951 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by monnoliv on Thu Jun 18 06:12:33 MST 2015
Yes, I know this. I assume that the example code here is good.
If not, how to know the frequency the can engine use? I measured a 500kbit/s at the output, but internal ?
0 Kudos

951 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by starblue on Thu Jun 18 05:56:49 MST 2015

Quote: monnoliv
/* Set CCAN peripheral clock under 100Mhz for working stable */


According to the UM that should be at most 50 MHz.
0 Kudos