SPI function description

SPI_I2S_SendData(SPI2, byte);

this function is standard function given in standard peripheral library of stm32 board.however it is not clear if the spi sends 8 bits through MOSI and makes the pin low or maintains the status of last bit on the pin until next bit is transfered.i scoped the output of the pin and found that the MOSI pin retains the last bit value.now i dont know if the correct sequence is being sent or some overflow bits are corrupting the data.any help?

Try checking it with a loopback test. You should receive what you send.

Leon

how exactly do i do it?do i need two differnt boards?

Just connect MISO and MOSI.

is there any standard code example for that?how do i read the value at MISO?are ther any standard functions in the library for that?

SPI uses shift registers in the master and slave. You should get back what you send, with a loopback test. Just check the receive register contents.

Leon

SPI is synchronous - data is only sampled based upon SCLK (where on SCLK depends on the SPI mode being used). The value of MOSI or MISO is not important until the clock condition is met (minus the normal signal setup times, etc).

More “fun” for you - this MCU may tx/rx either 8 or 16 bit data packet. (this is programmable) It may be possible that what you see is the “unexpected/unprogrammed” 9th bit.

Most of the higher pin count devices have at least 2 SPI modules - and as Leon says - you can perform a “loopback” on the same board - employing the single chip. (sends from spi1 to spi2)

Review/read the many libraries (especially those of IAR, Keil) - these have multiple SPI examples - including a loopback as I recall…

1)does the ideal implementation of SPI transfer involve automatic chip select during transfer and deselect after transfer?

2)when i send data through the MOSI pin, supposing if the last bit sent is “1”, should the pin return to 0 or does it maintain the “1” state and the chip select takes care of deselecting the slave?

3)Similarly, should i do the coding for selecting the chip select and deselecting it during transfer operation?or is if hardware builtin?this could save a lot of precision problems caused by chip select.any idea?

I was thinking of a loopback test to the same SPI. I always do that first when using SPI with an unfamiliar device, to make sure that it’s working. I also use a little PCB I’ve made with a 74HC595 and eight LEDs on the outputs for testing, the HC595 is SPI-compatible.

Where to begin?

a) Again - detailed SPI examples are numerous in both IAR & Keil libraries - freely available

b) STM32 has “non-standard” NSS behavior - you most always need to control this signal via SW

c) Leon’s suggestion of HW monitor is terrific. (we did the same - then implemented a “multi-function” (SPI, I2C, Uart) Serial Monitor on low cost Lcd which performs “Diagnostics” as well. Will introduce here shortly upon completion of “beta” testing.

d) Always advise that you test/develop across > single board/single IC. Do you observe the same behavior on 2nd bd/IC?

e) You will benefit greatly by thorough review of ST “RM0008” Ref Manual and the SPI examples mentioned several times now…

ok SPI port is working fine. i tested the loop back function.now if everything is fine in the sequence of commands i sent for initialization, what is going wrong?

Have you reviewed SPI chapter - as suggested - in ST’s RM0008?

Have you reviewed multiple SPI code examples - as suggested - in IAR & Keil libraries? (both freely available)

English is strange/demanding language - we can’t tell what you mean when you report, “SPI working fine” followed quickly by “what is going wrong?”

Helpers “lose interest” if you don’t follow suggestions - these are intended to save “wear & tear” on you and helper…