Problems with can on_chip drivers for lpc11c24

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

Problems with can on_chip drivers for lpc11c24

4,518 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mcabral on Tue Sep 27 12:48:39 MST 2011
hello,
I'm beginning to test drivers lpc11c24 API (can on_chip) and my problem is that there are no interrupts in transmission and reception.
I have a scope on the port can and this information is being transmitted.
CAN interrupt is enabled and the callback functions are initialized,
but for some reason, when you call can_transmit () or can_receive (), there is no interruption is executed and performs the callback functions
Can anyone help me with this?
thanks!
0 Kudos
Reply
22 Replies

4,014 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Oct 05 06:52:11 MST 2011
I'm dying to know... :)
0 Kudos
Reply

4,014 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mcabral on Wed Oct 05 06:41:52 MST 2011

Quote: Zero
Made a few minor changes, but this code is working without problems.

TX is transmitting, RX is receiving :eek::eek:

Congratulation, you have a hardware problem

So check your boards and your CAN bus

/****************************************************************************
 *   $Id:: main.c 5034 2010-09-24 23:48:37Z nxp12832                        $
 *   Project: NXP LPC11xx CAN example
 *
 *   Description:
 *     This file is part of the CAN and CANopen on-chip driver examples.
 *
 ****************************************************************************
 * Software that is described herein is for illustrative purposes only
 * which provides customers with programming information regarding the
 * products. This software is supplied "AS IS" without any warranties.
 * NXP Semiconductors assumes no responsibility or liability for the
 * use of the software, conveys no license or title under any patent,
 * copyright, or mask work right to the product. NXP Semiconductors
 * reserves the right to make changes in the software without
 * notification. NXP Semiconductors also make no representation or
 * warranty that such application will be suitable for the specified
 * use without further testing or modification.
****************************************************************************/

#include <cr_section_macros.h>
#include "driver_config.h"
#include "target_config.h"
#include "small_gpio.h"
#include "gpio.h"
#include "rom_drivers.h"

#ifndef NULL
#define NULL    ((void *)0)
#endif

__BSS(RESERVED) char CAN_driver_memory[256]; // reserva 256 bytes for CAN driver

ROM **rom = (ROM **)0x1fff1ff8;

CAN_MSG_OBJ msg_obj;
uint32_t cuenta;
uint32_t cuenta_Rx;
uint32_t cuenta_Tx;

/* Initialize CAN Controller */
uint32_t ClkInitTable[2] = {
  0x00000000UL, // CANCLKDIV
  0x00001C57UL  // CAN_BTR
};

/* Callback function prototypes */
void CAN_rx(uint8_t msg_obj_num);
void CAN_tx(uint8_t msg_obj_num);
void CAN_error(uint32_t error_info);

/* Publish CAN Callback Functions */
CAN_CALLBACKS callbacks = {
   CAN_rx,
   CAN_tx,
   CAN_error,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
};

/*    CAN receive callback */
/*    Function is executed by the Callback handler after
    a CAN message has been received */
void CAN_rx(uint8_t msg_obj_num){
    // rx_counter++;
      /* Determine which CAN message has been received */
      msg_obj.msgobj = msg_obj_num;

      /* Now load up the msg_obj structure with the CAN message */
      (*rom)->pCAND->can_receive(&msg_obj);

//      if (msg_obj_num == 1)
//      {
//        /* Simply transmit CAN frame (echo) with with ID +0x100 via buffer 2 */
//        msg_obj.msgobj = 2;
//        msg_obj.mode_id += 0x100;
//        (*rom)->pCAND->can_transmit(&msg_obj);
//      }

    ToggleGPIOBit(LED_PORT, LEDV_BIT);
    cuenta_Rx++;

  return;
}

/*    CAN transmit callback */
/*    Function is executed by the Callback handler after
    a CAN message has been transmitted */
void CAN_tx(uint8_t msg_obj_num){
    cuenta_Tx++;
    return;
}

