Skip to content

Commit

Permalink
Corrected extended identifier bug
Browse files Browse the repository at this point in the history
  • Loading branch information
pierremolinaro committed Jan 6, 2019
1 parent a9b4830 commit 7e55d6e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 6 deletions.
Binary file modified extras/acan2517FD.pdf
Binary file not shown.
4 changes: 2 additions & 2 deletions library.properties
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
name=ACAN2517FD
version=1.0.2
version=1.0.3
author=Pierre Molinaro
maintainer=Pierre Molinaro <[email protected]>
sentence=Driver for MCP2517FD CAN Controller (CAN FD mode)
paragraph=This library is an Arduino CAN network driver for the MCP2517FD CAN Controller, in CAN FD mode. Compatible with ACAN, ACAN2515, ACAN2517 libraries. Default configuration sends and receives any frame – no default filter to provide. Reception filters (up to 32) can be easily defined.
paragraph=This library is an Arduino CAN network driver for the MCP2517FD CAN Controller, in CAN FD mode. Compatible with ACAN, ACAN2515, ACAN2515Tiny, ACAN2517 libraries. Default configuration sends and receives any frame – no default filter to provide. Reception filters (up to 32) can be easily defined.
category=Communication
url=https://github.com/pierremolinaro/acan2517FD
architectures=*
21 changes: 17 additions & 4 deletions src/ACAN2517FD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -495,8 +495,12 @@ void ACAN2517FD::appendInControllerTxFIFO (const CANFDMessage & inMessage) {
const uint16_t ramAddress = (uint16_t) (0x400 + readRegisterSPI (C1FIFOUA_REGISTER (2))) ;
assertCS () ;
writeCommandSPI (ramAddress) ;
//--- Write identifier (see DS20005678A, page 27)
writeWordSPI (inMessage.id) ;
//--- Write identifier: if an extended frame is sent, identifier bits sould be reordered (see DS20005678B, page 27)
uint32_t idf = inMessage.id ;
if (inMessage.ext) {
idf = ((inMessage.id >> 18) & 0x7FF) | ((inMessage.id & 0x3FFFF) << 11) ;
}
writeWordSPI (idf) ;
//--- Write DLC, RTR, IDE bits
uint32_t data = lengthCodeForLength (inMessage.len) ;
if (inMessage.rtr) {
Expand Down Expand Up @@ -529,8 +533,12 @@ bool ACAN2517FD::sendViaTXQ (const CANFDMessage & inMessage) {
const uint16_t ramAddress = (uint16_t) (0x400 + readRegisterSPI (C1TXQUA_REGISTER)) ;
assertCS () ;
writeCommandSPI (ramAddress) ;
//--- Write identifier (see DS20005678A, page 34)
writeWordSPI (inMessage.id) ;
//--- Write identifier: if an extended frame is sent, identifier bits sould be reordered (see DS20005678B, page 27)
uint32_t idf = inMessage.id ;
if (inMessage.ext) {
idf = ((inMessage.id >> 18) & 0x7FF) | ((inMessage.id & 0x3FFFF) << 11) ;
}
writeWordSPI (idf) ;
//--- Write DLC, RTR, IDE bits
uint32_t data = lengthCodeForLength (inMessage.len) ;
if (inMessage.rtr) {
Expand Down Expand Up @@ -660,6 +668,11 @@ void ACAN2517FD::receiveInterrupt (void) {
message.data32 [i] = readWordSPI () ;
}
deassertCS () ;
//--- If an extended frame is received, identifier bits sould be reordered (see DS20005678B, page 42)
if (message.ext) {
const uint32_t tempID = message.id ;
message.id = ((tempID >> 11) & 0x3FFFF) | ((tempID & 0x7FF) << 18) ;
}
//--- Append message to driver receive FIFO
mDriverReceiveBuffer.append (message) ;
//--- Increment FIFO
Expand Down

0 comments on commit 7e55d6e

Please sign in to comment.