I am trying to get a CAN bus sniffer working, based on LPC2368. I keep getting a bus error interrupt, of type "form error". I suspect my timing settings. I verified that the sending party is transmitting at 125 kbit/s (8 μs bit duration). Here is my setting for a 72 MHz CPU clock and 125 kbit/s bus speed:
#define PULSE_BEFORE_SAMPLE 8
#define PULSE_AFTER_SAMPLE 3
#define PULSE_PER_BIT (PULSE_BEFORE_SAMPLE + PULSE_AFTER_SAMPLE + 1)
#define TSEG1 (PULSE_BEFORE_SAMPLE - 1)
#define TSEG2 (PULSE_AFTER_SAMPLE - 1)
#define SJW 3 //sync jump width
#define SAM 0 //sampling 0=single sample 1=triple sample
#define CAN_PRESCALER 7 //((CPU_CLK_HZ / PCLK_DIVIDER / CAN1_BAUDRATE / PULSE_PER_BIT) - 1 )
...
PCLKSEL0 |= PCLK_CAN1 << 26; //clock source = CCLK/6
...
CAN1BTR = (CAN_PRESCALER | (SJW << 14) | (TSEG1 << 16) | (TSEG2 << 20) | (SAM << 23));
Am I making an obvious mistake here? The controller is running in listen-only mode, all other mode bits are set to 0.