/*    CAN error callback */
/*    Function is executed by the Callback handler after
    an error has occured on the CAN bus */
void CAN_error(uint32_t error_info){
    ToggleGPIOBit(LED_PORT, LEDV_BIT);
  return;
}

/*    CAN interrupt handler */
/*    The CAN interrupt handler must be provided by the user application.
    It's function is to call the isr() API located in the ROM */
void CAN_IRQHandler (void){
  (*rom)->pCAND->isr();
}

int main(void) {

    InitGPIO();

    /* Initialize the CAN controller */
    (*rom)->pCAND->init_can(&ClkInitTable[0], 1);

    /* Configure the CAN callback functions */
    (*rom)->pCAND->config_calb(&callbacks);


    SetGPIOOut(LED_PORT, LEDV_BIT);
    SetGPIOOut(LED_PORT, LEDR_BIT);
    SetGPIOOut(PORT_0, PIO0_3);
    GPIOSetValue( PORT_0, PIO0_3, 0 ); // Habilitación del transceiver CAN vía STB (en bajo --> Activo)

    //set silent mode
//    LPC_CAN->CNTL |= (1<<7);
//    LPC_CAN->TEST |= (1<<3);

//    //set loopback mode
//    LPC_CAN->CNTL |= (1<<7);
//    LPC_CAN->TEST |= (1<<4);

//    //operación normal
//    LPC_CAN->CNTL &= ~(1<<7);
//    LPC_CAN->TEST &= ~((0x1<<2)|(0x1<<3)|(0x1<<4));

    /* Enable the CAN Interrupt */
    NVIC_EnableIRQ(CAN_IRQn);


    /* Configure message object 1 to receive all 11-bit messages 0x200-0x4FF */
    msg_obj.msgobj = 0;
    msg_obj.mode_id = 0x7FF; //| CAN_MSGOBJ_STD;
    msg_obj.mask = 0x000;
    (*rom)->pCAND->config_rxmsgobj(&msg_obj);


    while(1){

        if (cuenta == 1000000){

            ToggleGPIOBit(LED_PORT, LEDR_BIT);
            cuenta = 0;
        }
        cuenta++;
    }
}




ok!, thank you very much for your help! I'll review everything and I'll keep you informed of progress!
0 Kudos
Reply

4,014 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Oct 04 13:57:17 MST 2011
Made a few minor changes, but this code is working without problems.

TX is transmitting, RX is receiving :eek::eek:

Congratulation, you have a hardware problem

So check your boards and your CAN bus

/****************************************************************************
 *   $Id:: main.c 5034 2010-09-24 23:48:37Z nxp12832                        $
 *   Project: NXP LPC11xx CAN example
 *
 *   Description:
 *     This file is part of the CAN and CANopen on-chip driver examples.
 *
 ****************************************************************************
 * Software that is described herein is for illustrative purposes only
 * which provides customers with programming information regarding the
 * products. This software is supplied "AS IS" without any warranties.
 * NXP Semiconductors assumes no responsibility or liability for the
 * use of the software, conveys no license or title under any patent,
 * copyright, or mask work right to the product. NXP Semiconductors
 * reserves the right to make changes in the software without
 * notification. NXP Semiconductors also make no representation or
 * warranty that such application will be suitable for the specified
 * use without further testing or modification.
****************************************************************************/

#include <cr_section_macros.h>
#include "driver_config.h"
#include "target_config.h"
#include "small_gpio.h"
#include "gpio.h"
#include "rom_drivers.h"

#ifndef NULL
#define NULL    ((void *)0)
#endif

__BSS(RESERVED) char CAN_driver_memory[256]; // reserva 256 bytes for CAN driver

ROM **rom = (ROM **)0x1fff1ff8;

CAN_MSG_OBJ msg_obj;
uint32_t cuenta;
uint32_t cuenta_Rx;
uint32_t cuenta_Tx;

