# Communication Protocol

**URL:** <https://discourse.odriverobotics.com/t/communication-protocol/674>\
**Category:** General\
**Created:** [May 14, 2018, 6:36am UTC](https://discourse.odriverobotics.com/t/communication-protocol/674 "2018-05-14T06:36:09Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Owen](https://discourse.odriverobotics.com/letter_avatar_proxy/v4/letter/o/b2d939/32.png) [@Owen](https://discourse.odriverobotics.com/u/Owen)\
**Post date:** [May 14, 2018, 6:36am UTC](https://discourse.odriverobotics.com/t/communication-protocol/674/1 "2018-05-14T06:36:09Z")

</div>

What is the USB or UART communication protocol between the board and the PC? If I would like to design my own communication protocol, how can I modify the software?

---

<div class="post-metadata">

**Author:** ![madcowswe](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/madcowswe/32/1138_2.png) [@madcowswe](https://discourse.odriverobotics.com/u/madcowswe)\
**Post date:** [May 23, 2018, 7:21am UTC](https://discourse.odriverobotics.com/t/communication-protocol/674/2 "2018-05-23T07:21:22Z")

</div>

There are two available protocols. One designed for machine use, which we call the “native protocol”, and one designed to be human readable, which we call the “ascii protocol”. You can check the following for more info:

- Native protocol
  - [Documentation](https://docs.odriverobotics.com/ascii-protocol.html)
  - [Firmware Code](https://github.com/madcowswe/ODrive/blob/devel/Firmware/communication/protocol.cpp)
  - [Python Code](https://github.com/madcowswe/ODrive/blob/devel/tools/odrive/protocol.py)

- Ascii protocol
  - [Documentation](https://docs.odriverobotics.com/protocol)
  - [Firmware Code](https://github.com/madcowswe/ODrive/blob/devel/Firmware/communication/ascii_protocol.cpp)
  - [Arduino library](https://github.com/madcowswe/ODriveArduino/blob/master/ODriveArduino.cpp). Note that some of this is outdated as of today (we may update it soon).

---

<div class="post-metadata">

**Author:** ![Owen](https://discourse.odriverobotics.com/letter_avatar_proxy/v4/letter/o/b2d939/32.png) [@Owen](https://discourse.odriverobotics.com/u/Owen)\
**Post date:** [June 1, 2018, 6:24am UTC](https://discourse.odriverobotics.com/t/communication-protocol/674/3 "2018-06-01T06:24:39Z")

</div>

hi，How to use UART control, I have modified CONFIG\_UART\_PROTOCOL=native, connected GPIO1 and GPIO2 pins and GND. Is it connected to the PC via a USB to serial chip? If so, what command is executed on the git bash here terminal to start UART communication?

I would like to modify the UART protocol to apply to my control protocol and eventually control it via the bus, such as rs232 or rs485, using a simple check (non-CRC). Protocol.c is full of complex protocol processing and protocol.c file is an implementation of the processing used to receive and send data. Is the commands.c and legacy\_commands.c file to convert the transmitted data to commands?

---

<div class="post-metadata">

**Author:** ![madcowswe](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/madcowswe/32/1138_2.png) [@madcowswe](https://discourse.odriverobotics.com/u/madcowswe)\
**Post date:** [June 1, 2018, 8:49pm UTC](https://discourse.odriverobotics.com/t/communication-protocol/674/4 "2018-06-01T20:49:44Z")

</div>

> [@Owen](#):
>
> connected GPIO1 and GPIO2 pins and GND

What device did you connect here?

---

<div class="post-metadata">

**Author:** ![Owen](https://discourse.odriverobotics.com/letter_avatar_proxy/v4/letter/o/b2d939/32.png) [@Owen](https://discourse.odriverobotics.com/u/Owen)\
**Post date:** [June 3, 2018, 8:50am UTC](https://discourse.odriverobotics.com/t/communication-protocol/674/5 "2018-06-03T08:50:19Z")

</div>

I configured the CONFIG\_UART\_PROTOCOL to ASCII using the human readable protocol.Use the serial port tool on the PC to send the command p 0 -20000, but no response.Is there something wrong with my operation?

---

<div class="post-metadata">

**Author:** ![madcowswe](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/madcowswe/32/1138_2.png) [@madcowswe](https://discourse.odriverobotics.com/u/madcowswe)\
**Post date:** [June 11, 2018, 9:57am UTC](https://discourse.odriverobotics.com/t/communication-protocol/674/6 "2018-06-11T09:57:27Z")

</div>

Split this topic on June 11, 2018, 9:57am UTC

4 posts were split to a new topic: [Where did the Arduino lib go?](https://discourse.odriverobotics.com/t/where-did-the-arduino-lib-go/757)

---

<div class="post-metadata">

**Author:** ![W\_D](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/w_d/32/2013_2.png) [@W\_D](https://discourse.odriverobotics.com/u/W_D)\
**Post date:** [August 31, 2019, 5:29pm UTC](https://discourse.odriverobotics.com/t/communication-protocol/674/9 "2019-08-31T17:29:45Z")

</div>

Can somebody get me started on the native protocol, please. I believe to understand all, just worried about the details, CRC in particular.

Let’s say I am in message #2 and want to read the battery voltage. I would send:

`0x02 0x00 0x01 0x00 0x04 0x00 0x?? 0x??`

Little endian, meaning msg id 0x0002 is sent as 0x02 0x00, endpoint is 0x0001, expected result is a float, hence 0x0004 bytes long, payload does not exist and the last two bytes are the CRC. But how are they calculated?

The protocol.hpp talks about different algorithms and does not tell what all is included. I assume it starts with the first byte and includes everything except the last two bytes, the CRC to compare with?

> <https://github.com/madcowswe/ODrive/blob/master/Firmware/fibre/cpp/include/fibre/protocol.hpp>

---

<div class="post-metadata">

**Author:** ![W\_D](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/w_d/32/2013_2.png) [@W\_D](https://discourse.odriverobotics.com/u/W_D)\
**Post date:** [September 2, 2019, 8:00am UTC](https://discourse.odriverobotics.com/t/communication-protocol/674/10 "2019-09-02T08:00:00Z")

</div>

Anybody, please? Just a little hint to get me running…

---

<div class="post-metadata">

**Author:** ![PrimeEuler](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/primeeuler/32/1813_2.png) [@PrimeEuler](https://discourse.odriverobotics.com/u/PrimeEuler)\
**Post date:** [September 5, 2019, 9:10pm UTC](https://discourse.odriverobotics.com/t/communication-protocol/674/11 "2019-09-05T21:10:50Z")

</div>

In my javascript version I worked from the python code. Its calculated based on the JSON read from endpoint 0:

[FIbre.js](https://github.com/PrimeEuler/fibre/blob/master/lib/fibre.js)  
var buf = new Buffer.alloc(2)  
buf.writeInt16BE(calc\_crc16(PROTOCOL\_VERSION, operation.payload) )  
self.json\_crc = buf.readInt16LE(0)  
[Fibre.py](https://github.com/madcowswe/ODrive/blob/master/Firmware/fibre/python/fibre/discovery.py)  
json\_crc16 = fibre.protocol.calc\_crc16(fibre.protocol.PROTOCOL\_VERSION, json\_bytes)

---

<div class="post-metadata">

**Author:** ![W\_D](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/w_d/32/2013_2.png) [@W\_D](https://discourse.odriverobotics.com/u/W_D)\
**Post date:** [September 7, 2019, 1:59pm UTC](https://discourse.odriverobotics.com/t/communication-protocol/674/12 "2019-09-07T13:59:52Z")

</div>

Just learned something new, I believe: The UART is set to ASCII protocol in the firmware. I would need to compile the firmware and keep it current if others want to use the native protocol.

Correct?

Then it is not usable.

---

<div class="post-metadata">

**Author:** ![Wetmelon](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/wetmelon/32/10_2.png) [@Wetmelon](https://discourse.odriverobotics.com/u/Wetmelon)\
**Post date:** [September 8, 2019, 8:44pm UTC](https://discourse.odriverobotics.com/t/communication-protocol/674/13 "2019-09-08T20:44:57Z")

</div>

> [@W\_D](#):
>
> The UART is set to ASCII protocol in the firmware.

Yes but this is configurable.

> [@W\_D](#):
>
> I would need to compile the firmware and keep it current if others want to use the native protocol.

Huh?

---

<div class="post-metadata">

**Author:** ![W\_D](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/w_d/32/2013_2.png) [@W\_D](https://discourse.odriverobotics.com/u/W_D)\
**Post date:** [September 10, 2019, 9:09am UTC](https://discourse.odriverobotics.com/t/communication-protocol/674/14 "2019-09-10T09:09:10Z")

</div>

I feel stupid when asking but how do I activate the native protocol, packet or streaming, on the UART?

The odrv0.\* properties allow to enable ASCII on the USB port but I can’t see anything to change the UART protocol!?!

---

<div class="post-metadata">

**Author:** ![Wetmelon](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/wetmelon/32/10_2.png) [@Wetmelon](https://discourse.odriverobotics.com/u/Wetmelon)\
**Post date:** [September 10, 2019, 11:53am UTC](https://discourse.odriverobotics.com/t/communication-protocol/674/15 "2019-09-10T11:53:57Z")

</div>

It is done through the tup.config file during compilation

---

<div class="post-metadata">

**Author:** ![cinderblock](https://discourse.odriverobotics.com/user_avatar/discourse.odriverobotics.com/cinderblock/32/17_2.png) [@cinderblock](https://discourse.odriverobotics.com/u/cinderblock)\
**Post date:** [September 15, 2020, 12:07am UTC](https://discourse.odriverobotics.com/t/communication-protocol/674/16 "2020-09-15T00:07:23Z")

</div>

Is the information in this thread still valid for current versions of the firmware?

---

<div class="post-metadata">

**Author:** ![mbilsky](https://discourse.odriverobotics.com/letter_avatar_proxy/v4/letter/m/f07891/32.png) [@mbilsky](https://discourse.odriverobotics.com/u/mbilsky)\
**Post date:** [March 18, 2021, 3:20pm UTC](https://discourse.odriverobotics.com/t/communication-protocol/674/17 "2021-03-18T15:20:33Z")

</div>

Should be. Need to make sure you are using the correct CRC.

I made a video discussing how it works that should help.

[![](https://img.youtube.com/vi/Htb2Q0Yw1FU/maxresdefault.jpg "Decoding ODrive Native Protocol for UART and USB Interfaces for use with Teensy and Arduino") ](https://www.youtube.com/watch?v=Htb2Q0Yw1FU)
