LPC1549 and CAN

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

LPC1549 and CAN

4,569 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TravisT on Wed Apr 16 10:53:20 MST 2014
Hello,

I am really interested in the LPC1549 because of the switch matrix and its many peripherals. One down side is it is still so new, and finding libraries for some of its features has proven to be hard.

My main concern really is the CAN library. It appears that both MBED and LPCopen do not have libraries for CAN. The ROM API is my next step but I am not that strong at lower level programming so I am not sure how fast I will be able to move forward with just the ROM API.

Does anybody know more about the status of a CAN library or could provide help with using the device with ROM or CMSIS to communicate (ideally J1939 compliant)

Thanks
Labels (1)
0 Kudos
Reply
37 Replies

2,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Apr 24 07:07:11 MST 2015
I've started a new thread here:

http://www.lpcware.com/content/forum/working-lpc15xx-lqfp48-can-sample
0 Kudos
Reply

2,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Orac on Fri Apr 24 07:02:21 MST 2015

Quote:
I'm not sure which hardware / debugger you are using, but I think I've a sample somewhere which is supporting my LQFP48 boards



Thank you. Apart from our own hardware based on LQFP48 1549, I have tested on an LPC1549 Xpresso V2 board with LPC_Link2. I am using LPCXpresso V7.6.2 under Linux, my colleagues have also tested the same code on the same board using I think V7.5.? under Windows.
0 Kudos
Reply

2,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Fri Apr 24 06:26:34 MST 2015

Quote: Orac
This is very frustrating...



Yes  :)  Although LPC15xx is a nice CAN MCU, CAN support is miserable  :((


Quote: Orac
I presume there are people with CAN working on these devices?



Yes  :)  But obviously they are using their own samples (or waiting for usable CAN / CANOpen samples from NXP since 02/2014)  :O


Quote: Orac
I'm not sure what to do next...



I'm not sure which hardware / debugger you are using, but I think I've a sample somewhere which is supporting my LQFP48 boards  :)

I'll try to find it later when I'm in my office again...

0 Kudos
Reply

2,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Orac on Fri Apr 24 06:10:01 MST 2015
Hello R2D2, thank you for your assistance.

I have now gone back to basics and have an lpcxpresso 1549 LQFP64 dev board and have compiled completely untouched the periph_ccan_rom example posted earlier. I have connected a CAN transceiver to the board (using GPIO  0.11 and 0.31) and have no CAN messages.

This is very frustrating. We have used many LPC devices, 11Cxx, 13xx, 17xx, 40xx, 43xx all without any problems on all perhiperals, but CAN on the 1549 is really causing us problems. I'm not sure what to do next, I presume there are people with CAN working on these devices?

Regards
0 Kudos
Reply

2,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue Apr 21 10:19:55 MST 2015
Before combining 2 projects I would strongly recommend to use the CAN sample above until it's working...

I'm not sure if you've already a working LQFP48 board library for your board and if you have used the debugger to check SWM pin settings  :O
0 Kudos
Reply

2,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Orac on Tue Apr 21 08:50:23 MST 2015
I didn't use the ISP CAN pin assignments because I needed all the analogue inputs. I probably should have specified the 64pin device, but we have 2 spare pins on the 48pin device so thought it was sufficient.
0 Kudos
Reply

2,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue Apr 21 08:31:18 MST 2015
Please rename your project before you export it  :)

BTW: Is there any reason why you don't use CAN-ISP pin assignment  :~

Quote:

PIO0_13 CAN0_RD LQFP48-Pin21
PIO0_18 CAN0_TD LQFP48-Pin13


0 Kudos
Reply

2,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Orac on Tue Apr 21 08:19:56 MST 2015
As requested project attached.

Please note, it is a hybrid of the periph_sct_pwm and ccan_rom examples. io.c, io.h, sct.c, sct.h are not being called and are their when I tested my original (several days ago) code.

In our project we have an LED on 0.29, CAN TX on 0.20 and CAN RX on 0.17.

Regards
Pete

0 Kudos
Reply

2,901 Views
garyaltenberg
Contributor II

Hi Pete,

I am working on a new board with a LPC1517. I found this thread and your post where you say the project is attached but I don't see the file. Maybe because this was moved. Would it be possible to get your sample project.

Thanks,

Gary

0 Kudos
Reply

2,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Tue Apr 21 08:07:17 MST 2015

Quote: Orac
Does anyone have any thoughts on what I could try please?



Just post your project  :) 
0 Kudos
Reply

2,900 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Orac on Tue Apr 21 07:40:12 MST 2015
Sorry to bring this thread to life again but I have read it many many times over the last few days during my attempts to get my bespoke LPC1549JBD48 design to work on a CAN bus.

