2026-02-24 4:10 AM
I got an angle encoder with SSI interface, which is Synchronized Serial Interface. The output data is 21-bit. No CS signal is needed.
I have implemented using SPI1 master mode RX only reading this encoder, with SPI_CLK as the serial clock and SPI_MISO for data input. The data size to read is set to 3 bytes, but the clock is transmitted one more byte as intended. HOW DID THIS HAPPEN? Does the SPI send a dummy address on receiving?
The clock is generated immediately upon calling
__attribute__((aligned(4))) uint8_t raw_angle[16] = {0};
HAL_SPI_Receive_IT(&hspi1, raw_angle, 3);The data captured by logic analyzer:
The CubeMX setting is as below:
I found that SPI_SR_RXNE is left triggered after 3 bytes read by the HAL API, so I have to clear the flag before calling HAL_SPI_Receive_IT.
while((SPI1->SR & SPI_SR_RXNE)){
SPI1->DR;
}
HAL_SPI_Receive_IT(&hspi1, raw_angle, 3);
I have also tried DMA mode using HAL_SPI_Receive_DMA(&hspi1, raw_angle, 4) , but no luck of success. The DMA hits HAL_SPI_ERROR_FLAG error. The CubeMX setting is as below:
It is said that it's bad practice using DMA for small amount of data, but I still want to know how to get it work. Anyone could help? Thanks a lot.
Solved! Go to Solution.
2026-02-24 5:11 AM
SPI RX only mode generates clocks automatically. Use two-way mode if you need a specific number of bytes to be read. MOSI does not need hooked up.
2026-02-24 4:25 AM
Hello @NEdom.1
Please refer to the example below to configure your DMA.
2026-02-24 5:11 AM
SPI RX only mode generates clocks automatically. Use two-way mode if you need a specific number of bytes to be read. MOSI does not need hooked up.