/* Initialize CAN Controller */
uint32_t ClkInitTable[2] = {
  0x00000000UL, // CANCLKDIV
  0x00001C57UL  // CAN_BTR
};

/* Callback function prototypes */
void CAN_rx(uint8_t msg_obj_num);
void CAN_tx(uint8_t msg_obj_num);
void CAN_error(uint32_t error_info);

/* Publish CAN Callback Functions */
CAN_CALLBACKS callbacks = {
   CAN_rx,
   CAN_tx,
   CAN_error,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
};

/*    CAN receive callback */
/*    Function is executed by the Callback handler after
    a CAN message has been received */
void CAN_rx(uint8_t msg_obj_num){
    // rx_counter++;
      /* Determine which CAN message has been received */
      msg_obj.msgobj = msg_obj_num;

      /* Now load up the msg_obj structure with the CAN message */
      (*rom)->pCAND->can_receive(&msg_obj);

//      if (msg_obj_num == 1)
//      {
//        /* Simply transmit CAN frame (echo) with with ID +0x100 via buffer 2 */
//        msg_obj.msgobj = 2;
//        msg_obj.mode_id += 0x100;
//        (*rom)->pCAND->can_transmit(&msg_obj);
//      }

    ToggleGPIOBit(LED_PORT, LEDV_BIT);
    cuenta_Rx++;

  return;
}

/*    CAN transmit callback */
/*    Function is executed by the Callback handler after
    a CAN message has been transmitted */
void CAN_tx(uint8_t msg_obj_num){
    cuenta_Tx++;
    return;
}

/*    CAN error callback */
/*    Function is executed by the Callback handler after
    an error has occured on the CAN bus */
void CAN_error(uint32_t error_info){
    ToggleGPIOBit(LED_PORT, LEDV_BIT);
  return;
}

/*    CAN interrupt handler */
/*    The CAN interrupt handler must be provided by the user application.
    It's function is to call the isr() API located in the ROM */
void CAN_IRQHandler (void){
  (*rom)->pCAND->isr();
}

int main(void) {

    InitGPIO();

    /* Initialize the CAN controller */
    (*rom)->pCAND->init_can(&ClkInitTable[0], 1);

    /* Configure the CAN callback functions */
    (*rom)->pCAND->config_calb(&callbacks);


    SetGPIOOut(LED_PORT, LEDV_BIT);
    SetGPIOOut(LED_PORT, LEDR_BIT);
    SetGPIOOut(PORT_0, PIO0_3);
    GPIOSetValue( PORT_0, PIO0_3, 0 ); // Habilitación del transceiver CAN vía STB (en bajo --> Activo)

    //set silent mode
//    LPC_CAN->CNTL |= (1<<7);
//    LPC_CAN->TEST |= (1<<3);

//    //set loopback mode
//    LPC_CAN->CNTL |= (1<<7);
//    LPC_CAN->TEST |= (1<<4);

//    //operación normal
//    LPC_CAN->CNTL &= ~(1<<7);
//    LPC_CAN->TEST &= ~((0x1<<2)|(0x1<<3)|(0x1<<4));

    /* Enable the CAN Interrupt */
    NVIC_EnableIRQ(CAN_IRQn);


    /* Configure message object 1 to receive all 11-bit messages 0x200-0x4FF */
    msg_obj.msgobj = 0;
    msg_obj.mode_id = 0x7FF; //| CAN_MSGOBJ_STD;
    msg_obj.mask = 0x000;
    (*rom)->pCAND->config_rxmsgobj(&msg_obj);


    while(1){

        if (cuenta == 1000000){

            ToggleGPIOBit(LED_PORT, LEDR_BIT);
            cuenta = 0;
        }
        cuenta++;
    }
}

