lpcware

CAN - Self test

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 15, 2016 by lpcware
Content originally posted in LPCWare by rahulvasist on Sat Oct 08 10:05:27 MST 2011
Hi,
I´m trying to implement CAN on lpc1769. I´ve configured the CAN controller in local self test mode. I´ve connected the TD1 and RD1 through a 1K resistor to simulate a transceiver, but I´m not receiving interrupts for reception. I´ve attached the code below. Can anyone please help me sort this out?

Thank You in advance



#include "LPC17xx.h¨
unsigned int rxBuffer[2];

void canTx(unsigned int id, unsigned int datalen, unsigned int a[])
{
    unsigned int len;

    while(!(LPC_CAN1->SR & 0b0100));
    LPC_CAN1->TFI1= (datalen<<16);       //to set the DLC

    LPC_CAN1->TID1= id;                 //to set the message id

    LPC_CAN1->TDA1 = a[0];             //data
    LPC_CAN1->TDB1 = a[1];

    LPC_CAN1->CMR |= 0b1;
}


void CAN_IRQHandler(void)
{
    unsigned int status;
    status=LPC_CAN1->ICR;

    switch(status)
    {
    case 1: rxBuffer[0]=LPC_CAN1->RDA;
            rxBuffer[1]=LPC_CAN1->RDB;
            LPC_CAN1->CMR |= (1<<2);
        break;

    case 0b10: break;

    }

}




int main(void) {
unsigned int data[]={0xaa, 0xbb}, test;
LPC_SC->PCONP |= (1<<13);
LPC_PINCON->PINSEL0 |=(0b0101);

LPC_CAN1->MOD=0b01;           //to set in reset mode
LPC_CAN1->MOD |= 0b000100;  //to set the self test bit
test = LPC_CAN1->MOD;

LPC_CAN1->CMR=0b00110000;     //stb1 selected and self reception enabled

LPC_CAN1->IER = 0b001;        //ri enabled

LPC_CAN1->MOD &= ~(0b1);      //setting the can in operating mode

LPC_CANAF->AFMR = 0b10;      //AF in bypass mode
NVIC_EnableIRQ(CAN_IRQn);

while ( !(LPC_CAN1->GSR & (1 << 3)) );
canTx(0x00, 8, data);


while(1);
   

}

Outcomes