You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
voidSTM32_CAN::calculateBaudrate(CAN_HandleTypeDef *CanHandle, int baud)
684
684
{
685
-
/* this function calculates the needed Sync Jump Width, Time segments 1 and 2 and prescaler values based on the set baud rate and APB1 clock.
686
-
This could be done faster if needed by calculating these values beforehand and just using fixed values from table.
687
-
The function has been optimized to give values that have sample-point between 75-94%. If some other sample-point percentage is needed, this needs to be adjusted.
688
-
More info about this topic here: http://www.bittiming.can-wiki.info/
689
-
*/
690
-
int sjw = 1;
691
-
int bs1 = 5; // optimization. bs1 smaller than 5 does give too small sample-point percentages.
692
-
int bs2 = 1;
693
-
int prescaler = 1;
694
-
695
-
uint32_t frequency = getAPB1Clock();
685
+
uint8_t bs1;
686
+
uint8_t bs2;
687
+
uint16_t prescaler;
688
+
689
+
constuint32_t frequency = getAPB1Clock();
696
690
697
691
if (frequency == 48000000) {
698
692
if (lookupBaudrate(CanHandle, baud, BAUD_RATE_TABLE_48M)) return;
699
693
} elseif (frequency == 45000000) {
700
694
if (lookupBaudrate(CanHandle, baud, BAUD_RATE_TABLE_45M)) return;
701
695
}
702
696
703
-
while (sjw <= 4) {
704
-
while (prescaler <= 1024) {
705
-
while (bs2 <= 3) { // Time segment 2 can get up to 8, but that causes too small sample-point percentages, so this is limited to 3.
706
-
while (bs1 <= 15) { // Time segment 1 can get up to 16, but that causes too big sample-point percenages, so this is limited to 15.
0 commit comments