cancel
Showing results for 
Search instead for 
Did you mean: 

I need to find out how to interface with an SPI-based encoder which returns 34 bit words. The STM32F407 documentation (rm0090) shows only 32 bits per transfer.

JSuth.1
Associate II
 
7 REPLIES 7

Hard luck.

I don't know what you mean "32 bits per transfer", SPI in 'F407 is constrained to 8-bit or 16-bit, see SPI_CR1.DFF.

Solution depends on the slave and your expectations. Some SPI slaves don't mind if you clock more between framing signal transitions, so you can e.g. transfer 3x16=48 bits and just ignore the rest.

You always can bit-bang the protocol in some way.

JW

JSuth.1
Associate II

The encoder documentation describes the returned data as below. There are 18 bits of data. The communication begins with an opcode, in this case 0xA6, followed by the data. There is then a bit to show error, if any, then a warning bit, followed by a six-bit CRC. These are the 34 bits I was describing. We must input the data, then check the warning and error bits, test the CRC and, if all is OK, translate the data to an angular measurement. I was hoping that I could read the 34 bits with one transfer, then do the parsing. That doesn't seem possible with the F407.

x

0693W00000VOMdCQAX.png0693W00000VOMj5QAH.pngAs you can imagine, there are many other processes occurring here. But it sounds like bit banging is probably the only way.

Thank you for responding.

Uwe Bonnes
Principal III

Check if the device accepts 40 bit sent w/o problem. Check if you have time to bit-bang the 34 SPI bits. Consider a more modern STM32 that can transfer 4..16 bits per call and switch the bit width during transmission.

S.Ma
Principal

A slave chip to sell well should be easily compatible with most masters in the masket. Something weird here. As you transmit and receive with spu, check if 64 clocks (extra spare clocks) works. And as said by others, newer stm32 spi should be able to handle 17 bit chunck with fifo and dma.

Uwe Bonnes
Principal III

E.g. the HX711 weight sensor uses 25/26/27 SCK pulses. So people use bitbanging. But a 50 microsecond also resets the device. So if the CPU is busy for some time while SCK is already high, unexpected results happen. A lot of people got biten by that...

JSuth.1
Associate II

Yes, I can see that I will have to do the "bit banging". I was hoping to have things done automatically. I think there is enough time, but I haven't gotten to the point of checking the details. I'm using an STM32F4-Discovery just for testing. My motor controls will be done by the m4 processor of the STM32MP151. It's more complicated, so I was hoping to avoid needless complexity. Thanks very much for your help.

AScha.3
Chief II

with STM32MP151 is spi possible , just look im RM setting spi to 17 bit transfer;

then set circular DMA, 4 data words; on half-/full callback you get complete data .

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