cancel
Showing results for 
Search instead for 
Did you mean: 

Problems reading SSI encoder devices using SPI Master RX only on STM32F405RGTx

NEdom.1
Associate III

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:

NEdom1_0-1771933127367.png

The CubeMX setting is as below:

NEdom1_1-1771933279977.png

 

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:

 
 

NEdom1_5-1771934758899.png

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.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Super User

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.

If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

2 REPLIES 2
Saket_Om
ST Employee

Hello @NEdom.1 

Please refer to the example below to configure your DMA.

STM32CubeF4/Projects/STM32F4-Discovery/Examples/SPI/SPI_FullDuplex_ComDMA at master · STMicroelectronics/STM32CubeF4

To give better visibility on the answered topics, please click on "Accept as Solution" on the reply which solved your issue or answered your question.
Saket_Om
TDK
Super User

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.

If you feel a post has answered your question, please click "Accept as Solution".