Working LPC15xx LQFP48 CAN Sample

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

Working LPC15xx LQFP48 CAN Sample

3,372 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Apr 24 07:04:14 MST 2015
This is a working CAN sample for LQFP48. Board library is included 

Working_CAN_Sample

[u]Note #1[/u]

This board library is a copy of the original LPCXpresso board library. To avoid pin muxing problems I've deleted all pin muxing entries in board_sysinit.c.

[u]Note #2[/u]

There are 3 LED's defined in board.c:

#define MAXLEDS 3
static const uint8_t ledpins[MAXLEDS] =  { 2, 3, 5};
static const uint8_t ledports[MAXLEDS] = { 0, 0, 0};


[u]Note #3[/u]

can.h is including options to switch to LOOPBACK / DAR  mode:

#define DAR_MODE//disable auto retransmission
#define LOOPBACK_MODE//enable LOOPBACK


[u]Note #4[/u]

CAN pins are selected in can_init() of can.c:

#ifdef LQFP48
//CAN signal muxing LQFP48
 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 18, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 13, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
 Chip_SWM_MovablePortPinAssign(SWM_CAN_TD1_O , 0, 18);
 Chip_SWM_MovablePortPinAssign(SWM_CAN_RD1_I,  0, 13);
#endif
#ifdef LQFP64
 /* Assign the pins rx 0[11] and tx 0[31] @ LQFP64 */
 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 11, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
 Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 31, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
 Chip_SWM_MovablePinAssign(SWM_CAN_RD1_I, 11);/* Rx P0.11 */
 Chip_SWM_MovablePinAssign(SWM_CAN_TD1_O, 31);/* Tx P0.31 */
#endif


LQFP48 / 64 is selected in can.h:

#define LQFP48//LQFP48 package


This pins are the default ISP CAN pins 

[u]LQFP48[/u]

CAN0_TD: PIO0_18 / Pin13
CAN0_RD: PIO0_13 / Pin21

Original Attachment has been moved to: Working_CAN_Sample.zip

标签 (1)
0 项奖励
回复
6 回复数

3,062 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fluchino on Mon Nov 23 06:05:11 MST 2015
I added a correction to the can_transmit function based on what I understood from the documentation:
uint32_t can_transmit(CAN_MSG_OBJ* message_object) {
...
// Check object number
if((message_object->msgobj < 1) || (message_object->msgobj > 32)) {
return 1;// Wrong message object
}
// Read pending transmission request of object
if(message_object->msgobj <= 16)
while(LPC_CAN->TXREQ1 & (1 << (message_object->msgobj - 1))) {}
else
while(LPC_CAN->TXREQ2 & (1 << (message_object->msgobj - 17))) {}
...

Correct me if I am wrong.
Regards,
FL
0 项奖励
回复

3,062 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by j.adtoorn on Wed Sep 09 11:47:15 MST 2015
Thank you very much for this helpful example! Running a custom board with LPC1549 LQFP64 mcu, got it to work pretty much right away. I added the pinout of the board to can.h, also ours uses a transceiver shutdown + mode select pin, which are added to can_init().
0 项奖励
回复

3,062 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri May 01 05:37:32 MST 2015
Good to hear that it's working now  :)
0 项奖励
回复

3,062 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Orac on Fri May 01 05:24:06 MST 2015
Many many thanks for this code and support.

Sorry I haven't been in touch for a while I've been sort out our issue.

I tried the above code (with CAN pins changed) on our board and found it not to work, I changed physically the CAN pins to that of your code, and ran your code totally unchanged, it didn't work.

We then built up another LPC1549 board, our design but minimum components, just clock, decoupling, ubiquitos LED and CAN transceiver hooked to ISP CAN pins as per your example. It worked! Hooray!

I then tried our application with CAN example embedded and it worked! Put the legs of the ICs back on the board to route CAN pins to our pins and yes, it worked!

So, going back to our original board, we have replaced the LPC1549 and now it works so I can only assume there was something wrong with the IC. I've never expercienced this before, I could toggle the pins as GPIO but the CAN peripheral could not be routed.

Anyway, all OK now, working and we are really really pleased and relieved, that you very very much for your help.

Regards
Pete
0 项奖励
回复

3,062 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Gmatarrubia on Tue Apr 28 08:43:31 MST 2015
Thank you so much!
0 项奖励
回复

3,054 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Apr 24 17:16:32 MST 2015
[u]Hardware Test[/u]

First of all it's important to check the CAN pins. SWM is assigning CAN TD/RD in can.c:

Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 18, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 13, (IOCON_MODE_INACT | IOCON_DIGMODE_EN));
Chip_SWM_MovablePortPinAssign(SWM_CAN_TD1_O , 0, 18);
Chip_SWM_MovablePortPinAssign(SWM_CAN_RD1_I,  0, 13);


Of course it's possible to select other pins. Using SWM can be tricky, so a few hints about common SWM pitfalls:

#1: Reset problems

As explained in UM...


Quote:
Remark: The switch matrix is only reset by a POR or BOD reset. A hardware reset via the RESET pin or a watchdog timer reset do not reset the switch matrix. Therefore, peripheral functions remain connected to pins through the hardware or watchdog reset and the pins remain input or output as defined by the switch matrix and assume the default state as defined by the peripheral connected to them.



...it's important to power cycle the board after changing SWM settings 

#2: Double assignment problems

Other peripherals can use the same pin   

UM:

Quote:
Remark: You are allowed to assign only one digital output function to an external pin at any given time.
Remark: You can assign more than one digital input function to one external pin.



So it's useful to debug PINASSIGNx registers of Periperals->SWM.

If SWM setup is correct, LOOPBACK mode can be used to check CAN without external transceiver. Just connect an oscilloscope...

[img=1268x442]http://www.lpcware.com/system/files/CAN_TXD.JPG[/img]
0 项奖励
回复