LPC1769 CANbus off

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

LPC1769 CANbus off

670 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pollo89 on Wed Feb 20 04:42:51 MST 2013
Hi,
I've a LPC1769 and I connected it to my PC via CAN ( with a IXXAT USBtoCAN compact ). My firmware is a simply loop that ReceiveMessage ( and increase an index ).
I send messages with MiniMon ( ixxat software ) and it's all ok, but when I continue sending, minimon stop connections ( bus off ).
My question is: "Is code ok?".

See minimon log that i allegated.
Here my code
int main(void) {
    unsigned long i;
    CAN_MSG_Type RxMsg;            // Can RxMsg.
    PINSEL_CFG_Type pinCfg;
    // Initialize pins
    pinCfg.Funcnum = 1;
    pinCfg.OpenDrain = pinCfg.Pinmode = pinCfg.Portnum = 0;
    pinCfg.Pinnum = 0;
    PINSEL_ConfigPin(&pinCfg);  // P0.0 = CAN1RX
    pinCfg.Pinnum = 1;
    PINSEL_ConfigPin(&pinCfg);  // P0.1 = CAN1TX

    CAN_Init(LPC_CAN1 , 500000 );            // Initialize CAN1 at 500kbps
    CAN_SetAFMode( LPC_CANAF , CAN_AccBP ); // Bypass Access Filter. All ID accepted.
    i=0;
    while(1)
    {
        if( CAN_ReceiveMsg( LPC_CAN1 , &RxMsg ) == SUCCESS ) // Receive a message
            i++;
    }
    return 0 ;
}
0 Kudos
9 Replies

456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Feb 28 07:26:36 MST 2013
Please open a new thread for a new question (and delete this post here) :)
0 Kudos

456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by tarik1985 on Thu Feb 28 07:14:18 MST 2013
hi,
i'm new in J1939 communication for lpcxpresso1769 with LPCXPRESSO IDE, i want to create a code for reception a message but i don't know how to use and find the documentation C.:confused:
thaks
0 Kudos

456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Thu Feb 21 09:28:37 MST 2013

Quote: pollo89
EDIT: Added local self test code.
It works for some cycles ( or zero cycles ), then no more receive...



If Local Self Test fails it's time to check your hardware :eek:

Local self Test requires a RD / TD connection. This is usually done by your transceiver ;)
To avoid problems with a damaged transceiver you can also use a simple 1k resistor to connect them :)
0 Kudos

456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pollo89 on Wed Feb 20 09:28:10 MST 2013
I see,  I misunderstood from "can_self_test.c" written by code_red.
Now i can't test.
Tomorrow

EDIT: Added local self test code.
It works for some cycles ( or zero cycles ), then no more receive...
#define CANTESTMODE 1
int main(void) {
    CAN_MSG_Type TxMsg,RxMsg;            // CAN Msgs
    PINSEL_CFG_Type pinCfg;
    unsigned int i;
    // Initialize pins
    pinCfg.Funcnum = 1;
    pinCfg.OpenDrain = pinCfg.Pinmode = pinCfg.Portnum = 0;
    pinCfg.Pinnum = 0;
    PINSEL_ConfigPin(&pinCfg);  // P0.0 = CAN1RX
    pinCfg.Pinnum = 1;
    PINSEL_ConfigPin(&pinCfg);  // P0.1 = CAN1TX

    CAN_Init(LPC_CAN1 , 500000 );            // Initialize CAN1 at 500kbps
#if CANTESTMODE
    CAN_ModeConfig( LPC_CAN1 , CAN_SELFTEST_MODE , ENABLE );
#endif
    CAN_SetAFMode( LPC_CANAF , CAN_AccBP ); // Bypass Access Filter. All ID accepted.
    CAN_InitMessage( &TxMsg , &RxMsg );
    i=0;
    while(1)
    {
#if CANTESTMODE
        // Status CAN_SendMsg (LPC_CAN_TypeDef *CANx, CAN_MSG_Type *CAN_Msg, unsigned char self_test );
        CAN_SendMsg(LPC_CAN1, &TxMsg,1); //
#endif
        if( CAN_ReceiveMsg( LPC_CAN1 , &RxMsg ) == SUCCESS ) // Receive a message
            i++;
    }
    return 0;
}
0 Kudos

456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Feb 20 08:56:24 MST 2013

Quote: pollo89
Second time that I set Self Reception Request ( after reading ), Status Read Buffer is still 0.



:confused:

Your Self reception code is nonsense :eek:

This bit has to be set in your CAN_SendMsg() instead transmit bit for each transmit buffer