0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mcabral on Tue Oct 04 13:17:52 MST 2011
ok, I sent a zip file but I doubt that there may be some error because as I mentioned is a very simple project. But is bringing me many problems.:(

Thanks!!
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Oct 04 12:55:48 MST 2011
Sorry, can't test your project if you don't post your project. If there's a wrong project setting I'm wasting a lot of time :mad:

And as long as I don't see a message on my scope I don't believe that's a valid message :eek: So there's a lot of guessing here and that's not solving problems :)
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mcabral on Tue Oct 04 12:40:53 MST 2011

Quote: Zero
Don't understand what you mean with voltages? Did you scope it? Can you see a message which is (periodically) transmitted? It's not necessary to decode this message, a scope can show you a correct baudrate.

Perhaps you should zip and post your (receiving) project, so software problems can be excluded



I measured the voltages on the bus to verify that a message is being transmitted periodically. There really is a message being transmitted and reaches the receiver via a can bus baudrate 125Kbit/sec. The receiver code is as follows:
#include <cr_section_macros.h>
#include "driver_config.h"
#include "target_config.h"
#include "small_gpio.h"
#include "gpio.h"
#include "rom_drivers.h"

#ifndef NULL
#define NULL    ((void *)0)
#endif

__BSS(RESERVED) char CAN_driver_memory[256]; // reserva 256 bytes for CAN driver

ROM **rom = (ROM **)0x1fff1ff8;

CAN_MSG_OBJ msg_obj;
uint32_t cuenta;
uint32_t cuenta_Rx;
uint32_t cuenta_Tx;

/* Initialize CAN Controller */
uint32_t ClkInitTable[2] = {
  0x00000000UL, // CANCLKDIV
  0x00001C57UL  // CAN_BTR
};

/* Callback function prototypes */
void CAN_rx(uint8_t msg_obj_num);
void CAN_tx(uint8_t msg_obj_num);
void CAN_error(uint32_t error_info);

/* Publish CAN Callback Functions */
CAN_CALLBACKS callbacks = {
   CAN_rx,
   CAN_tx,
   CAN_error,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
};

/*CAN receive callback */
void CAN_rx(uint8_t msg_obj_num){

ToggleGPIOBit(LED_PORT, LEDV_BIT);
cuenta_Rx++;

  return;
}

/*CAN transmit callback */
void CAN_tx(uint8_t msg_obj_num){

//ToggleGPIOBit(LED_PORT, LEDV_BIT);
cuenta_Tx++;
return;
}

/*CAN error callback */
void CAN_error(uint32_t error_info){

  return;
}

/*CAN interrupt handler */
void CAN_IRQHandler (void){
  (*rom)->pCAND->isr();
}

int main(void) {

InitGPIO();

/* Initialize the CAN controller */
(*rom)->pCAND->init_can(&ClkInitTable[0], 1);

/* Configure the CAN callback functions */
(*rom)->pCAND->config_calb(&callbacks);


SetGPIOOut(LED_PORT, LEDV_BIT);
SetGPIOOut(LED_PORT, LEDR_BIT);
SetGPIOOut(PORT_0, PIO0_3);
GPIOSetValue( PORT_0, PIO0_3, 0 ); //transceiver CAN hab. STB (en bajo --> Activo)



/* Enable the CAN Interrupt */
NVIC_EnableIRQ(CAN_IRQn);


msg_obj.msgobj = 0;
msg_obj.mode_id = 0x7FF; 
msg_obj.mask = 0x000;
(*rom)->pCAND->config_rxmsgobj(&msg_obj);

       while(1){

if (cuenta == 1000000){

ToggleGPIOBit(LED_PORT, LEDR_BIT);
cuenta = 0;


}
cuenta++;
}
}

receiver's code is very simple. I do not understand what the problem.:mad:
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Oct 04 12:26:09 MST 2011

Quote:

...values &#8203;&#8203;of the CANH and CANL voltages on the bus are correct...

Don't understand what you mean with voltages? Did you scope it? Can you see a message which is (periodically) transmitted? It's not necessary to decode this message, a scope can show you a correct baudrate.

Perhaps you should zip and post your (receiving) project, so software problems can be excluded :)
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mcabral on Tue Oct 04 12:11:54 MST 2011

