I notice due_can declares a variable in which to hold RTR, but that variable is never populated.
This bug exists in (as far as I can tell) every version of the library.
I have patched the (6 month old) version of the library (as linked from the M2 Git repo), but it is not obvious how to properly fork/pullRq/submit the patch …So. If you want to know if a CAN device is requesting data, here’s the patch:
-
Open
C:\Users\YourUserName\AppData\Local\Arduino15\packages\macchina\hardware\sam\0.2.1\libraries\due_can\due_can.cpp
…If you’re not using Windows - you’re just going to have to go hunting for that file - sorry. -
Search for the string “fid” [Family ID] …there’s only one occurence of this string in this file:
rxframe->fid = m_pCan->CAN_MB[uc_index].CAN_MFID;
-
Just after/before/near ^that^, line add this line:
rxframe->rtr = (m_pCan->CAN_MB[uc_index].CAN_MSR & CAN_MSR_MRTR) ? 1 : 0 ;
-
That’s it, you can now identify Remote Transmit Request packets with something like:
if (frame.rtr) rtrHandler(frame) ;
-
If you like diff files, enjoy this:
--- C:\original\due_can.cpp 2018-03-03 15:35:22.000000000 -0000
+++ C:\rtr_fix\due_can.cpp 2018-03-03 15:38:02.000000000 -0000
@@ -1026,12 +1026,13 @@
rxframe->id = (ul_id >> CAN_MID_MIDvA_Pos) & 0x7ffu;
rxframe->extended = false;
}
rxframe->fid = m_pCan->CAN_MB[uc_index].CAN_MFID;
rxframe->length = (ul_status & CAN_MSR_MDLC_Msk) >> CAN_MSR_MDLC_Pos;
rxframe->time = (ul_status & CAN_MSR_MTIMESTAMP_Msk);
+ rxframe->rtr = (m_pCan->CAN_MB[uc_index].CAN_MSR & CAN_MSR_MRTR) ? 1 : 0;
ul_datal = m_pCan->CAN_MB[uc_index].CAN_MDL;
ul_datah = m_pCan->CAN_MB[uc_index].CAN_MDH;
rxframe->data.high = ul_datah;
rxframe->data.low = ul_datal;```