From cf888335a562891041e13fb7a655b7d710a01dc5 Mon Sep 17 00:00:00 2001 From: Pepe Date: Thu, 27 Jan 2022 11:35:04 +0000 Subject: [PATCH 1/2] Added a TXBnCTRL bit checker before sending the next CAN frame --- src/MCP2515/MCP2515_Control.cpp | 15 +++++++++++++++ src/MCP2515/MCP2515_Control.h | 1 + 2 files changed, 16 insertions(+) diff --git a/src/MCP2515/MCP2515_Control.cpp b/src/MCP2515/MCP2515_Control.cpp index 987d8ec..f32b02b 100644 --- a/src/MCP2515/MCP2515_Control.cpp +++ b/src/MCP2515/MCP2515_Control.cpp @@ -68,11 +68,26 @@ void MCP2515_Control::transmit(TxB const txb, uint32_t const id, uint8_t const * /* Load data buffer */ memcpy(tx_buffer.reg.data, data, std::min(len, 8)); + /* Wait untill all the TX buffers are empty */ + while(txbnctrl_peek()>0) + { + __asm__("nop\n\t"); + } + /* Write to transmit buffer */ _io.loadTxBuffer(txb, tx_buffer.buf); /* Request transmission */ _io.requestTx(txb); + +} + +uint8_t MCP2515_Control::txbnctrl_peek() +{ + if(0x8&&_io.readRegister(Register::TXB0CTRL)) return 1; + if(0x8&&_io.readRegister(Register::TXB1CTRL)) return 2; + if(0x8&&_io.readRegister(Register::TXB2CTRL)) return 3; + return 0; } void MCP2515_Control::receive(RxB const rxb, uint32_t & id, uint8_t * data, uint8_t & len) diff --git a/src/MCP2515/MCP2515_Control.h b/src/MCP2515/MCP2515_Control.h index 852ba6b..b8b65ed 100644 --- a/src/MCP2515/MCP2515_Control.h +++ b/src/MCP2515/MCP2515_Control.h @@ -35,6 +35,7 @@ class MCP2515_Control void transmit (TxB const txb, uint32_t const id, uint8_t const * data, uint8_t const len); void receive (RxB const rxb, uint32_t & id, uint8_t * data, uint8_t & len); + uint8_t txbnctrl_peek(); inline void reset () { _io.reset(); } inline uint8_t status () { return _io.status(); } From 4f05864d3d8b628841dbee00ed1ceef99d45756c Mon Sep 17 00:00:00 2001 From: Pepe Date: Thu, 27 Jan 2022 11:49:16 +0000 Subject: [PATCH 2/2] Fixed spell check typo --- src/MCP2515/MCP2515_Control.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/MCP2515/MCP2515_Control.cpp b/src/MCP2515/MCP2515_Control.cpp index f32b02b..fd5540e 100644 --- a/src/MCP2515/MCP2515_Control.cpp +++ b/src/MCP2515/MCP2515_Control.cpp @@ -68,7 +68,7 @@ void MCP2515_Control::transmit(TxB const txb, uint32_t const id, uint8_t const * /* Load data buffer */ memcpy(tx_buffer.reg.data, data, std::min(len, 8)); - /* Wait untill all the TX buffers are empty */ + /* Wait until all the TX buffers are empty */ while(txbnctrl_peek()>0) { __asm__("nop\n\t");