Quote: Zero
Sorry, I can't help you if you don't answer my questions and don't follow my suggestions :mad:

If you can't confirm that a node is transmitting messages it's useless to look for a receiver problem :eek:

So please use a tx_counter as suggested in my code sample and, if possible, scope your bus to see if a valid message is transmitted or if your transmitter is desperate repeating a message without getting an acknowledge.



sorry if I did not understand. A node is transmitting loopback mode. Its transmission counter is incremented properly and the values &#8203;&#8203;of the CANH and CANL voltages on the bus are correct. Unfortunately I do not have a scanner "can" so I can not say if the message being transmitted is valid. However, the receiving node is not working as it should and does not run any interrupt routine.
However, both nodes operate correctly in loopback mode. Also we had the receiving node operating in silent mode with the same results.
I'm really confused with this.:confused:
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Oct 04 11:51:19 MST 2011
Sorry, I can't help you if you don't answer my questions and don't follow my suggestions :mad:

If you can't confirm that a node is transmitting messages it's useless to look for a receiver problem :eek:

So please use a tx_counter as suggested in my code sample and, if possible, scope your bus to see if a valid message is transmitted or if your transmitter is desperate repeating a message without getting an acknowledge.
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mcabral on Tue Oct 04 11:40:59 MST 2011

Quote: Zero
#1 Who is sending your data? Are you 100% sure that this message is sent correct (ID, baudrate...) ?

#2 As mentioned above, it's a good idea to transmit first. So if your  loop back is working, use a tx_counter and transmit a message with a  delay loop.
Scope it to check if it's transmitted correct and if your  baudrate is correct.

#3 Still don't know which hardware (and CAN-BUS) you are using and what you've scoped already?

#4 Use this receive object to receive everything:

msg_obj.msgobj = 1;
msg_obj.mode_id = 0x7FF;  //receive all 
msg_obj.mask = 0x000;



both nodes are operating at 125 Kb / sec and the IDs are properly configured for the reception. On the other hand, I implemented your suggestions but the reception counter operating in normal mode never increases because interrupts are never executed. CAN network is implemented with two nodes and has termination resistors of 120 Ohm. The transceiver is properly fed and although I don´t have a scanner Can I check the CANH and CANL voltages. Aparentemenet everything should work as expected but it is not.
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Oct 04 11:01:54 MST 2011
#1 Who is sending your data? Are you 100% sure that this message is sent correct (ID, baudrate...) ?

#2 As mentioned above, it's a good idea to transmit first. So if your  loop back is working, use a tx_counter and transmit a message with a  delay loop.
Scope it to check if it's transmitted correct and if your  baudrate is correct.

#3 Still don't know which hardware (and CAN-BUS) you are using and what you've scoped already?

#4 Use this receive object to receive everything:

msg_obj.msgobj = 1;
msg_obj.mode_id = 0x7FF;  //receive all 
msg_obj.mask = 0x000;
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mcabral on Tue Oct 04 10:43:24 MST 2011

Quote: Zero
Of course

Did you use the sample or did you create your own project?




Hi, thanks for answering
actually used the example code with some modifications. The problem is I can not find how to receive the data sent. I have doubts whether there is any configuration problem I am having in mind because everything is connected according to specifications.
The problem occurs in normal operation because loopback mode everything works as desired. However, in normal mode gives no interruption...
#include <cr_section_macros.h>
#include "driver_config.h"
#include "target_config.h"
#include "small_gpio.h"
#include "gpio.h"
#include "rom_drivers.h"

#ifndef NULL
#define NULL    ((void *)0)
#endif

__BSS(RESERVED) char CAN_driver_memory[256]; // reserva 256 bytes for CAN driver

