2018-11-29 07:40 PM
Hi, I've worked a bit on STM32 before (STM32F7 to be more precise), so I have little knowledge about the STM platform. I normally don't need to ask question on forum because Google is a very good professor, but this time I'm not sure to have found enough informations.
So here's the problem I have:
I work on a project where I need (at least) to read a MAX31855 thermocouple converter with the help of a bluepill (STM32F103C8). It is done with the SPI 1 (remapped). The thing is, the readed data make absolutely no sense. I know thought that the hardware and software work because on an other project based on stm32duino, the temperature reading is ok. For my needs, I want to transfert everything from Arduino to good old C++ code with SW4STM32.
What I think is the problem: The thermocouple IC is read-only, so from what I can see it begin to push his data as soon the CS is low and that the SCK begin. The thing is, HAL_SPI_Receive (function from HAL provided by STM) uses HAL_SPI_TransmitReceive when in full duplex. So from what I can understand, it send one byte to receive one. This is why I've change hspi1.Init.Direction = SPI_DIRECTION_2LINES; to hspi1.Init.Direction = SPI_DIRECTION_2LINES_RXONLY; thinking it would work... but it didn't.
Anyway sorry for the very long message and my not so good english, but if someone have an idea, I'll appreciate it. Thanks!
2018-11-30 12:59 AM
The Rx-only mode on SPI is tricky as it starts to clock immediately after you enable it and won't stop until you disable it; so it's relatively difficult to insert a chipselect GPIO manipulation into the stream of clocks.
On the other hand, in the "normal" bidirectional mode, clocks are output only when data written into the data register. The Tx bit does not need to be enabled (i.e. set as AF - in the old 'F1 family this is more constraining than in other STM32 families, where the given pin still can be AF of a different peripheral) or simply the Tx pin may be left unconnected. This should cause no problem with Rx, so if the read data make no sense, you should investigate deeper.
The best way is to connect a logic analyzer to the SPI lines and observe the data there.
JW
2018-12-16 09:57 AM
So after all I finally manage to get some time to work on the project. I've analyse the SPI signal. It was looking OK but I'm not completely sure because I didn't monitored the CS lines (when I will get more time I will take the bigger logic analyser). After coding my project differently, it still doesn't work.
https://electronics.stackexchange.com/questions/130435/stm32-spi-half-duplex-1-wire-bidirectional-problem Here a thread that confirm what you say.
I can't understand how easy it was with the arduino code to do this VERY simple spi read while the HAL plateform doesn't work at all.
2020-09-23 02:12 PM
Hi could you share your code? I am working also with MAX and STM32 Mcu. Would be a great help!!