Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a TXBnCTRL bit checker before sending the next CAN frame #54

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/MCP2515/MCP2515_Control.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint8_t>(len, 8));

/* Wait until 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)
Expand Down
1 change: 1 addition & 0 deletions src/MCP2515/MCP2515_Control.h
Original file line number Diff line number Diff line change
Expand Up @@ -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(); }
Expand Down