ROM **rom = (ROM **)0x1fff1ff8;

CAN_MSG_OBJ msg_obj;
uint32_t cuenta;
uint32_t cuenta_Rx;
uint32_t status;

/* Initialize CAN Controller */
uint32_t ClkInitTable[2] = {
  0x00000000UL, // CANCLKDIV
  0x00001C57UL  // CAN_BTR
};

/* Callback function prototypes */
void CAN_rx(uint8_t msg_obj_num);
void CAN_tx(uint8_t msg_obj_num);
void CAN_error(uint32_t error_info);

/* Publish CAN Callback Functions */
CAN_CALLBACKS callbacks = {
   CAN_rx,
   CAN_tx,
   CAN_error,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
};

/*CAN receive callback */

void CAN_rx(uint8_t msg_obj_num){
ToggleGPIOBit(LED_PORT, LEDV_BIT);
cuenta_Rx++;
  return;
}

/*CAN transmit callback */

void CAN_tx(uint8_t msg_obj_num){
return;
}

/*CAN error callback */

void CAN_error(uint32_t error_info){

  return;
}

/*CAN interrupt handler */

void CAN_IRQHandler (void){
  (*rom)->pCAND->isr();
}

int main(void) {

InitGPIO();

/* Initialize the CAN controller */
(*rom)->pCAND->init_can(&ClkInitTable[0], 1);

/* Configure the CAN callback functions */
(*rom)->pCAND->config_calb(&callbacks);


SetGPIOOut(LED_PORT, LEDV_BIT);
SetGPIOOut(LED_PORT, LEDR_BIT);
SetGPIOOut(PORT_0, PIO0_3);
GPIOSetValue( PORT_0, PIO0_3, 0 ); 

//    //set loopback mode
//    LPC_CAN->CNTL |= (1<<7);
//    LPC_CAN->TEST |= (1<<4);

/* Enable the CAN Interrupt */
NVIC_EnableIRQ(CAN_IRQn);


/* Configure message object 1 to receive all 11-bit messages 0x200-0x2FF */
msg_obj.msgobj = 1;
msg_obj.mode_id = 0x200 | CAN_MSGOBJ_STD;
msg_obj.mask = 0x000;
(*rom)->pCAND->config_rxmsgobj(&msg_obj);



while(1){
if (cuenta == 1000000){

ToggleGPIOBit(LED_PORT, LEDR_BIT);
cuenta = 0;
}
cuenta++;
}
}


I hope someone can help me because I find no solution. Thanks in advance!
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Oct 04 09:02:13 MST 2011
Of course :)

Did you use the sample or did you create your own project?
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mcabral on Tue Oct 04 08:42:23 MST 2011
Hello again,
I tried to run the CAN communication and had no results. Loopback mode all is well. The problem remains that no messages are received from the network can.
Someone was able to establish communication with the rom drivers?
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Sep 29 05:05:17 MST 2011

Quote: TheDebugStore
Having adecode of CAN bus packets will give you far more information that a scope.



A lot of (cheap) USB scopes also allow a simple 'Serial decoding' of CAN, I2C, SPI, E.T....

Videos: http://www.picotech.com/picoscope6-serial-decoding.html
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by TheDebugStore on Thu Sep 29 04:37:48 MST 2011

Quote: mcabral
hello,
I'm beginning to test drivers lpc11c24 API (can on_chip) and my problem is that there are no interrupts in transmission and reception.
I have a scope on the port can and this information is being transmitted.
CAN interrupt is enabled and the callback functions are initialized,
but for some reason, when you call can_transmit () or can_receive (), there is no interruption is executed and performs the callback functions
Can anyone help me with this?
thanks!


I suggest that you use a CAN Bus Analyser.  We have a range of CAN Bus Analysers including the Total Phase Komodo CAN Duo (Analyser and exerciser) and the popular ZeroPlus LAP-C(16032) Logic Analyser with up to 30 protocol analysis modules free (including CAN 2).

