pybricks / technical-info

Detailed technical info for Pybricks hackers

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

BYTE_SYNC for EV3 sensors

JakubVanek opened this issue · comments

Hi all,

I am currently digging deeper into the EV3 sensor protocol. During this, I have found a disagreement between the UART sensor documentation and what I can observe. In particular, the documentation states:

The [information about the device] sequence sent by the device is terminated by BYTE_ACK and BYTE_SYNC.

When I probe EV3 sensor UART lines with a logic analyzer, I can only observe the BYTE_ACK message and not the BYTE_SYNC:

Screenshot of a logic analyzer where the sensor and the brick exchange ACKs. No SYNC bytes are visible

The trace above is from the EV3 color sensor. However, I'm seeing a similar pattern from other devices too. I have tested the following sensors against the stock EV3 firmware 1.10E:

  • EV3 Ultrasonic sensor 50N3
  • EV3 Color sensor 47N3
  • EV3 Gyro sensor 49N3

I have not tested the IR sensor yet.

The documentation also disagrees with what I thought about the BYTE_SYNC message. Comments in earlier EV3 firmware revisions hint that this message was intended for achieving baud rate synchronization before the sensor info sequence (link). The reverse-engineered firmware of a 20N7 EV3 color sensor seems to confirm this (link; the SYNC code is located at the beginning of the sequence, yet actually it is never executed).

However, I cannot rule out that LEGO repurposed the message. Is it possible that the BYTE_SYNC part is new to SPIKE Prime sensors or that this appeared later during the EV3 lifetime?

Thank you,
Jakub

Which sensors have you analyzed? Sending only the ACK at the end is typical for the newer Powered Up UART devices.

The comments about BYTE_SYNC might have been inferred from the comments in the original LEGO source code, which is as you noted, not how things are actually implemented.

Happy to take a pull request to fix the docs. But I think we should have a look at all of the sensors, especially the EV3 IR sensor to make sure we aren't missing something.

I have only analyzed the EV3 gyro, ultrasonic and color sensors (and all of them quite old). I haven't checked any Powered Up sensors yet. I'm quite curious about the EV3 IR sensor too, as I have read about the checksum-after-SYNC bug. I will try to test one in the following days.

the checksum-after-SYNC bug

I suspect we will find that it is really checksum-after-ACK bug and I just had the terminology confused when I first started working on this 10 years ago. 😁