I am trying to communicate between two LPC2129 microcontrollers, one as transmitter and the other as receiver, using interrupts to transmit and receive the message.

The transmit and receive interrupts are occurring in simulation, but the same is not working on the MCUs. But the other interrupts, like bus error and passive error are occurring.

And if I call the receive function in this ISR the message will receive once, and after that device is going to passive mode.

Issue: Even though I have separate ISRs for transmission and reception, it's not getting executed on the MCU, BUT the other CAN interrupt's ISR is executing.

The code is as follows please help.

CAN initialization:

PINSEL1 |= (DWORD) 0x00054000;
C2MOD = 1; // Enter Reset Mode
C2GSR = 0; // Clear status register
C2BTR = 0x001C001D; // Set bit timing
C2IER = 0x000007FF;
AFMR  = 0x00000001; // Enable recieve acceptance filter
C2MOD = 0; // Enter normal operating mode

VICIntEnable |= 0x08280000; //Enable interrupts
VICVectCntl0 = 0x00000033; //Select a priority slot for a given interrupt
VICVectAddr0 = (unsigned)CAN2_ISR; //Pass the address of the IRQ

VICVectCntl1 = 0x0000003B; //Select a priority slot for a given interrupt
VICVectAddr1 = (unsigned)CAN2_Rx_ISR; //Pass the address of the IRQ

VICVectCntl2 = 0x00000035; //Select a priority slot for a given interrupt
VICVectAddr2 = (unsigned)CAN2_Tx_ISR; //Pass the address of the IRQ

AFMR = 0x00000001; //Disable the acceptance filters

Transmit function:

void Tx_Frame(unsigned int ID, unsigned long LSB_4, unsigned long MSB_4, unsigned char LEN, char RTR_FF)
    while ( (C2SR & 0x00000004) != 0x00000004)
        ; // Checking that the TX buffer is empty

    C2TFI1 |= (LEN << 16);    // Frame information (RTR=0, 11 bit identifier. And length is setting)
    C2TFI1 |= (RTR_FF << 30);
    C2TDA1 = LSB_4;           // Data A
    C2TDB1 = MSB_4;           // Data B
    C2TID1 = ID;              // 11 bit ID or 29 bit
    C2CMR = 0x21;             // Command: Transmit previously written message through TX buffer 1.

Receive function:

void Rx_Frame(void)
    LEN = C2RFS;
    ID = C2RID;
    DATA_A = C2RDA;
    DATA_B = C2RDB;

    C2CMR = 0x04;  // Release receive buffer command
  • \$\begingroup\$ Smells like CAN bus hardware error. How is you CAN bus wired, which tranceivers do you use? \$\endgroup\$ – Turbo J Jun 21 '14 at 15:25
  • \$\begingroup\$ using MCP2551 Transceiver and connected as follows MCU RD2 to MCP2551 Rx, MCU TD2 to MCP2551 Tx. And for bus connection: CANH of one MCP2551 is connected to CANH on Another MCP 2551 directly through a wire and same way for CANL also. \$\endgroup\$ – Raghu T C Jun 23 '14 at 4:26
  • \$\begingroup\$ Can you connect CANalyzer on the bus and see what's going on?? I hope baud rate of both nodes is same! \$\endgroup\$ – Swanand Jul 9 '14 at 8:12

CAN requires the two termination resistors, 120 \$\Omega\$ each, to be present. The bus will not leave error state otherwise, and you get only error interrupts.

  • \$\begingroup\$ i am using 120 ohm resistor on each side but i am getting ACK slot error continuously from transmitter. i have directly connected two MCp2551 modules like CANH-CANH and CANL-CANL. please suggest how to eliminate this ACK slot error \$\endgroup\$ – Raghu T C Jun 24 '14 at 9:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.