Skip to content
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
2 changes: 2 additions & 0 deletions inc/can.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ enum can_bitrate
CAN_BITRATE_500K,
CAN_BITRATE_800K,
CAN_BITRATE_1000K,
CAN_BITRATE_83K,
Comment thread
Nakakiyo092 marked this conversation as resolved.
CAN_BITRATE_666K,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The SA option for 666 kbps is harder to accept.
I have never seen any slcan implementation that natively supports this bitrate.
In addition, there is a repository where SA is used for another purpose: "Set the nominal bit rate to 75k"
I’m not convinced it’s worth introducing, considering the confusion it will cause in the protocol.


CAN_BITRATE_INVALID,
};
Expand Down
14 changes: 14 additions & 0 deletions src/can.c
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,8 @@ HAL_StatusTypeDef can_set_bitrate(enum can_bitrate bitrate)
return HAL_ERROR;
}

// peripheral clock speed 160M

// Set default bitrate 125k
can_bitrate_nominal.prescaler = 16;
can_bitrate_nominal.sjw = 8;
Expand All @@ -377,6 +379,12 @@ HAL_StatusTypeDef can_set_bitrate(enum can_bitrate bitrate)
case CAN_BITRATE_50K:
can_bitrate_nominal.prescaler = 40;
break;
case CAN_BITRATE_83K:
can_bitrate_nominal.prescaler = 120;
can_bitrate_nominal.sjw = 2;
can_bitrate_nominal.time_seg1 = 13;
can_bitrate_nominal.time_seg2 = 2;
break;
case CAN_BITRATE_100K:
can_bitrate_nominal.prescaler = 20;
break;
Expand All @@ -388,6 +396,12 @@ HAL_StatusTypeDef can_set_bitrate(enum can_bitrate bitrate)
case CAN_BITRATE_500K:
can_bitrate_nominal.prescaler = 4;
break;
case CAN_BITRATE_666K:
can_bitrate_nominal.prescaler = 30;
can_bitrate_nominal.sjw = 1;
can_bitrate_nominal.time_seg1 = 6;
can_bitrate_nominal.time_seg2 = 1;
break;
case CAN_BITRATE_800K:
can_bitrate_nominal.prescaler = 2;
can_bitrate_nominal.sjw = 10;
Expand Down