Having adecode of CAN bus packets will give you far more information that a scope.

I hope this is helpful?

John Legg
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Sep 28 06:19:35 MST 2011
If loop back mode is working, check your CAN bus

 void CAN_tx(uint8_t msg_obj_num){
  tx_counter++;
  return;
}
This tx_counter isn't executed if the transmission wasn't successful :mad:
So if a breakpoint there does show no execution, your message wasn't received (achnowledged) from other nodes.


Quote:

...are two connected nodes...

...with termination?


Quote:

...that there is information...

.. and is it a CAN message or is it E.T. calling home :confused:
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mcabral on Wed Sep 28 05:50:18 MST 2011
in my project are two connected nodes. One is transmitted and the rest should receive the messages. The scope tells me that there is information on the network.
My question is: Can interruption is when you empty the transmission buffer or should I wait for a response from another node?
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by mcabral on Wed Sep 28 05:40:57 MST 2011
Hi,

Yes, I had tested in "loopback" and apparently all was well. The problem arose when I tried to operate in normal mode. Then run the program step by step shows that after a can_transmit (), the program does not execute the callback function.
I'm really surprised because I think callbacks functions properly configure and enable interrupts.

Thanks!!
0 Kudos
Reply

4,015 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Sep 27 17:11:14 MST 2011
Of course a modern chip is able to switch in a loop back mode to test CAN without working CAN bus and all this stuff

This code is based on can_onchip sample with enabled loop back mode. So your chip is transmitting and receiving without external CAN bus :eek:

Breakpoints in CAN_rx ([COLOR=Blue]rx_counter++[/COLOR]) and CAN_tx ([COLOR=Blue]tx_counter++[/COLOR]) will show this

/****************************************************************************
 *   $Id:: main.c 5034 2010-09-24 23:48:37Z nxp12832                        $
 *   Project: NXP LPC11xx CAN example
 *
 *   Description:
 *     This file is part of the CAN and CANopen on-chip driver examples.
 *
 ****************************************************************************
 * Software that is described herein is for illustrative purposes only
 * which provides customers with programming information regarding the
 * products. This software is supplied "AS IS" without any warranties.
 * NXP Semiconductors assumes no responsibility or liability for the
 * use of the software, conveys no license or title under any patent,
 * copyright, or mask work right to the product. NXP Semiconductors
 * reserves the right to make changes in the software without
 * notification. NXP Semiconductors also make no representation or
 * warranty that such application will be suitable for the specified
 * use without further testing or modification.
****************************************************************************/
#include "driver_config.h"
#include "target_config.h"

#include "rom_drivers.h"

#ifndef NULL
#define NULL    ((void *)0)
#endif

ROM **rom = (ROM **)0x1fff1ff8;

CAN_MSG_OBJ msg_obj;

/* Initialize CAN Controller */
uint32_t ClkInitTable[2] = {
  0x00000000UL, // CANCLKDIV
  0x00001C57UL  // CAN_BTR
};

/* Callback function prototypes */
void CAN_rx(uint8_t msg_obj_num);
void CAN_tx(uint8_t msg_obj_num);
void CAN_error(uint32_t error_info);

volatile unsigned short rx_counter=0; //receive counter
volatile unsigned short tx_counter=0; //transmit counter


/* Publish CAN Callback Functions */
CAN_CALLBACKS callbacks = {
   CAN_rx,
   CAN_tx,
   CAN_error,
   NULL,
   NULL,
   NULL,
   NULL,
   NULL,
};

/*    CAN receive callback */
/*    Function is executed by the Callback handler after
    a CAN message has been received */
