Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Pic18f4580 CAN protocol Doesnt Work

Status
Not open for further replies.

prabhakarandhar

Newbie level 2
Newbie level 2
Joined
Jan 22, 2011
Messages
2
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,304
i did the interface between two pic18f4580 using CAN protocol but i didnt work... i doesnt go to Configure mode please help me
// hitech c
#include<pic18.h>
struct CANMessage
{
unsigned long Address;
unsigned char Data[8];
unsigned char NoOfBytes;
};
struct CANMessage RX_Message, TX_Message, ReturnMessage;

char CANPut(struct CANMessage Message)
{
TXB0D0 = Message.Data[0];
TXB0SIDL = Message.Address<<5&0xff;
TXB0SIDH = Message.Address>>3&0xff;
while(TXB0CONbits.TX0IF!=1);
TXB0CONbits.TX0IF = 0;
}

struct CANMessage CANGet(void)
{
unsigned int Add,Add1;
ReturnMessage.Data[0] = RXB0D0;
Add = RXB0SIDH;
Add1= RXB0SIDL;
Add1= (Add1 >> 5)|(Add<<3);
ReturnMessage.Address = Add1;
}

void Can_isr()
{
if(RXB0IF)
{
RXB0IF =0;
RXB0CONbits.RXFUL =0;
RX_Message = CANGet();
}
}


void Can_Set_Baudrate(void)
{
BRGCON1 = 0X01;
BRGCON2 = 0X90;
BRGCON3 = 0X42;
}

void Can_Set_TxBuffer(void)
{
TXB0CON = 0x03; // Highest Priority
TXB0SIDL = 0xE0;
TXB0SIDH = 0xFF;
TXB0DLC = 0x08; // 8 byte Data length
TXB0D0 = 0X00;
TXB0D1 = 0X01;
TXB0D2 = 0X02;
TXB0D3 = 0X03;
TXB0D4 = 0X04;
TXB0D5 = 0X05;
TXB0D6 = 0X06;
TXB0D7 = 0X07;
}

void Can_Set_RxBuffer(void)
{
RXB0CON = 0X20;
RXB0SIDL = 0XE0;
RXB0SIDH = 0XFF;
RXB0DLC = 0x80;
RXB0D0 = 0X00;
RXB0D1 = 0X00;
RXB0D2 = 0X00;
RXB0D3 = 0X00;
RXB0D4 = 0X00;
RXB0D5 = 0X00;
RXB0D6 = 0X00;
RXB0D7 = 0X00;
}

void Can_Set_AMFilter()
{
RXF0SIDL = 0xE0;
RXF0SIDH = 0xFF;
RXM0SIDH = 0X00;
RXM0SIDL = 0X00;
}


void Can_Init(void)
{
TRISB = 0x08;
PEIE=1;
GIE=1;
ECANCON = 0x00; //Mode-0
CANCON = 0x80;
PORTC = CANSTAT;
while(CANSTAT&0X80==1);
Can_Set_Baudrate();
Can_Set_TxBuffer();
Can_Set_RxBuffer();
Can_Set_AMFilter();
CANCON = 0X00;
while(CANSTAT&0XE0!=0);
PIR3 = 0X00;
PIE3 = 0X01;
IPR3 = 0X01;
}

void main()
{
Can_Init();
while(1)
{
TX_Message.Address = 0x123;
TX_Message.Data[0] = 'A';
TX_Message.NoOfbytes = 1;
CanPut(TX_Message);
}
 

What is the baudrate that you are trying to set ?
And I don't understand the register settings.
When you say BRGCON1=0X01, does it set only the SJW ? What is the value of the BRP ? (bits which control the baud rate prescaler)
 
hi can you send the program of CAN TRANSMITTER AND RECEIVER... I WORKED WITH PIC18F4580...

- - - Updated - - -

Hello frens,

can any one having CAN Program for pic184580... i almost finished coding ..but not working due to some code.. pls help me to do that.....
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top