MCP2515 CAN bus controller question
2011-08-29 by Chuck Hackett
Some configuration info:
- 5 nodes (ATMega32 and MCP2515 on each)
- Communicating over a short CAT-5 network
- About 1.5 feet of CAT-5 between each node
- Terminated on both ends with 120 ohm resistor
- ATMega clock 14.7456Mhz xtal
- MCP2515 clock (Osc1) fed from ATMega32 timer @ 3.703 Mhz
- MCP2515 Settings:
- BRP = 5, PropSeg = 3, PS1 = 8, PS2 = 8 (calc'd bus rate -> 18.432
bps, scope shows this is correct)
- "Normal" mode
- RXM -> (00 = Rcv all *valid* messages that meet filter criteria)
- Error interrupts not enabled
This setup mostly works but I am chasing a couple of bugs. One is very
intermittent and *seems* to indicate that the data portion of a message was
either built incorrectly by the application code the sending node or the
MCP2515 in the receiving node accepted a message that failed checksum
validation.
My understanding is that using an RXM value of 00 indicates that only
'valid' messages are to be received and that I would not get a rcv data
interrupt (or Rcv buffer full indication) for either rcv buffer if the
message failed CRC validation ... correct?
When a Rvc interrupt occurs I (psudocode):
While ICOD (in CANSTAT) != 0
{
Switch(ICOD)
{
Case Error Status:
Read EFLG register, accumulate counts
Clear ERRIF in CANINTF
Case Wakeup:
Ignore and clear WAKIF in CANINTF
Case TXBx
Ignore and clear TXnIF in CANINTF
Case RXB0
Read buffer 0
queue msg for background processing
Clear RX0IF in CANINTF
Case RXB1
Read buffer 1
queue msg for background processing
Clear RX1IF in CANINTF
}
}
Return from interrupt.
Any problems with that sequence?
(BTW: Rcv is interrupt driven but the xmit side is not interrupt driven.
For xmit I do "busy waiting" in in background for a free MCP2515 xmit buffer
rather than handling xmit buffer empty interrupts)
Cheers,
Chuck Hackett
"Good judgment comes from experience, experience comes from bad judgment"
7.5" gauge Union Pacific Northern (4-8-4) 844
http://www.whitetrout.net/Chuck