cancel
Showing results for 
Search instead for 
Did you mean: 

Help to use SPI Receivce Only Slave correctly with an ADC

LKris.1
Associate II

Hi

I have a project were i should communicate with an AD7768 ADC from my Nucleo-H743ZI2. The AD7768 is setup as SPI master and the stm32H743 is setup in SPI Receive slave only mode.

There is three connections between the two devices, a clock signal, a data line and a data ready signal. The AD7768 is just sending data as soon as it is started, so the clock signal is always running and data arrives every time the ready signal is making a pulse. The data is always 32 bytes long and start from the first clock cycle after the ready signal i going low.

The ready signal i called every 1 ms.

How would you recommend this to be implemented?

I tried with a "one shoot"SPI read, were the ready signal is connected to a gpio interrupt and when it is called i read 32 bytes from the SPI. The result here was that the value read from the SPI was always three clock cycle late, so i didin´t get the first three bit. Here i was using the HAL_SPI_Reveive function, i then tried optimizing this function and then i was only missing the first two clock cycles.

I have been think of a function were i start the SPI receive and it just continue reading and then when the ready signal is calling the gpio interrupt, then is should ready the next 32 bytes. Could this maybe solve the problem? If so can anyone maybe give me an idea how to make the SPI continues reading functions.

I hope someone will guide me in the right direction 😊

5 REPLIES 5
TDK
Guru

The STM32 isn't really set up for high speed transactions like this. One possibility is to use two SPI interfaces always recording in circular DMA mode, one for nDRDY and one for DOUT, and scan for and correlate the 1 bit in nDRDY to a reading on DOUT.

There are other ADC chips that are probably a better choice here which support traditional SPI transactions.

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

As it is now its not possible to select another ADC, and its not possible to change the pin connection between the ADC and the MCU. So unfortunally I have to find a way of solving this issue with this setup, so if you have any idea or so, it woulds be a big help.

> its not possible to change the pin connection between the ADC and the MCU

And that is?

JW

LKris.1
Associate II

The connection is

PC10 - ADC SPI CLOCKK

PC12 - ADC SPI DATA

PA0 - ADC READY SIGNAL

You might've given this in terms of the ADC's pin names, for clarity.

I personally would set up one of the timers connected to PA0 (TIM2/TIM5, maybe even TIM8 would be viable) so that the Slave-mode controller's input is the PA0 pin and in Trigger mode, set the timer to OnePulse mode but don't enable it yet i.e. leave TIMx_CR1.CEN=0. I would then set up a different channel of that timer to Output Compare (with or without a pin assigned - no pin needed, but can be used to observe the "action", at least during debugging) and set up a DMA triggered from that channel. DMA would transfer a single word from memory to that SPI's control register, which starts SPI's Rx.

The delay imposed by the timer+DMA might need some trimming/debugging.

I would of course have SPI previously set so that it's Rx slave triggering DMA in circular mode transferring the received data to memory. Data can then be read out from memory either based on the PA0-associated EXTI (or timer trigger) interrupt, or simply by polling DMA's NDTR.

Cube/HAL of course gets more into way here, as this is far from being a "common usage", to which Cube and its clicky are catering.

JW