I've had a problem with 4 nodes, and 2 different libraries, one of which I did at one point have working. I can't seem to get them to send a transmission. I'm using two of them, with the mcp2551 transceiver on every node.
I've made a very quick schematic of the test boards that I'm using, There are 4 LEDs and 4 inputs. Those all work, typically. I have noticed some odd behavior, and you will see in my code that I have a while statement to turn off an LED, while in loopback mode that is the only way to get it to turn off.
A zipfile containing the J1939 library I have used once before, but can't currently use, as well as my current hobbled together code. I used the XC8 compiler with MPLABX and the PICKIT3. The files are located at http://tomt.me/halp/CANTest.zip
The two functions that are likely the most likely to be causing an issue if its software are included below. Under testmsg This is the line it will hang at:
while (TXB0CONbits.TXREQ);
Reading has lead me to believe that it is not getting an acknowledgement. I believe all nodes should take any messages from anywhere. I have also tried hooking the rx of node A to the tx of node b, as well as the tx of node a to the rx of node b, same result. Same result using a different mcp2551 chip, and same result using a different set of pic18f45k80 chips with their own mcp2551's on a plug-n-play breadboard. Also the same result with all four of them hooked up together. It's like the mcp2551's cant talk to each other. I feel I'm missing something important yet I just don't know what it is. Do I need to provide power to CANH and CANL? If so where can I read up about that? What else could be wrong? I'm just confused and very frustrated. I've tried everything I can think of, but it isn't working.
Thank you for your time.
I've made a very quick schematic of the test boards that I'm using, There are 4 LEDs and 4 inputs. Those all work, typically. I have noticed some odd behavior, and you will see in my code that I have a while statement to turn off an LED, while in loopback mode that is the only way to get it to turn off.
A zipfile containing the J1939 library I have used once before, but can't currently use, as well as my current hobbled together code. I used the XC8 compiler with MPLABX and the PICKIT3. The files are located at http://tomt.me/halp/CANTest.zip
The two functions that are likely the most likely to be causing an issue if its software are included below. Under testmsg This is the line it will hang at:
while (TXB0CONbits.TXREQ);
Reading has lead me to believe that it is not getting an acknowledgement. I believe all nodes should take any messages from anywhere. I have also tried hooking the rx of node A to the tx of node b, as well as the tx of node a to the rx of node b, same result. Same result using a different mcp2551 chip, and same result using a different set of pic18f45k80 chips with their own mcp2551's on a plug-n-play breadboard. Also the same result with all four of them hooked up together. It's like the mcp2551's cant talk to each other. I feel I'm missing something important yet I just don't know what it is. Do I need to provide power to CANH and CANL? If so where can I read up about that? What else could be wrong? I'm just confused and very frustrated. I've tried everything I can think of, but it isn't working.
Thank you for your time.
Code:
//Send a test message
void testmsg(unsigned char msg){
TXB0EIDH = 0x0000; //Clear extended IDs
TXB0SIDH = msg;
TXB0D0 = 1;
TXB0DLC = 0x00 | 1; //changed from count to 1 //Set the RTR flag to false, and set the DLC register.
TXB0CON = TXB0CON | 0x08 ; //Set the TXREQ flag.
LED3 = 1;
while (TXB0CONbits.TXREQ);
while (!(LED3=0)); //This SHOULDN'T BE REQUIRED!!!
LED1 ^= 1;
}
Code:
/*
* Initilize the chip, and CAN module.
*/
void Init(){
// Set the internal oscillator to 64MHz
OSCCONbits.IRCF = 7;
OSCTUNEbits.PLLEN = 1;
//Initialize I/O to be digital
ANCON0 = ANCON1 = 0x00;
//Set I/O
TRISC = 0x0F; // LED's then Inputs
//Set all LED's off.
LATC = 0x00;
//Set io for tx/rx pins
TRISB3 = 1; //RX pin
TRISB2 = 0; //TX Pin
// Initialize CAN module
// Enter CAN module into config mode
CANCON = 0x80; //REQOP<2:0>=100
while(!(CANSTATbits.OPMODE ==0x04));
//Select ECAN Mode 2
ECANCON = 0xA0; //enhanced fifo, with interrupt when one buffer remains, Acceptance Filters 0, 1, 2 and BRGCON2, 3
// Initialize CAN Timing to 1 Mbps @ 64MHz
//BRGCON1 = 0x81; //0000 0011 //SJW=3TQ BRP 1
//BRGCON2 = 0xB8; //1011 1000 //SEG2PHTS 1 sampled once PS1=8TQ PropagationT 1TQ
//BRGCON3 = 0x05; //0000 0101 //PS2 6TQ
// 100 Kbps @ 64MHz
BRGCON1 = 0x93; //0001 1111 //SJW=3TQ BRP 31
BRGCON2 = 0xB8; //1010 0000 //SEG2PHTS 1 sampled once PS1=8TQ PropagationT 1TQ
BRGCON3 = 0x05; //0000 0010 //PS2 6TQ
// Initialize Receive Masks
//Recieve ALL messages
RXM0EIDH = 0x00; //Extended ID Mask
RXM0EIDL = 0x00;
RXM0SIDH = 0x00; // Standard ID Mask
RXM0SIDL = 0x00;
//Disable Filters
RXFCON0 = 0x00; //Disable all
RXFCON1 = 0x00; //Disable all
// Enter CAN module into normal mode
//CANCON = 0x40; //Loopback Mode
CANCON = 0x00; //Normal Mode
while(CANSTATbits.OPMODE==0x00);
// Set Receive Mode for buffers
RXB0CON = 0x00;
RXB1CON = 0x00;
}
Last edited: