LPC1769 Can Driver

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

LPC1769 Can Driver

9,138 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ajay on Wed Mar 23 16:20:53 MST 2011
Has anyone been able to successfully get CAN to work on the LPCXpresso 1769?
0 Kudos
Reply
61 Replies

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LeGhimp on Fri Jun 14 01:42:08 MST 2013
Zero,

I tried to integrate the files you posted for auto detecting the baudrate.
And I do have 1 problem. In  the CLKPWR_GetPCLK function from lpc17xx_clkpwr.c the functions calls a global variable "SystemCoreClock" .

The oscilator which my board uses is a 12MHz oscilator.

Should I set SystemCoreClock = 12000000.
Or I am getting this wrong?
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MAUROFIUNER on Tue Jan 22 05:37:29 MST 2013
Local Self Test works fine! Now I'm trying with Global Self Test..
Thanks a lot Zero!
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Jan 17 08:47:31 MST 2013
[LEFT]See #4 of this thread http://knowledgebase.nxp.com/showthread.php?p=5962 ;)


Quote:
[COLOR=Red]Without transceiver[/COLOR] you can just connect RD1 / TD1 with something like 1k resistor[COLOR=Red] to simulate a transceiver.[/COLOR]

So you should be able to transmit a message in[COLOR=Red] Self Test Mode[/COLOR] even with LPCXpresso and RD / TD bridge without transceiver.

[/LEFT]
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MAUROFIUNER on Thu Jan 17 06:43:59 MST 2013
I have put a 1K resistor between TD1 and RD1???

Why? Is this always needs? I´m using lcpxpresso baseboard whit lcp1769, I can't send any message fine, error frame is transmitted indefinitely, 1k resistor between TD1 and RD1 can help me?

Sorry for my english.
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Nov 16 09:27:23 MST 2012
What's wrong with http://www.support.code-red-tech.com/CodeRedWiki/NXPDriverLibraries :confused:

Already discussed in #3 of this thread :eek:

Note: Please create a [COLOR=Red]new thread[/COLOR] for a new question and don't add your questions to old threads.
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tarik1985 on Fri Nov 16 09:11:40 MST 2012
hello,

i want to program my LPCXpresso lpc1769 with language C but i don't know which software to use to do it

i want also to create a program in language C which receive the data from the CANbus and save it in my computer in txt file.



thank you
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MAUROFIUNER on Wed Nov 14 06:10:34 MST 2012
Thanks a lot! I'm beginner in CAN protocols.
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Nov 13 12:56:19 MST 2012

Quote: MAUROFIUNER
I don´t know why signal go down when should maintain high.



Bit-Stuffing :eek:

http://www.softing.com/home/en/industrial-automation/products/can-bus/more-can-bus/bit-encoding/bit-...
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by MAUROFIUNER on Tue Nov 13 12:46:14 MST 2012
I'm trying to send a messagge with LCPXpresso-LPC1769,but I can´t..
I don´t know why signal go down when should maintain high.

Excuse my bad English!

My code is:

#include "lpc17xx_can.h"
#include "lpc17xx_libcfg.h"
#include "lpc17xx_pinsel.h"
#include "debug_frmwrk.h"
#include "lpc17xx_gpio.h"

/* Example group ----------------------------------------------------------- */
/** @defgroup CAN_LedControlCAN_LedControl
* @ingroup CAN_Examples
* @{
*/

/************************** PRIVATE VARIABLES *************************/
uint8_t menu[]=
"*******************************************************************************\n\r"
"Hello NXP Semiconductors \n\r"
"CAN demo \n\r"
"\t - MCU: LPC17xx \n\r"
"\t - Core: ARM CORTEX-M3 \n\r"
"\t - Communicate via: UART0 - 115200 bps \n\r"
"Use two CAN peripherals: CAN1 and CAN2 to communicate\n\r"
"Use CAN frames to control LED display\n\r"
"*******************************************************************************\n\r";

