LPC1769 CAN DRIVER INTERRUPT NOT HAPPENIG

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

LPC1769 CAN DRIVER INTERRUPT NOT HAPPENIG

916 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by 00zigor on Thu Sep 11 14:18:53 MST 2014
Hi, everyone.

I've just started working on LPC1769 on an custom board and i'm having problems getting the CAN BUS to work using the drivers and software examples provided here.

After some research here i've read that the drivers has a lot of bugs, and the links i've found pointing to new drivers always redirect to home in LPCware.com.

So, I can't find new drivers or examples more up to date.

I'm using a simple MCP2551 transceiver to recieve a messagem from another device transmitting every 10ms.

I already used a similar driver on LPC1788 and it worked fine.

Using a osciloscope i made sure that the signal is reaching the transceiver and is wired to the correct pins on the 1769.

I'm trying to enable CAN RX interruption but when the data comes the interruption doesn't happen.

Here's the exmple code before anyone asks:

/*********************************************************************//**
 * @briefCAN_IRQ Handler, control receive message operation
 * param[in]none
 * @return none
 **********************************************************************/
void CAN_IRQHandler()
{
uint8_t IntStatus;

IntStatus = CAN_IntGetStatus(LPC_CAN1);

//check receive interrupt
if((IntStatus >> 0) & 0x01)
{
TOGGLE_RX_LED;

}
}

