sarma.ank
Joined: 25 Mar 2011 Posts: 1
|
is this CAN configuration for PIC 18F2480 correct? |
Posted: Fri Mar 25, 2011 6:57 am |
|
|
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; |
|
|