/** CAN variable definition **/
CAN_MSG_Type TXMsg, RXMsg; // messages for test Bypass mode
uint8_t LED_Value;
uint32_t LED[8] = {(1<<6),(1<<5),(1<<4),(1<<3),(1<<2),(1<<31),(1<<29),(1<<28)};

/************************** PRIVATE FUNCTIONS *************************/
void CAN_IRQHandler(void);

void CAN_InitMessage(void);
//void print_menu();

/*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
/*********************************************************************//**
* @briefCAN_IRQ Handler, control receive message operation
* param[in]none
* @return none
**********************************************************************/
void CAN_IRQHandler()
{
uint8_t IntStatus;
uint32_t data,i;
/* get interrupt status
* Note that: Interrupt register CANICR will be reset after read.
* So function "CAN_IntGetStatus" should be call only one time
*/
IntStatus = CAN_IntGetStatus(LPC_CAN2);
//check receive interrupt
if((IntStatus>>0)&0x01)
{
CAN_ReceiveMsg(LPC_CAN2,&RXMsg);
data = RXMsg.dataA[0];
for(i=0;i<8;i++)
{
if ((data >> i)&0x01)
{
if(i<5)
GPIO_SetValue(2,LED);
else
GPIO_SetValue(1,LED);
}
else
{
if(i<5)
GPIO_ClearValue(2,LED);
else
GPIO_ClearValue(1,LED);
}
}

}
}

/*-------------------------PRIVATE FUNCTIONS----------------------------*/
/*********************************************************************//**
* @briefInitialize transmit and receive message for Bypass operation
* @param[in]none
* @return none
**********************************************************************/
void CAN_InitMessage(void) {
TXMsg.format = STD_ID_FORMAT;
TXMsg.id = 0x7ff;
TXMsg.len = 8;
TXMsg.type = DATA_FRAME;
TXMsg.dataA[0] = TXMsg.dataA[1] = TXMsg.dataA[2] = TXMsg.dataA[3] = 0xffffffff;
TXMsg.dataB[0] = TXMsg.dataB[1] = TXMsg.dataB[2] = TXMsg.dataB[3] = 0xffffffff;

RXMsg.format = 0x00;
RXMsg.id = 0x00;
RXMsg.len = 0x00;
RXMsg.type = 0x00;
RXMsg.dataA[0] = RXMsg.dataA[1] = RXMsg.dataA[2] = RXMsg.dataA[3] = 0x00000000;
RXMsg.dataB[0] = RXMsg.dataB[1] = RXMsg.dataB[2] = RXMsg.dataB[3] = 0x00000000;
}

/*-------------------------MAIN FUNCTION------------------------------*/
/*********************************************************************//**
* @briefc_entry: Main CAN program body
* @param[in]none
* @return int
**********************************************************************/
int c_entry(void) { /* Main Program */
PINSEL_CFG_Type PinCfg;

/* LED setting */
GPIO_SetDir(1,(1<<28)|(1<<29)|(1<<31),1);
GPIO_SetDir(2,(1<<2)|(1<<3)|(1<<4)|(1<<5)|(1<<6),1);


/* Pin configuration
  *CAN1: select 0.0 as RD1. P0.1 as TD1
*/
PinCfg.Funcnum = 1;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
PinCfg.Pinnum = 0;
PinCfg.Portnum = 0;
PINSEL_ConfigPin(&PinCfg);
PinCfg.Pinnum = 1;
PINSEL_ConfigPin(&PinCfg);

// CAN2 Pins P0.4 as RD2 and P0.5 as TD2
  PinCfg.Funcnum = 2;
  PinCfg.Pinnum = 4;
  PinCfg.Portnum = 0;
  PINSEL_ConfigPin(&PinCfg);
  PinCfg.Pinnum = 5;
  PINSEL_ConfigPin(&PinCfg);

//Initialize CAN1 & CAN2
CAN_Init(LPC_CAN1, 125000);
CAN_Init(LPC_CAN2, 125000);

//Enable Interrupt
CAN_IRQCmd(LPC_CAN2, CANINT_RIE, ENABLE);
CAN_SetAFMode(LPC_CANAF,CAN_AccBP);
CAN_InitMessage();



//Enable CAN Interrupt
NVIC_EnableIRQ(CAN_IRQn);
while(1)
{//receiving is done via interrupt
//CAN_SendMsg(LPC_CAN1, &TXMsg);
CAN_SendMsg(LPC_CAN2, &TXMsg);
}

return 1;
}

#if 0
/* With ARM and GHS toolsets, the entry point is main() - this will
allow the linker to generate wrapper code to setup stacks, allocate
heap area, and initialize and copy code and data segments. For GNU
toolsets, the entry point is through __start() in the crt0_gnu.asm
file, and that startup code will setup stacks and data */
int main(void) {
return c_entry();
}
#endif

#ifdef  DEBUG
/*******************************************************************************
* @briefReports the name of the source file and the source line number
* where the CHECK_PARAM error has occurred.
* @param[in]file Pointer to the source file name
* @param[in]    line assert_param error line source number
* @returnNone
*******************************************************************************/
void check_failed(uint8_t *file, uint32_t line) {
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

/* Infinite loop */
while (1)
;
}
#endif

Oscilloscope Capture is:
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by miczie on Wed Jul 11 05:30:33 MST 2012
Hello,

I'm using an LPCXpresso with LPC 1769 with CAN controllers. I have written a driver basing on the previous posts. Local and Global self test passed positively. The reception is done with use of interrupts. I have also an experimental CAN network with TWO PLC's. They are sending messages to each other and the reception by my controller works fine. However, when I want to send a message to the PLC it is either bit error or the ACK slot error. I suppose that the bitrate is fine since the messages are received properly. Has anyone met such issue?
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon May 21 09:12:22 MST 2012

Quote: mcabral
Anyone know of any library to manage the sending of messages longer than 8 bytes?



No, even 'segmented transfer' is using 8 byte messages to transmit 7 data bytes :eek:

See: http://atlas.web.cern.ch/Atlas/GROUPS/DAQTRIG/DCS/LMB/PROFILE/cano-sdo.htm
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mcabral on Mon May 21 07:19:38 MST 2012
Hi!

  Anyone know of any library to manage the sending of messages longer than 8 bytes? I would be very useful in my current project. thanks!
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Feb 10 08:52:29 MST 2012

Quote: fjarnjak
That one is needed to route signals on Xpresso base board to the outside connector.



Of course this code is using my own Z1769-V3 BaseBoard with 3.3V TI transceivers :)

Unfortunately EA didn't follow my layout :rolleyes:
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjarnjak on Fri Feb 10 05:54:20 MST 2012

Quote: Zero


#1 Samples are working with described changes

#2 I've posted a test project already in #14 of http://knowledgebase.nxp.com/showthread.php?t=2592



[U][B]EDITED:[/B][/U]

Thanx for the code. I have tried it - and it works on CAN1. I have put a 1K resistor between TD1 and RD1 and I get correct signals - logic analyzer has protocol analyzer and CAN messages are correct

I checked with TD2 and RD2 on the pins - and it works well.

Except that now I have finally a code / driver that works [U]([B]many thanks[/B][/U]).

Then on the base board it did not work - so I looked in great detail and I just realized that CAN2 has 2 possible output pins. One is on P2.7 and P2.8  but another one is P0.4 and P0.5 if PINSEL for those is set to function = 2. That one is needed to route signals on Xpresso base board to the outside connector.

So I have used your code (also pasted below) and configured CAN2 pins correctly and now it works.


Now I can send & receive Thanx!

Code is here:

/** CAN variable definition **/
CAN_MSG_Type TXMsg, RXMsg; // messages for test Bypass mode
CAN_MSG_Type TX2Msg, RX2Msg;
uint32_t CANRxCount, CANTxCount = 0;
uint32_t CAN2RxCount, CAN2TxCount = 0;

/************************** PRIVATE FUNCTIONS *************************/

