Hi
I'm having trouble with my 2nd CAN block on the LPC2364. The initialization goes fine (CAN2MOD is set to 0x00 in the end), but when I want to send a CAN message, it disables the CAN block by the transmission request. What could be the cause of it. The hardware works fine, idem for CAN block 1. When I step trough the code, CAN block 1 don't disable the CAN 1 operation mode. What's the difference with CAN 2?
This is my init and transmist code:
void initCAN() { // turn on power of CAN blocks: bit 13/14 of PCONP PCONP |= 1 << 13; // CAN 1 PCONP |= 1 << 14; // CAN 2 // P0.21 and P0.22 for CANRx1 and CANTx1 (TD1, RD1) = 11 PINSEL1 |= 0x3C00; // P0.4 and P0.5 for CANRx2 and CANTx2 (TD2, RD2) = 10 PINSEL0 |= 0xA00; CAN1MOD = CAN2MOD = 0x01; // Reset CAN CAN1IER = CAN2IER = 0x00; // Disable Receive Interrupt CAN1GSR = CAN2GSR = 0x00; // Reset error counter when CANxMOD is in reset // Baudrate Prescaler CAN1BTR = CAN2BTR = 0x7E0001; // 500K IODIR0 |= 1<<20; // CAN1_TXEN = output IOCLR0 |= 1<<20; // CAN1_TXEN = low --> activate transceiver IODIR0 |= 1<<6; // CAN2_TXEN = output IOCLR0 |= 1<<6; // CAN2_TXEN = low --> activate transceiver CAN1MOD = CAN2MOD = 0x00; // CAN in operating mode installInterruptCAN(0x17, 0xFF, (void *)canHandler); //0x17 = 0d23 CAN1IER = CAN2IER = 0x01; // enable receive interrupts }
int TransmitHandler(MESSAGE *sendMsg, U8 can) { if(can == 0x01){ volatile unsigned status = CAN1SR; if(status & 0x04) // Transmit buffer 1 released { //RTR, long or short ID & DLC CAN1TFI1 = sendMsg->Frame & 0xC00F0000; CAN1TID1 = sendMsg->canID; CAN1TDA1 = sendMsg->DataA; CAN1TDB1 = sendMsg->DataB; // Transmission Request on TX Buffer 1 CAN1CMR = 0x21; return 1; } else if(status & 0x400) // Transmit buffer 2 released { //RTR, long or short ID & DLC CAN1TFI2 = sendMsg->Frame & 0xC00F0000; CAN1TID2 = sendMsg->canID; CAN1TDA2 = sendMsg->DataA; CAN1TDB2 = sendMsg->DataB; // Transmission Request on TX Buffer 2 CAN1CMR = 0x41; return 1; } else if(status & 0x40000) // Transmit buffer 3 released { //RTR, long or short ID & DLC CAN1TFI3 = sendMsg->Frame & 0xC00F0000; CAN1TID3 = sendMsg->canID; CAN1TDA3 = sendMsg->DataA; CAN1TDB3 = sendMsg->DataB; // Transmission Request on TX Buffer 3 CAN1CMR = 0x81; return 1; } else return 0; } else if(can == 0x02){ volatile unsigned status = CAN2SR; if(status & 0x04) // Transmit buffer 1 released { //RTR, long or short ID & DLC CAN2TFI1 = sendMsg->Frame & 0xC00F0000; CAN2TID1 = sendMsg->canID; CAN2TDA1 = sendMsg->DataA; CAN2TDB1 = sendMsg->DataB; // Transmission Request on TX Buffer 1 CAN2CMR = 0x21; return 1; } else if(status & 0x400) // Transmit buffer 2 released { //RTR, long or short ID & DLC CAN2TFI2 = sendMsg->Frame & 0xC00F0000; CAN2TID2 = sendMsg->canID; CAN2TDA2 = sendMsg->DataA; CAN2TDB2 = sendMsg->DataB; // Transmission Request on TX Buffer 2 CAN2CMR = 0x41; return 1; } else if(status & 0x40000) // Transmit buffer 3 released { //RTR, long or short ID & DLC CAN2TFI3 = sendMsg->Frame & 0xC00F0000; CAN2TID3 = sendMsg->canID; CAN2TDA3 = sendMsg->DataA; CAN2TDB3 = sendMsg->DataB; // Transmission Request on TX Buffer 3 CAN2CMR = 0x81; return 1; } else return 0; } return 0; }
If somenone could help me I will be very thankfull!
Thanks Genji
That couldn't be the problem, because it's already by the first pass-through that it happens. I can't even send one single message. So the error counter can't have a value other than 0 or 1 and it resets by a value much higher than that by default (forgot the correct value at this time).
Electrical problem resulting in the transmitter failing because of the error counter?
View all questions in Keil forum