CAN - Self test

キャンセル
次の結果を表示 
表示  限定  | 次の代わりに検索 
もしかして: 

CAN - Self test

663件の閲覧回数
lpcware
NXP Employee
NXP Employee
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);
    

}
0 件の賞賛
返信
4 返答(返信)

514件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rahulvasist on Sat Oct 08 22:58:45 MST 2011
Ya, got it thanks. I had misunderstood the datasheet. I thought both SRR and TR bits must be set.
0 件の賞賛
返信

514件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Oct 08 21:40:47 MST 2011
Are you kidding? What do you think is:

 LPC_CAN1->CMR |= 0b1; 
in your TX routine doing?

Did you try to change that line to:
LPC_CAN1->CMR  = (1<<4);                //send with self reception
0 件の賞賛
返信

514件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by rahulvasist on Sat Oct 08 21:06:40 MST 2011
I've set the SRR bit. The code-

LPC_CAN1->CMR=0b00110000

which is the 7th line in main funciton does that.
0 件の賞賛
返信

514件の閲覧回数
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Ex-Zero on Sat Oct 08 12:47:33 MST 2011
Your code includes a lot of nonsense :), but it fails because you are not transmitting with 'Self Reception Request' :eek:

 LPC_CAN1->CMR  = (1<<4);                //send with self reception
Note: CMR registers are WO, so don't read and OR them :eek:
0 件の賞賛
返信