3
\$\begingroup\$

I have some problems understanding SPI:

I am currently using STMF2xx to connect with FTDI UM232H, I will configure my STMF2xx into slave and FTDI into master.

But, I am having problem getting the data in my STM32 from the FTDI, but when I check my signal, I could see my MOSI (FTDI to STM32) signal is correct!

May I know what could be wrong?

But, isn't that my MISO line should be getting the same data as MOSI but is bit shifted? (am I right? isn't that SPI works like a shift register, whenever sends data into MOSI, the hardware will automatically output to MISO?)

My second question is, does it matter if my MOSI line is always LOW, but MISO line is always HIGH? Or do I need to setup that MOSI and MISO must be low/high initial, or MOSI high, MISO low?

My current configuration for my SPI is:

  1. 2 line duplex
  2. 1 Mhz clock
  3. MSB
  4. 8bit
  5. Phase = Low
  6. Polarity = Positive
  7. Hardware: 4 lines connection, CS, SCLK, MOSI, MISO

SPI signal

\$\endgroup\$
11
  • \$\begingroup\$ What software is running on your STMF2xx? You are correct that data is output on MISO at either the rising or falling (dependant on configuration) edge of the clock at the same time as MOSI is clocked in to the slave. The slave device must have some kind of program to create the MISO data however, are you sending data to the STMF2xx peripheral? \$\endgroup\$
    – Xcodo
    Sep 10, 2014 at 16:07
  • \$\begingroup\$ Possibly I'm misunderstanding you. Are you saying that the SCLK and MOSI data look correct but your program does not read the data? In that case I would check that your STMF2xx SPI peripheral is set up and initialised correctly. \$\endgroup\$
    – Xcodo
    Sep 10, 2014 at 16:10
  • \$\begingroup\$ i wrote my firmware in STMF2xx, right now I configure it as an interrupt driven (NVID), but I am not getting any interupt when I send data from FTDI...but now my STMF2xx, is not sending any data, so my MISO should be high? and no data will be transfered out automatically??? (isnt that true that SPI, when data send using MOSI, it will output the data into MISO automatically cuz of the hardware shift register??? \$\endgroup\$
    – Tim
    Sep 10, 2014 at 16:12
  • \$\begingroup\$ @Xcodo how can i check if my SPI peripheral is init properlly??? i am configuring it as slave \$\endgroup\$
    – Tim
    Sep 10, 2014 at 16:13
  • \$\begingroup\$ I think that would help us if you would put the codes. at least main code. \$\endgroup\$
    – Roh
    Sep 10, 2014 at 16:24

2 Answers 2

3
\$\begingroup\$

But, isn't that my MISO line should be getting the same data as MOSI but is bit shifted? (am I right? isn't that SPI works like a shift register, whenever sends data into MOSI, the hardware will automatically output to MISO?)

No. The slave should clock out whatever it has put into the output register. If there is a 0 there, then 0 is clocked out.

My second question is, does it matter if my MOSI line is always LOW, but MISO line is always HIGH? Or do I need to setup that MOSI and MISO must be low/high initial, or MOSI high, MISO low?

Irrelevant. The level only matters when sampled at the appropriate phase and polarity of the clock.

Make sure that the SPI peripheral is enabled in slave mode and that MISO is configured as an output.

\$\endgroup\$
2
  • \$\begingroup\$ just one more question, to make sure i understand fully, so it doesnt matter what level the MISO/MOSI line (HIGH or LOW), the most important, is to check the phase and polarity only? (the positive or negative edge) \$\endgroup\$
    – Tim
    Sep 11, 2014 at 11:48
  • 1
    \$\begingroup\$ The idle level doesn't matter. The clock settings are important to get right, but if the slave device isn't configured as a SPI slave or if it hasn't set anything to clock out then it won't clock anything out regardless of the clock settings. \$\endgroup\$ Sep 11, 2014 at 11:50
1
\$\begingroup\$

There are several ways interrupt driven SPI can fail to work.

Trivially, the MOSI and MISO connections may be wrong. I am assuming that is not the case.
AFAICT the FT232H might drive signals to 3.63V, which might be an issue the STM32F, but IIRC shouldn't damage it. I am assuming this is okay.
The STM32F should be able to drive FT232H inputs, which the recognise an input high at 2V. So I am assuming this is okay.

The STM32F SPI might not be correctly configured:

  • clock for SPI operation
  • their are four clock vs edge configurations which must match FTDI
  • STM32F pins must be configured for the correct alt function
  • IIRC STM32F pins still need to be configured correctly for output too

Interrupt failure:

  • Incorrect interrupt vector
  • Too low priority, and getting blocked

So try to simplify.

Are you using a 'working' example from ST?

Try to receive data by polling the SPI. Removing issues about interrupts, and just toggle a pin each time data is received. You can watch that pin on your 'scope.

If this doesn't work, try simple 'bit bashing', and receive data by polling the clock and data pin directly. You might only achieve a few Mbit/s, but that would check things are working.

\$\endgroup\$
2
  • \$\begingroup\$ about the connection, i just connect MISO line from FTDI to MISO in STM32 and same for MOSI, my connection should be correct? \$\endgroup\$
    – Tim
    Sep 11, 2014 at 0:19
  • \$\begingroup\$ @Tim - Yes, MISO to MOSI, and MOSI to MISO, when the FTDI is master and STM32F is slave. \$\endgroup\$
    – gbulmer
    Sep 11, 2014 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.