Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4a002de

Browse filesBrowse files
authored
Merge pull request #709 from arduino/fix-support-extended-and-standard
[Arduino_CAN] support both 11-Bit (standard) and 29-Bit (extended) IDs
2 parents d5d3713 + f2efce8 commit 4a002de
Copy full SHA for 4a002de

File tree

2 files changed

+8
-4
lines changed
Filter options

2 files changed

+8
-4
lines changed

‎libraries/Arduino_CAN/examples/CANWrite/CANWrite.ino

Copy file name to clipboardExpand all lines: libraries/Arduino_CAN/examples/CANWrite/CANWrite.ino
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ void loop()
3535
*/
3636
uint8_t const msg_data[] = {0xCA,0xFE,0,0,0,0,0,0};
3737
memcpy((void *)(msg_data + 4), &msg_cnt, sizeof(msg_cnt));
38-
CanMsg msg(CAN_ID, sizeof(msg_data), msg_data);
38+
CanMsg msg(CanStandardId(CAN_ID), sizeof(msg_data), msg_data);
3939

4040
/* Transmit the CAN message, capture and display an
4141
* error core in case of failure.

‎libraries/Arduino_CAN/src/Arduino_CAN.cpp

Copy file name to clipboardExpand all lines: libraries/Arduino_CAN/src/Arduino_CAN.cpp
+7-3Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,14 @@ void Arduino_CAN::end()
4848

4949
int Arduino_CAN::write(CanMsg const & msg)
5050
{
51+
bool const is_standard_id = msg.isStandardId();
52+
5153
mbed::CANMessage const can_msg(
52-
msg.id,
54+
is_standard_id ? msg.getStandardId() : msg.getExtendedId(),
5355
msg.data,
5456
msg.data_length,
5557
CANData,
56-
CANStandard);
58+
is_standard_id ? CANStandard : CANExtended);
5759

5860
return _can.write(can_msg);
5961
}
@@ -65,8 +67,10 @@ size_t Arduino_CAN::available()
6567

6668
if (msg_read)
6769
{
70+
bool const is_standard_id = (can_msg.format == CANStandard);
71+
6872
CanMsg const msg(
69-
can_msg.id,
73+
is_standard_id ? CanStandardId(can_msg.id) : CanExtendedId(can_msg.id),
7074
can_msg.len,
7175
can_msg.data);
7276

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.