CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

is this CAN configuration for PIC 18F2480 correct?

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
sarma.ank



Joined: 25 Mar 2011
Posts: 1

View user's profile Send private message

is this CAN configuration for PIC 18F2480 correct?
PostPosted: Fri Mar 25, 2011 6:57 am     Reply with quote

Hi All,
I have PIC 18F2480 connected to TJA1040 can transceiver and clock is 8Mhz.
Could anyone tell me, whether my configuration is correct or not?
Code:

#define CONFIG_MODE 0x9F
#define MODE_MASK 0xE0
#define NORMAL_MODE 0x1F
#define MY_IDENT 0x7DF
#define MY_ADDRESS_IDENTIFIER MY_IDENT



CANCON = (CONFIG_MODE & MODE_MASK) | (CANCON & 0x3F); //Set configuration mode
while((CANSTAT & MODE_MASK) != (CONFIG_MODE & MODE_MASK));  //Wait until config mode is set

/*Baud rate:250Kbps, sampling frequency:75%*/
BRGCON1 = 0x01;
BRGCON2 = 0x83;
BRGCON3 = 0x01;

CIOCON = 0x30;               
IPR3 = 0xFF;

CANCON = (NORMAL_MODE & MODE_MASK) | (CANCON & (MODE_MASK ^ 0xFF));              //Set normal mode
while((CANSTAT & MODE_MASK) != (NORMAL_MODE & MODE_MASK));     //Wait until normal mode is set

PIE3 = 0xA0;         //Enable CAN interrupts except TX interrupts
PIR3 = 0xA4;                  //Set TXB1 & TXB2 int flagss

CANCON |= 0x08;

TXB0SIDL = (unsigned char)(MY_ADDRESS_IDENTIFIER << 5);
TXB0SIDH = (unsigned char)(MY_ADDRESS_IDENTIFIER >> 3);     //Load address with MY_ADDRESS_IDENTIFIER standard identifier
TXB0DLC = 0x01;                                   
TXB0D0 = 0xAA;
TXB0D1 = 0xAA;
TXB0D2 = 0xAA;
TXB0D3 = 0xAA;
TXB0D4 = 0xAA;
TXB0D5 = 0xAA;
TXB0D6 = 0xAA;
TXB0D7 = 0xAA;
TXB0CON = 0x00;                                    //Initiate transmission
TXB0REQ = 1;
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group