int main(void) {

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

  //Initialize CAN1
    CAN_Init(LPC_CAN1, 125000);

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

  //Enable CAN Interrupt
    NVIC_EnableIRQ(CAN_IRQn);

  // Force the counter to be placed into memory
    volatile static int i = 0 ;

  // Enter an infinite loop, just incrementing a counter
    while(1) {
        i++ ;
    }
    return 0 ;
Labels (1)
0 Kudos
13 Replies

744 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by 00zigor on Fri Sep 26 13:48:36 MST 2014
Hey LabRat,

Sorry for the delayed answer.

Finaly got my code working on both CMSIS and LPCOpen.

So, on question 1:

Quote:
Why is your timer flag not volatile?



It didn't need to be anything else at that moment, that flag was just so I wouldn't call another function in timer0 interruption, memory alocation was not a concern at the moment and a global variable as the fastest choice.

Question 2:

Quote:
Why are you using different setting for receive and transmit message?



I was just testing how to receive a message from another device using the exemples that i had, that part was not really necessary now that I think of it.

Question 3:

Quote:
Why are you using a timer match instead a simple Systick timer?



Because this way I can know whether my harware stoped working or not.
I have a LED at MAT0.0 pin blinking whitout software interference.

Question 4:

Quote:
Why do you init your messages every time before sending a new message?


I was just desperate...  :bigsmile:

Anyway, turns out I had a major cold soldering at my board witch was causing bus error in many registers including ICR whitch made me think that i was receiving a message whitout the correct data, once i undertood that things really started to improve.

Now I'm moving on to the next stage with this project.
CMSIS is working fine and LPCOpen worked wonderfully.
Thank you so much.
0 Kudos

744 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Fri Sep 19 13:02:32 MST 2014

Quote: 00zigor
Here's my code up until now...



I'm not sure what your library from 2011 is doing in detail, but a few things in your code are confusing me 

Why is your timer flag not volatile?
//Transmission flag updated in timer0 interrupt
uint8_t flag_tx = FALSE;



Why are you using different setting for receive and transmit message?
void CAN_InitMessage(void)
{
TXMsg.format = [color=#f00]EXT_ID_FORMAT;[/color]
...
RXMsg.format =[color=#f00] 0x00;[/color]
...
}

Why are you using a timer match instead a simple Systick timer?


Why do you init your messages every time before sending a new message?
if(flag_tx)
{
 flag_tx = FALSE;
 [color=#f00]CAN_InitMessage();[/color]
 CAN_SendMsg(LPC_CAN1, &TXMsg);
}


Sample:
/*
===============================================================================
 Name        : LPC17_CAN_Test.c
 Author      : $(author)
 Version     :
 Copyright   : $(copyright)
 Description : main definition
===============================================================================
*/

#include "LPC17xx.h"
#include "lpc17xx_timer.h"
#include "lpc17xx_libcfg_default.h"
#include "lpc17xx_pinsel.h"
#include "lpc17xx_gpio.h"
#include "lpc17xx_can.h"
#include <string.h>

/** PINSEL configuration definition for CAN**/
PINSEL_CFG_Type CAN_PinCfg; //Parameters for pin configuration.

/** PINSEL configuration definition for GPIO**/
PINSEL_CFG_Type GPIO_PinCfg; //Parameters for pin configuration.

/** CAN variable definition **/
CAN_MSG_Type TXMsg, RXMsg; // messages for test Bypass mode
CAN_MSG_Type RspMsg;    // Respond message

//CAN messages initialization.
void CAN_InitMessage(void);
//CAN interruption Handler.
void CAN_IRQHandler(void);
//CAN initialization.
void INIT_CAN(void);

volatile uint32_t timer;//systick timer
volatile uint8_t flag_tx = FALSE;//transmit flag

/*********************************************************************//**
 * @briefCAN_IRQ Handler, control receive message operation
 * param[in]none
 * @return none
 **********************************************************************/
void CAN_IRQHandler(void)
{
 uint8_t IntStatus;
 IntStatus = CAN_IntGetStatus(LPC_CAN1);

//check receive interrupt
 if((IntStatus >> 0) & 0x01)
 {
  CAN_ReceiveMsg(LPC_CAN1,&RXMsg);
  memcpy(&RspMsg,&RXMsg,sizeof(CAN_MSG_Type)); //copy respond message
  RspMsg.id += 0x100;//Respond ID = receive + 0x100
  CAN_SendMsg(LPC_CAN1, &RspMsg);//and send it...
 }
}

//SysTick_Handler
void SysTick_Handler(void)
{
 timer++;
 if(timer >= 100)//reached tx delay
 {
  timer =0;//reset timer
  flag_tx = TRUE;//set transmit flag
 }//end reached tx delay
}

void INIT_CAN(void)
{
 /* Pin configuration
  * CAN1: select P0.0 as RD1. P0.1 as TD1 */
 CAN_PinCfg.Funcnum = 1;
 CAN_PinCfg.OpenDrain = 0;
 CAN_PinCfg.Pinmode = 0;
 CAN_PinCfg.Portnum = 0;
 CAN_PinCfg.Pinnum = 0;
 PINSEL_ConfigPin(&CAN_PinCfg);
 CAN_PinCfg.Pinnum = 1;
 PINSEL_ConfigPin(&CAN_PinCfg);
//Initialize CAN1
 CAN_Init(LPC_CAN1, 125000);
//Configures CAN AF mode
 CAN_SetAFMode(LPC_CANAF,CAN_AccBP);
//Configures CAN mode.
 CAN_ModeConfig(LPC_CAN1, CAN_OPERATING_MODE, ENABLE);
//Enable Interrupt
 CAN_IRQCmd(LPC_CAN1, CANINT_RIE, ENABLE);
//Enable CAN Interrupt
 NVIC_EnableIRQ(CAN_IRQn);
//Intialize CAN TX and RX messages.
 CAN_InitMessage();
}

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

 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 Function//
int main(void)
{
 INIT_CAN();
 SysTick_Config(SystemCoreClock / 1000); //1ms timer
 while(1)//loop
 {
  if(flag_tx)
  {
   flag_tx = FALSE;
   TXMsg.dataA[1]++;//change message
   CAN_SendMsg(LPC_CAN1, &TXMsg);
  }
 }
 return 0 ;
}
0 Kudos

744 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Wed Sep 17 14:41:46 MST 2014

Quote: 00zigor
...but I can't find where it configures IOCON for the CAN Pins and there's nothing even related to that anywhere in the code, i tried to find some clue on other exemples but got nothing.



:quest:


Quote: LabRat

This sample looks confusing, but after throwing out AF stuff and DEBUG messages it it a simple sample.

Perhaps you want to test it, too. Should work out of the box if you [color=#f00]change CAN_CTRL_NO and add the correct PIN setup in board_sysinit.c of board library..[/color].



You are not telling me that a simple pin setup got you 

Of course you can also setup pins in CAN_init.

Sample:

//init CAN, [color=#f00]Pin muxing is done in board_sysinit.c already !!![/color]
void CAN_init(void)
{
[color=#f00]//if no PIN setup is done, it's time now...
// Chip_IOCON_PinMux(LPC_IOCON,0,0,IOCON_MODE_INACT,IOCON_FUNC1);// P0.0 CAN-RD1
// Chip_IOCON_PinMux(LPC_IOCON,0,1,IOCON_MODE_INACT,IOCON_FUNC1);// P0.1 CAN-TD1[/color]
 Chip_CAN_Init(LPC_CAN, LPC_CANAF, LPC_CANAF_RAM);
 Chip_CAN_SetBitRate(LPC_CAN, 100000);
 Chip_CAN_EnableInt(LPC_CAN, CAN_IER_BITMASK);
 Chip_CAN_SetAFMode(LPC_CANAF, CAN_AF_BYBASS_MODE);
 NVIC_EnableIRQ(CAN_IRQn);
}
0 Kudos

744 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by 00zigor on Wed Sep 17 13:05:33 MST 2014
OK, so... I tried to use LPC open and... it got me even more confused than I already am.  :quest:

The code has no comments at the functions declarations, using the exemples it's no use, so if you're like me, and just started working on 1769 you'll get nowhere.

In the can_peripheral exemple the driver configures the AFLUT  and I think I managed to set bypass mode, but I can't find where it configures IOCON for the CAN Pins and there's nothing even related to that anywhere in the code, i tried to find some clue on other exemples but got nothing.

Whoever wrote those drivers never thougth that someone would try to learn how the hardware works using them.

Besides ,to change to another development platform now would take some time, and i'm kinda out of it now.

I'm still trying to understand what went wrong whit my CMSIS driver for CAN, since it worked for about an hour before it just crashed and never worked again.

I'm using LPCXpresso 7.2.0, CMSIS2.0 and the driver and expemles provided Here for CAN bypass mode.

I'm on an custom borad using LPC1769 and using as debugger a NXP LPC-Link.

Right now i'm trying to watch every single register while reading the UM10360 so maybe I can figure out what is wrong, but if someone laready been trough someting like that, Please help me out.

Here's my code up until now:


#ifdef __USE_CMSIS
#include "LPC17xx.h"
#endif

#include <cr_section_macros.h>

#include "lpc17xx_timer.h"
#include "lpc17xx_libcfg_default.h"
#include "lpc17xx_pinsel.h"
#include "lpc17xx_gpio.h"
#include "lpc17xx_can.h"

/** PINSEL configuration definition for CAN**/
PINSEL_CFG_Type CAN_PinCfg; //Parameters for pin configuration.

/** PINSEL configuration definition for GPIO**/
PINSEL_CFG_Type GPIO_PinCfg; //Parameters for pin configuration.

/** CAN variable definition **/
CAN_MSG_Type TXMsg, RXMsg; // messages for test Bypass mode

//CAN messages initialization.
void CAN_InitMessage(void);

//CAN interruption Handler.
void CAN_IRQHandler(void);

//Timer 0 initialization.
void INIT_Timer_0(void);

//CAN initialization.
void INIT_CAN(void);

//Transmission flag updated in timer0 interrupt
uint8_t flag_tx = FALSE;

/*----------------- INTERRUPT SERVICE ROUTINES --------------------------*/
/*********************************************************************//**
 * @briefTIMER0 interrupt handler sub-routine
 * @param[in]None
 * @return None
 **********************************************************************/
void TIMER0_IRQHandler(void)
{
if (TIM_GetIntStatus(LPC_TIM0, TIM_MR0_INT)== SET)
{
flag_tx = TRUE;
}
TIM_ClearIntPending(LPC_TIM0, TIM_MR0_INT);
}

/*********************************************************************//**
 * @briefCAN_IRQ Handler, control receive message operation
 * param[in]none
 * @return none
 **********************************************************************/
void CAN_IRQHandler(void)
{
uint8_t IntStatus;
IntStatus = CAN_IntGetStatus(LPC_CAN1);

//check receive interrupt
if((IntStatus >> 0) & 0x01)
{
CAN_ReceiveMsg(LPC_CAN1,&RXMsg);

}
}

//Inicialização de Timer 0.
void INIT_Timer_0(void)
{
//timer init
TIM_TIMERCFG_Type TIM_ConfigStruct;
TIM_MATCHCFG_Type TIM_MatchConfigStruct ;

//PINSEL_CFG_Type PinCfg;
// Conifg P1.28 as MAT0.0
GPIO_PinCfg.Funcnum = 2;
GPIO_PinCfg.OpenDrain = 0;
GPIO_PinCfg.Pinmode = 0;
GPIO_PinCfg.Portnum = 3;
GPIO_PinCfg.Pinnum = 25;
PINSEL_ConfigPin(&GPIO_PinCfg);

// Initialize timer 0, prescale count time of 100uS
TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
TIM_ConfigStruct.PrescaleValue= 100;

// use channel 0, MR0
TIM_MatchConfigStruct.MatchChannel = 0;
// Enable interrupt when MR0 matches the value in TC register
TIM_MatchConfigStruct.IntOnMatch   = TRUE;
//Enable reset on MR0: TIMER will reset if MR0 matches it
TIM_MatchConfigStruct.ResetOnMatch = TRUE;
//Stop on MR0 if MR0 matches it
TIM_MatchConfigStruct.StopOnMatch  = FALSE;
//Toggle MR0.0 pin if MR0 matches it
TIM_MatchConfigStruct.ExtMatchOutputType =TIM_EXTMATCH_TOGGLE;
// Set Match value, count value of 1000 (10000 * 100uS = 1000000uS = 1S --> 1 Hz)
TIM_MatchConfigStruct.MatchValue   = 10000;

// Set configuration for Tim_config and Tim_MatchConfig
TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct);
TIM_ConfigMatch(LPC_TIM0,&TIM_MatchConfigStruct);

/* preemption = 1, sub-priority = 1 */
NVIC_SetPriority(TIMER0_IRQn, ((0x01<<3)|0x01));
/* Enable interrupt for timer 0 */
NVIC_EnableIRQ(TIMER0_IRQn);
// To start timer 0
TIM_Cmd(LPC_TIM0,ENABLE);

}

void INIT_CAN(void)
{
/* Pin configuration
 * CAN1: select P0.21 as RD1. P0.22 as TD1 */
CAN_PinCfg.Funcnum = 3;
CAN_PinCfg.OpenDrain = 0;
CAN_PinCfg.Pinmode = 0;
CAN_PinCfg.Portnum = 0;
CAN_PinCfg.Pinnum = 21;
PINSEL_ConfigPin(&CAN_PinCfg);
CAN_PinCfg.Pinnum = 22;
PINSEL_ConfigPin(&CAN_PinCfg);

//Initialize CAN1
CAN_Init(LPC_CAN1, 125000);

        //Configures CAN AF mode
CAN_SetAFMode(LPC_CANAF,CAN_AccBP);

        //Configures CAN mode.
CAN_ModeConfig(LPC_CAN1, CAN_SELFTEST_MODE, ENABLE);

//Enable Interrupt
CAN_IRQCmd(LPC_CAN1, CANINT_RIE, ENABLE);

//Enable CAN Interrupt
NVIC_EnableIRQ(CAN_IRQn);

//Intialize CAN TX and RX messages.
CAN_InitMessage();
}

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

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//
int main(void) {

    // TODO: insert code here
INIT_Timer_0();
INIT_CAN();

    // Enter an infinite loop, sending a can message every timer 0 interruption (1 second).
    while(1) {

    if(flag_tx)
    {
    flag_tx = FALSE;
    CAN_InitMessage();
    CAN_SendMsg(LPC_CAN1, &TXMsg);
    }
    }
    return 0 ;
}
0 Kudos

744 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by 00zigor on Fri Sep 12 13:26:44 MST 2014
Will do.

Specialy because this little bugger just stoped working.
Maybe things will get a little easier using LPCOpen.

Tanks again.
0 Kudos

744 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Fri Sep 12 07:39:26 MST 2014

Quote: 00zigor
You have no idea of how ashamed I feel right now.



I know that feeling..., good to hear that your board is working  :bigsmile:

Let me just add a note:

Your code looks like a very old CMSIS sample. LPCOpen is also including a CAN sample  :)

This sample looks confusing, but after throwing out AF stuff and DEBUG messages it it a simple sample.

Perhaps you want to test it, too. Should work out of the box if you change CAN_CTRL_NO and add the correct PIN setup in board_sysinit.c of board library...

0 Kudos

744 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by 00zigor on Fri Sep 12 07:23:44 MST 2014
Dear LabRat,

You have no idea of how ashamed I feel right now.   :bigsmile: (That's me hiding the shame behind a smile)

As soon as I corrected this error my interruptions started working and i'm receiving the data correctely as well as transmitting them.
Tank you very much kind sir, and I'm sorry for my lack of attention.
I blame my dislexy actualy.

PS.: For a Rat you're a pretty nicce guy.  8-)
0 Kudos

744 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Thu Sep 11 21:36:39 MST 2014
PinCfg.Pinnum = 0;
PinCfg.Portnum = 21;
PINSEL_ConfigPin(&PinCfg);
PinCfg.Pinnum = 22;
PINSEL_ConfigPin(&PinCfg);


|(

P21[0] and P21[22]   :quest:  You have a lot of Ports in your 1769...
0 Kudos

744 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Thu Sep 11 16:45:25 MST 2014
I'm not sure which toolchain and library you are using...

Is it LPCXpresso and CMSIS2.0? Is there a sample from where you've started?

Does your oscillosope show any activity at TD1?
0 Kudos

744 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by 00zigor on Thu Sep 11 16:08:08 MST 2014
I enabled Timer 0 whit 500ms to transmit a frame and put CAN_sendmsg() inside timer 0 interruption but when I tried to debug the transmitting function the compiler returned the message: No source available for "CAN_SendMsg() at 0x434"
So I tried putting a flag inside interruption handler and pooling the flag in the main loop but the debugger just jumps out of the "if" and dosen't even update the function flag

the code with transmition in interrupt handler is bellow:


void CAN_IRQHandler()
{
uint8_t IntStatus;
IntStatus = CAN_IntGetStatus(LPC_CAN1);

//check receive interrupt
if((IntStatus >> 0) & 0x01)
{
CAN_ReceiveMsg(LPC_CAN1,&RXMsg);

}
}

//CAN 1 Initialization.
void INIT_CAN(void)
{
/* Pin configuration
 * CAN1: select P0.21 as RD1. P0.22 as TD1 */
PinCfg.Funcnum = 3;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
PinCfg.Pinnum = 0;
PinCfg.Portnum = 21;
PINSEL_ConfigPin(&PinCfg);
PinCfg.Pinnum = 22;
PINSEL_ConfigPin(&PinCfg);

//Initialize CAN1
CAN_Init(LPC_CAN1, 125000);

//Configures CAN operation mode.
CAN_ModeConfig(LPC_CAN1, CAN_SELFTEST_MODE, ENABLE);

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

//Enable CAN Interrupt
NVIC_EnableIRQ(CAN_IRQn);

CAN_InitMessage();
}

//Timer 0 Initialization.
void INIT_Timer_0(void)
{
//timer init
TIM_TIMERCFG_Type TIM_ConfigStruct;
TIM_MATCHCFG_Type TIM_MatchConfigStruct ;

//PINSEL_CFG_Type PinCfg;
// Conifg P1.28 as MAT0.0
PinCfg.Funcnum = 2;
PinCfg.OpenDrain = 0;
PinCfg.Pinmode = 0;
PinCfg.Portnum = 3;
PinCfg.Pinnum = 25;
PINSEL_ConfigPin(&PinCfg);

// Initialize timer 0, prescale count time of 100uS
TIM_ConfigStruct.PrescaleOption = TIM_PRESCALE_USVAL;
TIM_ConfigStruct.PrescaleValue= 100;

// use channel 0, MR0
TIM_MatchConfigStruct.MatchChannel = 0;
// Enable interrupt when MR0 matches the value in TC register
TIM_MatchConfigStruct.IntOnMatch   = TRUE;
//Enable reset on MR0: TIMER will reset if MR0 matches it
TIM_MatchConfigStruct.ResetOnMatch = TRUE;
//Stop on MR0 if MR0 matches it
TIM_MatchConfigStruct.StopOnMatch  = FALSE;
//Toggle MR0.0 pin if MR0 matches it
TIM_MatchConfigStruct.ExtMatchOutputType =TIM_EXTMATCH_TOGGLE;
// Set Match value, count value of 1000 (5000 * 100uS = 500000uS = 0,5S --> 2 Hz)
TIM_MatchConfigStruct.MatchValue   = 5000;

// Set configuration for Tim_config and Tim_MatchConfig
TIM_Init(LPC_TIM0, TIM_TIMER_MODE,&TIM_ConfigStruct);
TIM_ConfigMatch(LPC_TIM0,&TIM_MatchConfigStruct);

/* preemption = 1, sub-priority = 1 */
NVIC_SetPriority(TIMER0_IRQn, ((0x01<<3)|0x01));
/* Enable interrupt for timer 0 */
NVIC_EnableIRQ(TIMER0_IRQn);
// To start timer 0
TIM_Cmd(LPC_TIM0,ENABLE);

}

void CAN_InitMessage(void)
{
TXMsg.format = EXT_ID_FORMAT;
TXMsg.id = 0x208;
TXMsg.len = 8;
TXMsg.type = DATA_FRAME;
TXMsg.dataA[0] = TXMsg.dataA[1] = TXMsg.dataA[2] = TXMsg.dataA[3] = 0x00000000;
TXMsg.dataB[0] = TXMsg.dataB[1] = TXMsg.dataB[2] = TXMsg.dataB[3] = 0x00000000;

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;
}

int main(void) {

INIT_Timer_0();
INIT_CAN();

    // Force the counter to be placed into memory
    volatile static int i = 0 ;
    // Enter an infinite loop, just incrementing a counter
    while(1) {
        i++ ;
    }
    return 0 ;
}
0 Kudos

744 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Thu Sep 11 15:30:06 MST 2014
Try to transmit messages before you try to receive messages  :)

If you are not able to transmit, you should try to use 'Local Self Test' and scope TXD1...
0 Kudos

744 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by 00zigor on Thu Sep 11 15:07:37 MST 2014
You're right, it's function 3, didn't notice that function 2 is reserved.
Changed that in the code but still nothing...  :((

And a can't transmit anything...
0 Kudos

744 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LabRat on Thu Sep 11 14:45:19 MST 2014

Quote: 00zigor
I'm trying to enable CAN RX interruption but when the data comes the interruption doesn't happen.



Isn't RD1/TD1 Function 3?

Are you able to transmit messages?
0 Kudos