Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

CAN communication

Status
Not open for further replies.

deepa.malagi

New Member
HI all,

I am using pic18f4585 ic. I am facing a problem in can communication please help me.

problem is, TXREQ is always 1(not getting '0')
i am not getting what is the problem.

I have configured CAN in HS mode(500Kbps)
and also help me in calculating baud rate prescale

I am using internal oscillator(8MHz).
& My code is,
Code:
void HS_CAN_Init(void)
{
//configuration mode   
//CANCONbits.ABAT=1;

CANCONbits.REQOP2 = 1;
CANCONbits.REQOP1 = 0;
CANCONbits.REQOP0 = 0;
//CANCONbits.ABAT=0;
   while ((CANSTAT & 0xE0) != 0x80);
ECANCON=0x00; //40
//baud rate confi
    BRGCON1=0x07;
   BRGCON2=0x92;
   BRGCON3=0x02;

CIOCON=0x20;   //20
TRISB=0x08;
//PORTB=0xFF;
//filter config

RXB0CON=0x20;  //receive only standard messages, 24
RXB1CON=0x20;  //20
//RXB0SIDL=0x60;
//RXB0SIDH=0x00;

 //sidl
  //    ptr--;
  //    *ptr=(make8(id,0) << 5) & 0xE0;
//RXB0SIDL=((0x01) << 5) & 0xE0);

      //sidh
   //   ptr--;
   //   *ptr=(make8(id,0) >> 3) & 0x1F;
   //   *ptr|=(make8(id,1) << 5) & 0xE0;
//RXB0SIDH = ((0x01) >> 3) & 0x1F);
//RXB0SIDH |= ((0x02) << 5) & 0xE0);
      
TXB0DLC=0x08;
RXB0DLC=0x08; //48
//RXF0SIDL=0x40;
//RXF0SIDH=0x00;

//RXF0SIDL=((0x01 << 5) & 0xE0);
//RXF0SIDH = ((0x01 >> 3) & 0x1F);
//RXF0SIDH |= ((0x02 << 5) & 0xE0);

RXM0SIDL=0xE3;  //0x00
RXM0SIDH=0xFF;  //0x00
RXFCON0=0x03; //01
RXFCON1=0;
RXFBCON0  = 0x10;  //00
RXFBCON1  = 0x00;
RXFBCON2  = 0x00;
RXFCON0  = 0x03;  //01
RXFCON1  = 0x00;
MSEL0=0x54;  //FC
//return to loopback mode 

CANCONbits.REQOP2 = 0;
CANCONbits.REQOP1 = 0;
CANCONbits.REQOP0 = 0;
while ((CANSTAT & 0xE0) != 0x00);
}

void send_CAN(void)
{
   TXB0D0=0;
   TXB0D1=0;
   TXB0D2=0x28;   
   TXB0D3=0;   
   TXB0D4=0;   //k1
   TXB0D5=0;  //k
   TXB0D6=0;
   TXB0D7=0;    
   TXB0SIDL=((0x40 << 5) & 0xE0);
   TXB0SIDH = ((0x40 >> 3) & 0x1F);
   TXB0SIDH |= ((0x04 << 5) & 0xE0);
   TXB0CONbits.TXREQ=1;
   while(TXB0CONbits.TXREQ == 1);
}
Please help me.....
 
Last edited by a moderator:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top