void CAN_rx(uint8_t msg_obj_num){
 [B][COLOR=Red] [COLOR=Blue]rx_counter++;[/COLOR][/COLOR][/B]
  /* Determine which CAN message has been received */
  msg_obj.msgobj = msg_obj_num;

  /* Now load up the msg_obj structure with the CAN message */
  (*rom)->pCAND->can_receive(&msg_obj);

  if (msg_obj_num == 1)
  {
    /* Simply transmit CAN frame (echo) with with ID +0x100 via buffer 2 */
    msg_obj.msgobj = 2;
    msg_obj.mode_id += 0x100;
    (*rom)->pCAND->can_transmit(&msg_obj);
  }

  return;
}

/*    CAN transmit callback */
/*    Function is executed by the Callback handler after
    a CAN message has been transmitted */
void CAN_tx(uint8_t msg_obj_num){
  [COLOR=Blue][B]tx_counter++;[/B][/COLOR]
  return;
}

/*    CAN error callback */
/*    Function is executed by the Callback handler after
    an error has occured on the CAN bus */
void CAN_error(uint32_t error_info){
  return;
}

/*    CAN interrupt handler */
/*    The CAN interrupt handler must be provided by the user application.
    It's function is to call the isr() API located in the ROM */
void CAN_IRQHandler (void){
  (*rom)->pCAND->isr();
}

int main(void) {
   [COLOR=Red] volatile unsigned int i,counter=0;[/COLOR]

    /* Output the Clk onto the CLKOUT Pin PIO0_1 to monitor the freq on a scope */
    LPC_IOCON->PIO0_1    = (1<<0);
    /* Select the MAIN clock as the clock out selection since it's driving the core */
    LPC_SYSCON->CLKOUTCLKSEL = 3;
    /* Set CLKOUTDIV to 6 */
    LPC_SYSCON->CLKOUTDIV = 10;        //    CLKOUT Divider = 10
    /* Enable CLKOUT */
    LPC_SYSCON->CLKOUTUEN = 0;
    LPC_SYSCON->CLKOUTUEN = 1;
    while (!(LPC_SYSCON->CLKOUTUEN & 0x01));

    /* Initialize the CAN controller */
    (*rom)->pCAND->init_can(&ClkInitTable[0], 1);

    /* Configure the CAN callback functions */
    (*rom)->pCAND->config_calb(&callbacks);

 [B][COLOR=Red]   //set loop back mode
    LPC_CAN->CNTL |= (1<<7);
    LPC_CAN->TEST |= (1<<4);[/COLOR][/B]

    /* Enable the CAN Interrupt */
    NVIC_EnableIRQ(CAN_IRQn);

    /* Send a simple one time CAN message */
    msg_obj.msgobj  = 0;
    msg_obj.mode_id = 0x410;
    msg_obj.mask    = 0x0;
    msg_obj.dlc     = 4;
    msg_obj.data[0] = 'T';    //0x54
    msg_obj.data[1] = 'E';    //0x45
    msg_obj.data[2] = 'S';    //0x53
    msg_obj.data[3] = 'T';    //0x54
    (*rom)->pCAND->can_transmit(&msg_obj);

    /* Configure message object 1 to receive all 11-bit messages 0x400-0x4FF */
    msg_obj.msgobj = 1;
    msg_obj.mode_id = 0x400;
    msg_obj.mask = 0x700;
    (*rom)->pCAND->config_rxmsgobj(&msg_obj);    

    while(1)
    {
    [COLOR=Red] i++;
     if(i>100000)
     {
      i=0;
      /* Send a simple CAN message */
      msg_obj.msgobj  = 0;
      msg_obj.mode_id = 0x411;
      msg_obj.mask    = 0x0;
      msg_obj.dlc     = 5;
      msg_obj.data[0] = 'T';    //0x54
      msg_obj.data[1] = 'E';    //0x45
      msg_obj.data[2] = 'S';    //0x53
      msg_obj.data[3] = 'T';    //0x54
      msg_obj.data[4] = counter;
      (*rom)->pCAND->can_transmit(&msg_obj);
      counter++;
     }[/COLOR]
    }
}
0 Kudos
Reply