cancel
Showing results for 
Search instead for 
Did you mean: 

SPI - one-way communication Slave->Master

pzahorski
Associate
Posted on June 09, 2015 at 10:54

Hello everybody,

In my current project I need to establish an SPI connection between an STM32F407 microcontroller (slave) and an AD7763 A/D converter (master). Before the ADC actually starts sending any data, its two registers need to be initialised. The microcontroller must first send a total of 64 bits without getting any feedback, which basically means it needs to work in some kind of one way slave to master mode. I know this is against common standards, as generally one direction SPI communication works the other way around, but my question would be - is it doable at all? If yes, does it make sense to try to implementent it, or are there any easier/better solutions?

At the moment I'm trying to send a single byte from the slave to the master, but it keeps being sent continuously instead of only once. I have tried setting an SPIx->DR = 0x00; command in my function to set the register back to 0 after the transmission, but it still does not fully solve the problem - data is sent two/three times instead of once. This is probably due to the transmission's high speed (frequency = 20 MHz).

Thanks in advance for all your inputs/suggestions/examples.

#stm32 #spi #slave #master
2 REPLIES 2
Posted on June 10, 2015 at 05:20

The read/write sense of SPIx->DR is a *different* register, you are not writing or clearing a value.

The slave cannot generate clocks, this has to be done by the master, usually by writing to the DR, any dummy value will do. Reading DR clears the RXNE state in the SR, you might need to do this if the RXNE flag is already raised, and you need to clear out stale data.

One should also be very wary of the debugger, if you look at the DR it changes the SR and the internal state of the SPI peripheral in undesirable ways.

I suspect you'll need to stick it on a logic analyzer and confirm whatever sequence you're generating matches what the documentation says your part needs.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pzahorski
Associate
Posted on June 10, 2015 at 11:41

Thanks for your answer.

Yes, I know this is a different register. What I meant is that I tried to make my microcontroller send zero values after transmitting what I wanted it to transmit, but this way around would not work.

Generating clocks is not an issue - the AD converter actually does provide a 20MHz signal so I do not need to worry about that.

I do not use any logic analyser yet. I'm trying to send exactly one byte of sample data to the master and using an oscilloscope connected to the MISO pin I'm controlling if it's being sent once only, a couple of times or continously.

You have mentioned something about clearing the RXNE flag. When exactly and how am I supposed to do this? Is it not only set and cleared by hardware? When the register has a 0x43 or 0xC3 value and I try to set the RXNE flag to 0 it does not work like this, the register's value is always set back to 0xC3 and the data keeps being sent all the time.