I am using periph_sct_pwm from LPCopen as the base framework since I want to use the SCT as well. I have tried our own LPC11C24 C_CAN code which we have running in several projects but I can't get any CAN traffic at all, and I have scoped the TX input pin of the transceiver. If I don't configure the TX pin (I am using PIO0.20 as TX) I can see it toggle if I use LPC_GPIO->NOT[0] = (1<<20); After disabling the SWDIO and making the GPIO output.

I have also downloaded the ccan_rom example from a little way north in this thread, compiled it in to our applcation, routed the TX and RX to our pins, and again, no CAN traffic.

Does anyone have any thoughts on what I could try please? I've tried routing the CAN TX to a different pin and I don't see any action there either. All clocks seem to be enabled, and I have a flashing LED showing me the code is being executed.

Regards
0 Kudos
Reply

2,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by robin48gx on Thu Aug 07 02:55:10 MST 2014
OK ZeRo's example uses BASIC mode, where no filtering is applied.
0 Kudos
Reply

2,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by robin48gx on Thu Aug 07 01:56:06 MST 2014
Am still unclear on how te message filtering works in LPC1549.
There appears to be an array of message objects.
Some of these may have the DIR set to zero, and the mask and arb registers define the filter. Well thats how I think it works. But how do you set it into a mode where it actaully applies filtering?
0 Kudos
Reply

2,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by robin48gx on Wed Aug 06 03:56:41 MST 2014
I am able to send and receive CAN messages now.
Have modified ZeRo's code a little to make it use
extended addressing and to place a 29 bit identifier
correctly (the bits for the 11 bit standard and 29 bit
extended fit into different ARB registers --- a little confusing really).

Trying to get filtering of input messages working now, the user manual
is a little unclear on this but I am experimenting.

Will post my modifications to ZeRo's code if anyone asks. :)

0 Kudos
Reply

2,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Fri Aug 01 02:35:22 MST 2014

Quote: robin48gx
I am not able to TX messages yet...



Then scope PIO0_31,  PIO0_11 and your CAN lines to see if there's transmitted something...

You can also use LOOPBACK to receive your own transmitted message...
0 Kudos
Reply

2,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by robin48gx on Fri Aug 01 02:16:14 MST 2014
Thankyou for that, the handler is now the one being called after I invoke
(void CAN_Send(uint32_t *msg_ptr )).

Currently I have the C-RD and C-TD lines on the "LPC1549 Xpresso v2" board connected to a MAX3053 can txr. The Can High and low lines are connected to a working CAN 100 bps network, where I have an embedded linux system monitoring all CAN messages (which I am filtering with grep).

