An STM32 HAL example of communicating with an absolute encoder over the SSI interface. A single-turn 14-bit encoder from CUI Devices is taken as an example. The relevant evaluation kit is AMT232B-V. Both blocking and non-blocking (_IT) modes are implemented.
The main motivation behind this submission is to encourage you to get familiar with an SSI interface. And the "an" here is to point out that SSI is kind of a loosely defined standard and many modified versions exist. You should then pay a special attention to timing waveforms provided by a manufacturer of a device you are going to deal with. The differences may be in the physical layer (differential vs. single-ended lines) as well as in the presence of the CS line or its lack (as in the initial specification). You may also encounter some naming inconsistencies. The SSI without the CS line uses the first SCK transition from high to low to start the communication with the slave and the consecutive transition from low to high to inform the slave that it is time to push the first bit of information. The bits should be then sampled at the CLK falling edges. The SSI with the CS line may still keep the original "additional" clock cycle or skip it, as the CS line can now serve its purpose, turning into the regular SPI, yet still called in some datasheets an SSI.
For example, to communicate with the absolute encoder AMT23, we have to reproduce the following waveforms:
Source: CUI Devices AMT23 datasheet
We are going to use a regular SPI peripheral to do that. Note that the SPI uses CS to initialize pushing the bits. The SPI then samples the MISO line also at the red falling edge what is needless here. Also note that the STM32 SPI peripheral can be configured to read from 4 to 16 bits. We will then use HAL_SPI_TransmitReceive() to read 16 logical states (the spare red one and the 15 green bits of information). Then we will read the last bit of information (the blue one) using HAL_GPIO_ReadPin() before pulling up the CS line.
Don't worry 🙂 Just hit Alt-K to generate /Drivers/CMCIS/ and /Drivers/STM32G4xx_HAL_Driver/ based on the .ioc file. After a couple of seconds your project will be ready for building.
- OLED: stm32-ssd1306 (MIT license)
- Bidirectional 4-channel logic level shifter
- OLED display 1.3" (SH1106 or SSD1306)
- AMT Cable AMT-06C-1-036
- DSLogic Plus or any other logic analyzer capable of sampling at 16+ MHz.
- YAT - Yet Another Terminal :: Serial Communication :: Engineer/Test/Debug
- Tabby - a terminal for the modern age
- SSI Interface Description (from the original developers of SSI)
- SSI Encoders Overview
- How SSI Encoders Work
- Synchronous Serial Interface
- Integrating Absolute Encoders - An Overview of SPI, RS-485, and SSI Protocols
- AR35-T25E/S Series - Figure 9 suggests to be an example of SPI denoted as SSI (haven't put my hands on that particular encoder, so correct me if I'm wrong)
- AEAT-6010/6012 Magnetic Encoder - identical waveforms as in our case
- BiSS and SSI - An Overview
Create your own home laboratory/workshop/garage! Get inspired by ControllersTech, DroneBot Workshop, Andreas Spiess, GreatScott!, ElectroBOOM, Phil's Lab, atomic14, That Project, Paul McWhorter, and many other professional hobbyists sharing their awesome projects and tutorials! Shout-out/kudos to all of them!
Warning
Control in power electronics and drives - do try this at home ❗
190+ challenges to start from: Control Engineering for Hobbyists at the Warsaw University of Technology.
Stay tuned!