LPC11Cxx and CAN OnChip [Example]

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

LPC11Cxx and CAN OnChip [Example]

523 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by teslabox on Mon Nov 14 04:05:29 MST 2011
Hello,

I use LPC11C24 and I found ZIP file "LPC11C14_CAN_ONCHIP_Sample". I want to receive one special CAN message with special ID and check in the value in "IF", and then inside "IF" send another CAM message. To do it I use two ROM functions:
(*rom)->pCAND->can_receive (&msg_obj);
and
(*rom)->pCAND->can_transmit(&msg_obj);
They work great separetely but when I want to receive some messages and then send another it doesn't work.
How to use these rom function to properly send and transmit CAN mesages?
(there are also: (*rom)->pCAND->config_rxmsgobj(&msg_obj); - I don't know what it is... and what for?)
0 Kudos
Reply
5 Replies

423 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Tue Nov 15 09:54:02 MST 2011

Quote:

It works! My whole algorithm is working...

And is waiting to surprise you later... :rolleyes:


Quote:

...but how to solve the values for 500 kbps...

Someone posted this for 500kHz @ 48MHz :eek:
[Code]
// Initialize CAN Controller  @48MHz 500kHz
uint32_t ClkInitTable[2] = {
  0x00000002UL, // CANCLKDIV
  0x107UL          // CAN_BTR
};
[/Code]in http://knowledgebase.nxp.com/showthread.php?t=2537
0 Kudos
Reply

423 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by teslabox on Tue Nov 15 07:47:30 MST 2011
It works! My whole algorithm is working but how to change CAN bitrate fron original 125 kbps to 500 kbps? There is a table with BTR values (BRP, TSEG1, TSEG2, SJW):
/* Initialize CAN Controller */
uint32_t ClkInitTable[2] = 
{
  0x00000000UL, // CANCLKDIV
  0x00001C57UL  // CAN_BTR
};

but how to solve the values for 500 kbps (CLKOUT is 4,8 MHz)?
0 Kudos
Reply

423 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Nov 14 07:03:22 MST 2011
That's nonsense :eek:

Just detect your IDs in CAN_rx() as suggested before :)
0 Kudos
Reply

423 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by teslabox on Mon Nov 14 06:46:55 MST 2011
I make as follows:

    for (;;)
    {
        msg_obj.msgobj = 1;                            // 1 -> means Standard Frame receive (Standard == 11 bit)
        msg_obj.mode_id = 0x400;                    // start ID == 0x400
        msg_obj.mask = 0x700;                        // mask ID == 0x700 -> stop ID == 0x4FF
        (*rom)->pCAND->config_rxmsgobj(&msg_obj);    // configure message object 1 to receive all 11-bit messages 0x400-0x4FF
        (*rom)->pCAND->can_receive(&msg_obj);        // load up the msg_obj structure with the CAN message

        if (msg_obj.mode_id == 0x401)
        {
            LPC_GPIO0->DATA |= (1<<7);        // LED 1 ON
            LPC_GPIO2->DATA &=~(1<<10);        // LED 2 OFF
            delay (500);
         }
        if (msg_obj.mode_id == 0x402)
        {
            LPC_GPIO0->DATA &=~(1<<7);        // LED 1 OFF
            LPC_GPIO2->DATA |= (1<<10);        // LED 2 ON
            delay (500);
        }
        else
        {
            LPC_GPIO0->DATA |=(1<<7);        // LED 1 OFF
            LPC_GPIO2->DATA |=(1<<10);        // LED 2 OFF
        }
    }
and it works (enter to the "IFs") but I have to send to LPC11X24 a lot of messages (ID 0x402 or 0x401) to turn on only one LED. Something works to slowly?

---------------------------------------------------------------------------------------------------
OK, I made some changes and it is OK:
    msg_obj.msgobj = 1;                            // 1 -> means Standard Frame receive (Standard == 11 bit)
    msg_obj.mode_id = 0x400;                    // start ID == 0x400
    msg_obj.mask = 0x700;                        // mask ID == 0x700 -> stop ID == 0x4FF
    (*rom)->pCAND->config_rxmsgobj(&msg_obj);    // configure message object 1 to receive all 11-bit messages 0x400-0x4FF

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

        if (msg_obj.mode_id == 0x401)
        {
            LPC_GPIO0->DATA |= (1<<7);        // LED 1 ON
            LPC_GPIO2->DATA &=~(1<<10);        // LED 2 OFF
            delay (500);
         }
        if (msg_obj.mode_id == 0x402)
        {
            LPC_GPIO0->DATA &=~(1<<7);        // LED 1 OFF
            LPC_GPIO2->DATA |= (1<<10);        // LED 2 ON
            delay (500);
        }
        else
        {
            LPC_GPIO0->DATA |=(1<<7);        // LED 1 OFF
            LPC_GPIO2->DATA |=(1<<10);        // LED 2 OFF
        }
    }
}

It drives the LEDs immediately after when I send messages to my LPC11Cxx :).
0 Kudos
Reply

423 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Mon Nov 14 04:24:41 MST 2011
This part is used to define the message and its mask you want to receive:

    /* 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);    
This part is used to receive a message:

/*    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){
  
  /* 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)
  {
    //INSERT ID check here

    /* 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;
}
So you can either set your message object ID and mask to receive just 1 ID, or you can check received IDs in CAN_rx()
0 Kudos
Reply