Skip to content

Commit

Permalink
Fix: Determine if CAN TX is ongoing by reading from the TXBnCTRL regi…
Browse files Browse the repository at this point in the history
…ster. (#55)
  • Loading branch information
aentinger authored Jan 31, 2022
1 parent 3cdceb5 commit 57e8ae8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
10 changes: 5 additions & 5 deletions src/ArduinoMCP2515.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,19 +122,19 @@ void ArduinoMCP2515::onExternalEventHandler()

bool ArduinoMCP2515::transmitCANFrame(uint32_t const id, uint8_t const * data, uint8_t const len)
{
uint8_t const status = _ctrl.status();

if (isBitClr(status, bp(STATUS::TX0REQ)))
if (isBitClr(_io.readRegister(Register::TXB0CTRL), bp(TXBnCTRL::TXREQ)))
{
_ctrl.transmit(TxB::TxB0, id, data, len);
return true;
}
else if (isBitClr(status, bp(STATUS::TX1REQ)))

if (isBitClr(_io.readRegister(Register::TXB1CTRL), bp(TXBnCTRL::TXREQ)))
{
_ctrl.transmit(TxB::TxB1, id, data, len);
return true;
}
else if (isBitClr(status, bp(STATUS::TX2REQ)))

if (isBitClr(_io.readRegister(Register::TXB2CTRL), bp(TXBnCTRL::TXREQ)))
{
_ctrl.transmit(TxB::TxB2, id, data, len);
return true;
Expand Down
5 changes: 5 additions & 0 deletions src/MCP2515/MCP2515_Const.h
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ enum class CANSTAT : uint8_t
OPMOD0 = 5
};

enum class TXBnCTRL : uint8_t
{
TXREQ = 3,
};

/**************************************************************************************
* CONVERSION FUNCTIONS
**************************************************************************************/
Expand Down

0 comments on commit 57e8ae8

Please sign in to comment.