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

add autoretransmit disable option #3

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion st-f4can/include/can.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ extern void CANSetFilter(uint8_t index, uint8_t scale, uint8_t mode, uint8_t fif
* =2: CAN2_RX mapped to PB12, CAN2_TX mapped to PB13
*
* =3: CAN2_RX mapped to PB12, CAN2_TX mapped to PB13
*
* @param automaticRetransmission - allow automatic retransmission to be disabled
*
*/
extern bool CANInit(BITRATE bitrate, int _CAN1, int _CAN2);
extern bool CANInit(BITRATE bitrate, int _CAN1, int _CAN2, bool automaticRetransmission = true);

/**
* Decodes CAN messages from the data registers and populates a
Expand Down
16 changes: 9 additions & 7 deletions st-f4can/src/can.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ void CANSetFilter(uint8_t index, uint8_t scale, uint8_t mode, uint8_t fifo, uint
}


bool CANInit(BITRATE bitrate, int _CAN1, int _CAN2)
bool CANInit(BITRATE bitrate, int _CAN1, int _CAN2, bool automaticRetransmission)
{
// Reference manual
// https://www.st.com/content/ccc/resource/technical/document/reference_manual/4d/ed/bc/89/b5/70/40/dc/DM00135183.pdf/files/DM00135183.pdf/jcr:content/translations/en.DM00135183.pdf
Expand Down Expand Up @@ -157,12 +157,14 @@ bool CANInit(BITRATE bitrate, int _CAN1, int _CAN2)
CAN2->MCR |= 0x1UL; // Require CAN2 to Initialization mode
while (!(CAN2->MSR & 0x1UL)); // Wait for Initialization mode
//printRegister("CAN2->MCR=", CAN2->MCR);

//CAN1->MCR = 0x51UL; // Hardware initialization(No automatic retransmission)
CAN1->MCR = 0x41UL; // Hardware initialization(With automatic retransmission)

//CAN2->MCR = 0x51UL; // Hardware initialization(No automatic retransmission)
CAN2->MCR = 0x41UL; // Hardware initialization(With automatic retransmission)
if(automaticRetransmission){
CAN1->MCR = 0x41UL; // Hardware initialization(With automatic retransmission)
CAN2->MCR = 0x41UL; // Hardware initialization(With automatic retransmission)
}
else{
CAN1->MCR = 0x51UL; // Hardware initialization(No automatic retransmission)
CAN2->MCR = 0x51UL; // Hardware initialization(No automatic retransmission)
}


// Set bit rates
Expand Down