void CAN_IRQHandler()
{
 uint8_t CAN1IntStatus;
 uint8_t CAN2IntStatus;
 CAN1IntStatus = CAN_IntGetStatus(LPC_CAN1);
 CAN2IntStatus = CAN_IntGetStatus(LPC_CAN2);
//check receive interrupt
 if(CAN1IntStatus &0x01)
 {
  LED_TOG;
  CAN_ReceiveMsg(LPC_CAN1,&RXMsg);
  CANRxCount++; //count success received message
  TXMsg.id  = RXMsg.id + 0x100;
  TXMsg.RDA = CANRxCount;
  TXMsg.RDB = CANTxCount;
  CAN_SendMsg(LPC_CAN1, &TXMsg);
  CANTxCount++;
 }

 if(CAN2IntStatus &0x01)
 {
      CAN_ReceiveMsg(LPC_CAN2,&RX2Msg);
      CAN2RxCount++; //count success received message
      TX2Msg.id  = RX2Msg.id + 0x100;
      TX2Msg.RDA = CAN2RxCount;
      TX2Msg.RDB = CAN2TxCount;
      CAN_SendMsg(LPC_CAN2, &TXMsg);
      CAN2TxCount++;
 }

}

/*********************************************************************//**
 * @brief       Initialize transmit and receive message for Bypass operation
 * @param[in]   none
 * @return      none
 **********************************************************************/
void CAN_InitMessage(void)
{
 TXMsg.format = STD_ID_FORMAT;
 TXMsg.id = 0x123;
 TXMsg.len = 8;
 TXMsg.type = DATA_FRAME;
 TXMsg.RDA = 0x00;
 TXMsg.RDB = 0x00;

  TX2Msg.format = STD_ID_FORMAT;
  TX2Msg.id = 0x126;
  TX2Msg.len = 8;
  TX2Msg.type = DATA_FRAME;
  TX2Msg.RDA = 0x00;
  TX2Msg.RDB = 0x00;

 RXMsg.format = STD_ID_FORMAT;
 RXMsg.id = 0x00;
 RXMsg.len = 0x00;
 RXMsg.type = 0x00;
 RXMsg.dataA[0] = RXMsg.dataA[1] = RXMsg.dataA[2] = RXMsg.dataA[3] = 0x00000000;
 RXMsg.dataB[0] = RXMsg.dataB[1] = RXMsg.dataB[2] = RXMsg.dataB[3] = 0x00000000;
}

/////////////////////////////////////////
// Main
int main(void)
{
 PINSEL_CFG_Type PinCfg;
/* Pin configuration
 * CAN1: select 0.0 as RD1. P0.1 as TD1
 */
 PinCfg.Funcnum = 1;
 PinCfg.OpenDrain = 0;
 PinCfg.Pinmode = 0;
 PinCfg.Pinnum = 0;
 PinCfg.Portnum = 0;
 PINSEL_ConfigPin(&PinCfg);
 PinCfg.Pinnum = 1;
 PINSEL_ConfigPin(&PinCfg);

 // CAN2 Pins P0.4 as RD2 and P0.85 as TD2
  PinCfg.Funcnum = 2;
  PinCfg.Pinnum = 4;
  PinCfg.Portnum = 0;
  PINSEL_ConfigPin(&PinCfg);
  PinCfg.Pinnum = 5;
  PINSEL_ConfigPin(&PinCfg);


//LED
 LPC_GPIO0->FIODIR |=LED;
//Initialize CAN1
 CAN_Init(LPC_CAN1, 125000);
 CAN_Init(LPC_CAN2, 125000);
//Enable Interrupt
 CAN_IRQCmd(LPC_CAN1, CANINT_RIE, ENABLE);
 CAN_IRQCmd(LPC_CAN2, CANINT_RIE, ENABLE);
//Enable CAN Interrupt
 NVIC_EnableIRQ(CAN_IRQn);
 CAN_SetAFMode(LPC_CANAF,CAN_AccBP);
 CAN_InitMessage();
 CAN_SendMsg(LPC_CAN1, &TXMsg);
 CAN_SendMsg(LPC_CAN2, &TXMsg);
 while (1)
 {
// receiving is done via interrupt
 }
 return 1;
}
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Fri Feb 10 04:27:51 MST 2012

