2
\$\begingroup\$

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.

\$\endgroup\$
  • 1
    \$\begingroup\$ So, did you get this working? \$\endgroup\$ – BullBoyShoes Jan 15 '11 at 22:18
4
\$\begingroup\$

I've worked with the Microchip CAN controller with SPI bus interface, MCP2515. One of the most difficult parts of setting up CAN is making sure that all the baud rate registers are set properly for all of devices on the bus. I'm not sure if you have access to the registers on the sending device, but being able to read the exact baud rate register values from the sender may give you an idea as to which register you have configured incorrectly. Also knowing the type of error if any is being detected by the sender may help you solve your CAN bus problem.

Microchip has an application note, AN754, that provides a guide to setting the CAN bus timing. It's not specific to Microchip. There are a few basic timing parameters you must set properly in order for the CAN bus communication to work. They are:

  • Tq = Time Quanta
  • Nominal Bit Time
  • Synchronization segment width
  • Propagation segment width
  • Phase segment 1 width
  • Phase segment 2 width

Make sure these values all match in your sender and receiver.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Thanks for the wisdom but it is not helpful in this particular situation. The devices are different(LPC2368 and AVR-something ) so they need to be set up separately. \$\endgroup\$ – Atilla Filiz Dec 8 '10 at 8:17
2
\$\begingroup\$

The problem was about selecting the wrong pins. Case is closed.

|improve this answer|||||
\$\endgroup\$
  • \$\begingroup\$ Well, that would do it! +1 for admitting your mistake. \$\endgroup\$ – Erik May 10 '11 at 6:22

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.