Skip to content

Commit 4a002de

Browse 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

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Diff for: libraries/Arduino_CAN/examples/CANWrite/CANWrite.ino

+1-1
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.

Diff for: libraries/Arduino_CAN/src/Arduino_CAN.cpp

+7-3
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)