Skip to main content
NewEpisode 3a is out: Carry the conversation onWatch →

This part is for members

Membership opens soon. Leave your email and we'll tell you the day it does. Founding members get the launch price.

Keep watching the free parts
Data & comms · 30a

CAN 1: one write, two front doors

CAN, part one: in 25a a bench called the write callback directly; here 0x607A = 262,144 really comes in over the CAN wire, through the board's own CAN code. It opens with the whole episode on one framework page: the build target picks the front door, both doors lead down one hallway to set_app_Target_position, and what the master hears back depends on the door and on every layer passing the answer up. The page: the two doors (each one's frame) on the left, the shared hallway in the middle, the replies and a table of real runs on the right. The bench, sil-mac/ep30: drv_can_app.c and bsp_fdcan.c copied unchanged onto a bench HAL, CANFestival built from the Keil project's file list, the master's frames written byte by byte by frames.py, every frame in and out recorded; one build per protocol. Seven stops: which door (the Keil project has six targets: the base target and the virtual-motor target leave MINOR_VERSION unset → version.h's default 0, plain CAN + CiA402; YH_CANOPEN and its release target set 2, CANopen; two more are EtherCAT → episode 31; the #if in fdcan_app_fifo0_handle compiles in one door only); the frame on the wire (node 0x15; CANopen 0x615: 23 7A 60 00 00 00 04 00, 0x23 = expedited download of four bytes; plain CAN 0x015: 01 7A 60 00 00 00 04 00; the peripheral's filters: CANopen keeps only 0x000, 0x080 and IDs whose low seven bits are 0x15, plain CAN keeps everything); the plain CAN door (fdcan_cia402_handle, one function: check the ID, at least five bytes, direction, index, subindex, the value by length, then master_cia402_write_callback, whose return it never reads); the CANopen door (fdcan_canopen_hendle → canDispatch (0x615 >> 7 = 12) → proceedSDO → SDOlineToObjdict → _setODentry; scanIndexOD clears two global hooks, then for any index from 0x2000 up points them at servohub's callbacks, so the value never lands in the stack's own 0x607A variable; the return value travels back up); the hallway (authority check → switch on the index → the 0x607A callback → set_Target_position → set_app_Target_position, which checks the limits and stores the target); the reply (CANopen answers on 0x595 with 60 7A 60 00 00 00 00 00; plain CAN queues its reply with the tx_can header, whose ID only bsp_fdcan_set_id ever set and whose length stays 0: ten writes and reads, ten empty frames); the motor moves (controlword 0x1F 5 ms later; target reached 316.2 ms after the edge, as in 25a; the two doors' runs identical value for value); reading back (0x6064: CANopen answers 43 64 60 00 FF FF 03 00 = 262,143; plain CAN computes 262,143 and sends zero bytes, so on the base target a master can write but never read back; the fix branch fix/can-cia402-reply-length sends the reply through bsp_can_send_message: 00 64 60 00 FF FF 03 00, the motion byte for byte the same). Then a write the drive refuses: 0x607D:2 = 200,000 before the enable (after it, refused with 0x08000022), then 262,144: set_app_Target_position returns 2, the target stays 0, the motor never moves, the statusword reports target reached, 0x1637, and both doors say success, because set_Target_position ignores the 2; 25a's fix branch makes CANopen answer 80 7A 60 00 31 00 09 06 (0x06090031, value too high); plain CAN's reply has no status byte, so even both fixes can't say so (read from the code). With the host holding control authority (MAVLink → episode 32), every bus write is refused before the switch with 0x08000022; CANopen answers 80 7A 60 00 22 00 00 08. Not covered: PDOs and SYNC, and what happens when the master goes quiet → 30b; segmented SDOs, emergency frames, node management are not in this course; EtherCAT → episode 31. Your turn: read 0x6041 after the move: CANopen answers 4B 41 60 00 37 16 00 00, plain CAN (fix branch) 00 41 60 00 37 16 00 00.

Up next30b · CAN 2: PDOs and SYNC, the path every cycle takes→