The original code reads address 0x31, 0x41, or 0x51 "TXBnSIDH – TRANSMIT
BUFFER n STANDARD IDENTIFIER HIGH". Because that location points to a
constant value, some of the msg ids cause the program to loop 50 times
and then report a timeout error. After changing the address to point to
0x30, 0x40, or 0x50 "TXBnCTRL – TRANSMIT BUFFER n CONTROL REGISTER", all
of the messages send out properally with no timeout errors.
not clearing m_nRtr until next data frame without request bit is
received. This lead to sending out all frames in between with
request bit set aswell. Fixed by extending sendMsgBuf to
INT8U sendMsgBuf(INT32U id, INT8U ext, INT8U rtr, INT8U len, INT8U *buf)
and setMsg to
INT8U setMsg(INT32U id, INT8U ext, INT8U len, INT8U rtr, INT8U *pData)
giving the possibillity to specify if request bit is set or not when
sending a message.
Feature: New function INT8U MCP_CAN::isRemoteRequest(void) added
to make it possible to check if the remote request bit was set on
the last received message.
- Added: buffer limit in mcp2515_readRegisterS
- Added: return code check in readMsgBuf
- Added: function readMsgBufID to read message and object id in a single phase
There was an error in the bit arithmatic for the can id.
Basically, if the 15th bit of the id was set, then the upper 16bits were 1 less than they should be.
e.g. 0x0001(8-F)XXX -> 0x0000(8-F)XXX
e.g. 0x0000(8-F)XXX -> 0xFFFF(8-F)XXX
The offending operation is (tbufdata[MCP_EID8]<<8). This promotes an unsigned char to a signed int, which results in the corrupted ids. The fix is to cast it to an unsigned int. Note that int's are 16 bit on avr.
It took me a while to figure this out, but the SPICS pin is not necessarily initialized to output when the arduino starts. Explicitly making it an output in the begin() method saves the library user from having to set the pin as output in their code (which they may not know they need to do, since it is not in the example code).