Something like:
Status CAN_SendMsg (...
{
...
        /*Write transmission request Tx Buffer 1*/
        if(self_recep)
             CANx->CMR = 0x30;
        else
             CANx->CMR = 0x21;
...
        /*Write transmission request Tx Buffer 2*/
        if(self_recep)
            CANx->CMR = 0x50;
        else
            CANx->CMR = 0x41;
...        
        /*Write transmission request Tx Buffer 3*/
        if(self_recep)
            CANx->CMR = 0x90;
        else
            CANx->CMR = 0x81;
0 Kudos

456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pollo89 on Wed Feb 20 08:31:37 MST 2013
My CAN transceiver should be a philips.
ixxat usb-to-can interfaces is here

By the way, I set up self-test mode.
It all works if transceiver is power off ( with no 5Volt vcc ).
If i give it 5Volt vcc, it doesn't work.
Second time that I set Self Reception Request ( after reading ), Status Read Buffer is still 0.

#define CANTESTMODE 1
int main(void) {
    unsigned long i;
    CAN_MSG_Type TxMsg,RxMsg;            // CAN Msgs
    PINSEL_CFG_Type pinCfg;
    // Initialize pins
    pinCfg.Funcnum = 1;
    pinCfg.OpenDrain = pinCfg.Pinmode = pinCfg.Portnum = 0;
    pinCfg.Pinnum = 0;
    PINSEL_ConfigPin(&pinCfg);  // P0.0 = CAN1RX
    pinCfg.Pinnum = 1;
    PINSEL_ConfigPin(&pinCfg);  // P0.1 = CAN1TX

    CAN_Init(LPC_CAN1 , 500000 );            // Initialize CAN1 at 500kbps
#if CANTESTMODE
    CAN_ModeConfig( LPC_CAN1 , CAN_SELFTEST_MODE , ENABLE );
#endif
    CAN_SetAFMode( LPC_CANAF , CAN_AccBP ); // Bypass Access Filter. All ID accepted.
    CAN_InitMessage( &TxMsg , &RxMsg );
#if CANTESTMODE
    CAN_SendMsg(LPC_CAN1, &TxMsg);
    LPC_CAN1->CMR |=(1<<4);                    //Self Reception Request ( works)
#endif
    i=0;
    while(1)
    {
        if( CAN_ReceiveMsg( LPC_CAN1 , &RxMsg ) == SUCCESS ){ // Receive a message
            i++;
        }
#if CANTESTMODE
        LPC_CAN1->CMR |= (1<<4);            //Self Reception Request ( doesn't work )
#endif
    }
    return 0;
}
0 Kudos

456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Feb 20 07:27:53 MST 2013
I'm not familiar with your I-XY toy :eek: (Is it an Apple product?)

As mentioned above modern CAN Controller include test functions. Therefore I always start working with a new chip with:

#1 Enable Self Test Mode and transmit a message in a slow (1s) loop. In Self test mode [COLOR=Red]no ACK and therefore no second node is required[/COLOR]. Now scoping your CAN lines is (or is not) showing you a working CAN signal with correct baudrate.

#2 Enable Self Reception and try to read messages from #1.

Until now there's no other CAN device necessary (which can kid you with its settings ;)). Now you can connect other CAN nodes and hope that they work.
If so you can switch off Self Test mode and your nodes should ACK messages.

But that's just the way I'm used to work with Atmel, Philips and NXP CAN. But I would strongly recommend to use this test functions before other nodes are connected :)
0 Kudos

456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by pollo89 on Wed Feb 20 06:14:50 MST 2013
I want to do an echo test without interrupt.
In this way I think that polling is the best way ( I'm newbe, I'll accept suggests ).
I think anyway that 'Local Self-Test' can't help me but I'll try.
LPC found same messages, after that gave me minimon give me busoff error. If I reconnect minimon, it still accept message like before...
By the way, In IXXAT MiniMON FAQ:
[B]1. According to the CAN specification, dependening on the receive error counter, the CAN node can have the following states: 000-127: error-active state 128-255: error-passive state 256- : Bus-Off What the relation between this states and the state of the Minimon32 LEDs (BusOff-, Error- and Reset-LED) ?[/B]
The error LED shows, whether the CAN controller is in warning level state. Error Counter: <= 96 : Error LED is green. 
Error Counter: > 96 : Error LED ist red. 
Error Counter: < 256 : Bus-Off LED ist green. 
Error Counter: = 256 : Bus-Off LED ist red. 
The Reset LED shows, whether the CAN controller is in initialisiation mode (RESET) or activ (RUN).
Can I see error frames?
0 Kudos

456 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Wed Feb 20 05:13:42 MST 2013
I'm not familiar with polling received CAN messages :eek:

Your code doesn't look wrong :) Did you already transmit messages from LPC to confirm that your LPC hardware :confused:  is working ?

BTW: LPC1769-CAN is including useful 'Local Self-Test' and ‘Self Reception’  ;)
0 Kudos