I am not able to TX messages yet, and after each message sending attempt, the CAN_IRQHandler is called, and this increments the error flag in the following part of the code as stepped though in the de-bugger.
can_stat = LPC_CAN->STAT;
if(can_int & CAN_STATUS_INTERRUPT)
{
  if(can_stat & STAT_EWARN)
  {
   EWarnCnt++;
  }
0 Kudos
Reply

2,901 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Thu Jul 31 09:17:26 MST 2014

Quote: robin48gx
I am trying to use the code ZeRo posted but keep getting a vector error at FFFFFFF9 (which I think is the vector for CAN0).



ISR names changed, try:

....
void CAN_IRQHandler(void)
....

0 Kudos
Reply

2,902 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by robin48gx on Thu Jul 31 08:10:39 MST 2014
Has a CAN library been released yet ? I am trying to use the code ZeRo posted but keep getting a vector error at FFFFFFF9 (which I think is the vector for CAN0).

I would really like a library that automatically switches pin selections between the 48 and 64 pin device. Just simple can message sending and on the reception side, filtering and queueing.
0 Kudos
Reply

2,904 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sun Jun 08 08:00:15 MST 2014
[h3]Note #5:[/h3]Another option to control transmissions would be reading CAN transmission request registers (TXREQ1-2)

Sample:
//transmit message #1
[color=#f00]    while(LPC_CAN->TXREQ1 & (1<<0)){}//read pending transmission request of object 0[/color]
    msg_obj.msgobj  = 0;
    msg_obj.mode_id = 0x700+ NODE_ID;
    msg_obj.mask    = 0x0;
    msg_obj.dlc     = 0x4;
    msg_obj.data[0] = 0x11;
    msg_obj.data[1] = 0x11;
    msg_obj.data[2] = 0x11;
    msg_obj.data[3] = 0x11;
    LPC_CAND_API->hwCAN_MsgTransmit(pCanHandle, &msg_obj);

//transmit message #2
[color=#f00]    while(LPC_CAN->TXREQ1 & (1<<0)){}//read pending transmission request of object 0[/color]
    msg_obj.msgobj  = 0;
    msg_obj.mode_id = 0x700 + NODE_ID+1;
    msg_obj.mask    = 0x0;
    msg_obj.dlc     = 3;
    msg_obj.data[0] = 0x22;
    msg_obj.data[1] = 0x22;
    msg_obj.data[2] = 0x22;
    LPC_CAND_API->hwCAN_MsgTransmit(pCanHandle, &msg_obj);


Unfortunately there's no CAN struct defined in LPCOpen (LPC15xx)   :~  Probably because it's also forgotten in LPCOpen (LPC11C24), as mentioned already here:

http://www.lpcware.com/content/forum/forgotten-can-register-struct-lpcxpresso-lpc11c24-lpcopen-v200a
0 Kudos
Reply

2,904 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by R2D2 on Sun Jun 08 06:10:27 MST 2014
[h3]Note #4:[/h3]Without overwrite protection mechanism, transmitting message objects can result in unexpected behavior.

Transmitting 2 messages isn't working as expected. Sample:

#define NODE_ID 0x20//own node id

//message #1
msg_obj.msgobj  = 0;
[color=#f00]msg_obj.mode_id = 0x700+ NODE_ID[/color];
msg_obj.mask    = 0x0;
[color=#f00]msg_obj.dlc     = 0x4;[/color]
msg_obj.data[0] = 0x11;
msg_obj.data[1] = 0x11;
msg_obj.data[2] = 0x11;
[color=#f00]msg_obj.data[3] = 0x11;[/color]
LPC_CAND_API->hwCAN_MsgTransmit(pCanHandle, &msg_obj);

//message #2
msg_obj.msgobj  = 0;
msg_obj.mode_id = 0x700 + NODE_ID+1;
msg_obj.mask    = 0x0;
msg_obj.dlc     = 3;
[color=#30f]msg_obj.data[0] = 0x22;
msg_obj.data[1] = 0x22;
msg_obj.data[2] = 0x22;[/color]
LPC_CAND_API->hwCAN_MsgTransmit(pCanHandle, &msg_obj);

C_CAN is transmitting a single message:

Quote:
[color=#f00]720 04 [/color][color=#30f]22 22 22 [/color][color=#f00]11[/color]


a mixture of message #1 and #2 

Of course that's the result of overwriting Message Object #0 while it is transmitted.

To avoid this it's useful to add a simple state control and wait until last message is transmitted.

Something like:
//wait 5ms before CAN_Fail
#define CAN_TX_TIME 5 

//CAN State
enum CAN_STATE
{
 CAN_Success,
 CAN_TX,
 CAN_Fail
};

//CAN
typedef struct _CAN_STATE
{
 volatile uint16_t timeout; //tx timeout
 volatile uint8_t  state;//CAN state
}CAN_STATE_t;
CAN_STATE_t can_state;

...
static void CAN_tx(uint8_t msg_obj)
{
 Board_LED_Toggle(1);//show TX
 can_state.state = CAN_Success;//success, ready to transmit next message
}
...
//CAN timer, call every ms in SysTick...
__attribute__((always_inline)) __INLINE void CAN_1ms_timer(void)
{
 //timer to control tx
 if(can_state.state == CAN_TX)
 {
  //timeout to fail
  if(can_state.timeout)
  {
   can_state.timeout--;
   if(can_state.timeout==0) can_state.state = CAN_Fail;
  }
 }
}

//transmit message #1
   while(!((can_state.state == CAN_Success) || (can_state.state == CAN_Fail))){}; //wait
    can_state.timeout = CAN_TX_TIME;//can timeout
    can_state.state = CAN_TX; //set tx busy flag
    msg_obj.msgobj  = 0;
    msg_obj.mode_id = 0x700+ NODE_ID;
    msg_obj.mask    = 0x0;
    msg_obj.dlc     = 0x4;
    msg_obj.data[0] = 0x11;
    msg_obj.data[1] = 0x11;
    msg_obj.data[2] = 0x11;
    msg_obj.data[3] = 0x11;
    LPC_CAND_API->hwCAN_MsgTransmit(pCanHandle, &msg_obj);

//transmit message #2
   while(!((can_state.state == CAN_Success) || (can_state.state == CAN_Fail))){}; //wait
    can_state.timeout = CAN_TX_TIME; //can timeout
    can_state.state = CAN_TX; //set tx busy flag
    msg_obj.msgobj  = 0;
    msg_obj.mode_id = 0x700 + NODE_ID+1;
    msg_obj.mask    = 0x0;
    msg_obj.dlc     = 3;
    msg_obj.data[0] = 0x22;
    msg_obj.data[1] = 0x22;
    msg_obj.data[2] = 0x22;
    LPC_CAND_API->hwCAN_MsgTransmit(pCanHandle, &msg_obj);


Of course another possible solution would be to use 2 Message Objects...
0 Kudos
Reply