autowp / arduino-mcp2515

Arduino MCP2515 CAN interface library
MIT License
795 stars 279 forks source link

Sending messages cannot be updated #88

Closed hanlu1215 closed 1 year ago

hanlu1215 commented 1 year ago

In the send example, if each time the message to be sent is updated in a loop, it is found that the update cannot be completed, and the CAN bus is always the first third message

hanlu1215 commented 1 year ago

Thank you very much


发件人: HarveyBates5B @.> 发送时间: 2023年3月27日 7:43 收件人: autowp/arduino-mcp2515 @.> 抄送: hanlu1215 @.>; Author @.> 主题: Re: [autowp/arduino-mcp2515] Sending messages cannot be updated (Issue #88)

Ended up modifying the sendMessage() method to reset the TX CTRL registers if all the buffers are full. Don't know what the implications are so if someone who knows more about this could help that would be greatly appreciated.

This is my sendMessage() method now, be aware its recursive.

MCP2515::ERROR MCP2515::sendMessage(const struct can_frame *frame) {

if (frame->can_dlc > CAN_MAX_DLEN) {
    return ERROR_FAILTX;
}

TXBn txBuffers[N_TXBUFFERS] = {TXB0, TXB1, TXB2};

for (auto & txBuffer : txBuffers) {
    const struct TXBn_REGS *txbuf = &TXB[txBuffer];
    uint8_t ctrlval = readRegister(txbuf->CTRL);
    if ( (ctrlval & TXB_TXREQ) == 0 ) {
        return sendMessage(txBuffer, frame);
    }
}

uint8_t zeros[14]{};
setRegisters(MCP_TXB0CTRL, zeros, 14);
setRegisters(MCP_TXB1CTRL, zeros, 14);
setRegisters(MCP_TXB2CTRL, zeros, 14);

return sendMessage(frame);

}

― Reply to this email directly, view it on GitHubhttps://jpn01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fautowp%2Farduino-mcp2515%2Fissues%2F88%23issuecomment-1484247342&data=05%7C01%7C%7C40f34add17c642b254dc08db2e4b8aa6%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638154674225558698%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=%2B6dElqo1PDCCXH7mRs0%2B2Tkpzq0dySBTmiqCglg1ewQ%3D&reserved=0, or unsubscribehttps://jpn01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fnotifications%2Funsubscribe-auth%2FAMHIBNZSK4P7SUNK74LONILW6DBBTANCNFSM6AAAAAAWGNMS5I&data=05%7C01%7C%7C40f34add17c642b254dc08db2e4b8aa6%7C84df9e7fe9f640afb435aaaaaaaaaaaa%7C1%7C0%7C638154674225558698%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=AYN43Oy0r2o1qbPnznfy1%2FbEWkloPrDsgaWJ852N57I%3D&reserved=0. You are receiving this because you authored the thread.Message ID: @.***>