3

I would like to ask a question relating to the following communication setup:

STM32 -- Arduino Pro Mini -- ADNS3080 sensor

The interface between STM32 -- Arduino is I2C and the interface between Arduino Pro Mini--ADNS3080 is SPI.

I have tested the communication between the STM32 and the Arduino Pro Mini, and between the Arduino Pro Mini and the ADNS3080 sensor. Both of them work fine; I can successfully send and receive data in both cases.

Now, I want to read the register of the ADNS3080 sensor using the STM32. First, I start an I2C communication between the STM32 and the Arduino Pro Mini, then I send the register address of the ADNS3080 to the Arduino Pro Mini. The Arduino Pro Mini reads the register address and in the same function starts a communication, using SPI, with the ADNS3080 sensor.

But I receive I2C errors in the STM32. Is it possible to use I2C and SPI at the same time? Do I have to introduce delays between the I2C and SPI commands?

Regards, Ali

migrated from electronics.stackexchange.com Dec 17 '16 at 16:24

This question came from our site for electronics and electrical engineering professionals, students, and enthusiasts.

  • 1
    I feel like their interrupts would be bumping into each other. – Bort Dec 17 '16 at 14:50
  • 1
    I smell a real time issue but not sure. Is the I2C finished before stating SPI? – Tedi Dec 17 '16 at 14:55
  • 3
    They are on separate busses, so yes you can do both in one program. However if one is being triggered by an interrupt from the other and it itself relies on interrupts there may be a problem there. You should have one interrupt telling your main program it's time to do the second operation rather than run it direct from inside an interrupt. – Majenko Dec 17 '16 at 14:55
  • 2
    Are you expecting that the Arduino can execute the SPI transaction and return the data to the STM32 in the same I2C transaction? That isn't likely to work. You're going to need some sort of flow control or handshake mechanism that tells the STM32 when the data is actually available. This could be anything from clock stretching to splitting it into multiple I2C cycles in which the STM32 polls the Arduino for status. – Dave Tweed Dec 17 '16 at 16:10
  • You will get better answers if you post your code. You are asking about errors in unposted code, with no schematic. Any answers thus are general, and largely guesswork. – Nick Gammon Dec 18 '16 at 5:14
3

is it possible to use I2C and SPI at the same time?

Yes it is. Both are implemented in hardware in the chip. They can operate "in the background" and raise an interrupt when there is something to do.

Do I have to introduce delays between the I2C and SPI commands?

No you don't.

0

Your Arduino code probably needs to implement clock stretching as an i2c slave. This tells the master to chill for a little while as the slave does some work to get an answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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