Quote: fjarnjak
Can anyone that has a real working code for LPCXpresso board post it? Since samples do not work.

:confused:

#1 Samples are working with described changes :eek:

#2 I've posted a test project already :) in #14 of http://knowledgebase.nxp.com/showthread.php?t=2592
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjarnjak on Fri Feb 10 04:07:20 MST 2012

Quote: Ajay
Has anyone been able to successfully get CAN to work on the LPCXpresso 1769?



I haven't.....I have tried every single sample code being downloadable from NXP, or that Keil demo, etc - they all fail.

I have even tried to connect RD2 and TD2 pins with a 1k resistor as one poster suggested and I get no activity on the logic analyzer while sending in self-test mode. Also while in self-test mode, it does send 1 message but it never executes the IRQ handler to process receiving message - like it never receives messages at all.

I have tried all possible permutation with all available sample codes and the result is the same.

I have tried toggling the pins in GPIO mode where RD1, TD1, RD2 and TD2 are and it works OK. So nothing is fried.

All the above I have tried with LPCXpresso LPC1769 board mounted in Baseboard and without being mounted in baseboard (while in baseboard I am using real transreceiver and not 1k resistor of course). Connections while in base board are OK - tested them all.

Basically what I want to accomplish is purely to be able to send a CAN message on CAN2 port and get it on the other end on a PC with IXXAT CAN adapter and likewise send some CAN message and get it on LPC side on CAN2 port.

Sounds simple......guess not.

Can anyone that has a real working code for LPCXpresso board post it? Since samples do not work.
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by fjarnjak on Thu Feb 09 08:27:12 MST 2012
I have tried CAN example included with CMSIS v2 for LPCXpresso (LPC1769) and it doesn't work - it always loops in the while loop waiting for GSR to become 0. And it never does.

I have modified example to use CAN2 only because I am using LPCXpresso base board which routes CAN2 to the CAN transreceiver.

while ( !(LPC_CAN2->GSR & (1 << 3)) );
          if ( CAN_SendMessage( &MsgBuf_TX ) == FALSE )
            {
                // nothing
            }


I have checked my LPXpresso base board setup (jumpers 12 and 13) and I can verify I correctly route signals from 1769 board to jumpers and from jumpers to the transreceiver.

I have also tried this LED Control for CAN example and it also doesn't work. Actually, in while loop I am just sending messages - not waiting for user to press something, so it should work - it doesn't.

I have even removed the LPC board from the base board and connected logic analyzer on RD and TD pins for CAN - no signal whatsoever while code is running. I tried with CAN1 and CAN2 - nothing. However, to verify I toggle some other IO pin and it works fine - so code is not dead or stuck in some loop.

Any ideas? How did you make it work?

Thanks.
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by OXO on Sat Aug 06 00:58:03 MST 2011

Quote: Ajay
Hello James & OXO,

It has some time since I tried the CAN driver code. Are you referencing "lpc17_CAN__LedControl" in this thread? What is the "can_test_AFLUT" example?

Thanks!



It is one of the examples in the lpc17xx.cmsis.driver.library
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by jharwood on Fri Aug 05 15:25:35 MST 2011

Quote: Ajay
Are you referencing "lpc17_CAN__LedControl" in this thread?


Yes, that is the project that it is taken from.


Quote:

What is the "can_test_AFLUT" example?


I'm not sure where that example is from :confused:
0 Kudos
Reply

4,426 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ajay on Fri Aug 05 10:47:37 MST 2011
Hello James & OXO,

It has some time since I tried the CAN driver code. Are you referencing "lpc17_CAN__LedControl" in this thread? What is the "can_test_AFLUT" example?

Thanks!
0 Kudos
Reply