cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103 SPI question

turboscrew
Senior III
Posted on April 28, 2017 at 12:57

This is the first time I need SPI, and there are two things that are still unclear to me:

1) I understand that to receive from a slave, I need to send something - maybe zeros?

So if I have a chip that takes register address and data, and returns status, I need to send

address, data and a zero?

2) It says in the reference manual that the HW NSS goes active when something is written in the

transmitter register and stays active until the SPI is turned OFF (SPE-bit), but how about the clock?

Does the clock stop ticking when the transmitter shift register gets empty? And is the BSY-flag turned

OFF when that happens?

#spi #stm32f103
2 REPLIES 2
Tilen MAJERLE
ST Employee
Posted on April 28, 2017 at 13:08

Hello,

please check answers below:

  1. In SPI you have to clock out 8 cycles for one byte to get something from slave. I think you understand that. To get clocking, you have to 'send' something. In most cases you send dummy bytes, either 0x00 or 0xFF, TO do that, you enable SPI peripheral, and write your byte (dummy) to transmit register. SPI will automatically start clocking and BUSY bit will be set until clocking is finished. After that, you can read byte received from slave.
    1. In case of address->data->status, you would do it like this: BYTE1 = ADDR, BYTE2 = DATA, BYTE3 = DUMMY (either 0x00 or 0xFF). You are interested only in third received byte, so read only this byte and interpret it later.
  2. NSS will go low. clocking will stop after all your bytes are sent. If you have 1 byte, 8 clock cycles will be on output SCLK pin. At that time, BUSY flag will go back to 0 (cleared state)

Hope this is more clear now.

Posted on April 28, 2017 at 13:12

Thanks for confirming what I suspected.