Jump to content

SPI Protocol


Recommended Posts


You don't have to implement the SPI protocol yourself if you don't want to. Instead you can use the C/C++ bindings for microcontrollers. Those bindings implement the SPI-TFP protocol for you, so that you can use more or less the same API as with the normal C bindings. See for example here for the Load Cell Bricklet API.

To use the bindings you have to use a Hardware Abstraction Layer (HAL) for your Arduino, but currently there is no generic one available. (We've released the bindings just some weeks ago). You basically have two options here: Patch the Arduino ESP32 Brick HAL or try to use the prototype Arduino HAL, however I'm not sure if this one works right now.

If you really want to implement the SPI protocol yourself, you have to take a look at our implementations, as there currently is no documentation of the SPI protocol. The implementation used in the microcontroller bindings is here: https://github.com/Tinkerforge/generators/tree/master/uc (have a look at spitfp.h/.c)

As a very short overview (so you know what to grep for ;) ):

  • The SPI protocol (called SPITFP) wraps the TFP protocol that is also used over TCP. See here for the TFP protocol: https://www.tinkerforge.com/en/doc/Low_Level_Protocols/TCPIP.html and for example the Load Cell 2.0 packets: https://www.tinkerforge.com/en/doc/Software/Bricklets/LoadCellV2_Bricklet_TCPIP.html
  • SPITFP consists of two header bytes, a wrapped TFP packet (if it is not only an ACK) and one footer byte:
    • The packet length: 3 bytes for an acknowledgement or 11 to 83 bytes for a payload packet
    • The sequence number of this packet (4 bit) and the sequence number that is acknowledged with this packet (also 4 bit)
    • (Footer) A checksum over all packet bytes except this one. This is a Pearson hash . See here for an implementation
  • Only one packet in flight is allowed in each direction. A bricklet will resend the last packet if you don't acknowledge it.
  • Bricklets expect that you send a CoMCU-enumerate as first packet. If you don't, the bricklet will send a response for the enumerate by itself.


Link to comment
Share on other sites

31 minutes ago, fj2020 said:

-how do I find the bricklet UID? 

The bricklet returns its UID in the enumerate response. For the enumerate request you don't have to set a UID, but use 0 (or "1" if base58-encoded)

31 minutes ago, fj2020 said:

-where do I find information about CoMCU-enumerate?

This is basically the "normal" enumerate: https://www.tinkerforge.com/de/doc/Low_Level_Protocols/TCPIP.html#broadcast-functions but with another function ID (252).

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...