Go Down

Topic: Simultaneous SPI and I2C communication (Read 1 time) previous topic - next topic

joeyjosefjoey

Hi, so basically I am trying to connect 2 accelerometers to the arduino via the I2C protocol and then logging the readings onto an SD card using the Wireless SD shield, which uses the SPI protocol. As some may know, the data buses are shared between I2C and SPI and hence I have a problem when trying to write to the SD card and  read from the accelerometers. Is there any way the 2 protocols can be implemented together or is there maybe one of the arduino boards which has seperate buses for the two protocols?

Thanks

Graynomad

Quote
the data buses are shared between I2C and SPI

In what way? They are separate AFAIK.

_____
Rob
Rob Gray aka the GRAYnomad www.robgray.com

joeyjosefjoey

I was doing some research about it and i found that on a forum. The problem is when i was retrieving data from the I2C bus, the moment i open the file on the SD card, the program halts. I went looking around to see what the problem was and i read that the SDA and SCL are also the DIN and DOUt buses of the SPI protocol =/

Graynomad

Quote
I went looking around to see what the problem was and i read that the SDA and SCL are also the DIN and DOUt buses of the SPI protocol

Not in this universe, at least not on any chip I've seen. Have you looked at the schematics for your board?

Quote
The problem is when i was retrieving data from the I2C bus, the moment i open the file on the SD card, the program halts.

Just a wild guess, but have you considered that there might be a problem with your code :)

Can you post it and also your schematic of possible?


______
Rob
Rob Gray aka the GRAYnomad www.robgray.com

joeyjosefjoey

Thanks for you reply Graynomad. I don't believe everything that is said in a forum, but i always do research about anything that might be an issue concerning my case. In fact, other than that forum, I couldn't find anything about the I2C and SPI sharing the data bus, so that's why I decided to post something here, to get some opinions.

With regards to the code, it could be that I have some errors but I kept the code quite similar to that on the SD library examples but it definitely needs some more work. I am currently not at home so I can't post the code but if I fail in making it work, i will definitely do so. At least now i know that i might have a chance of solving it software wise.

Thanks again.

Nick Gammon


As some may know, the data buses are shared between I2C and SPI ...


No, they are not.

http://www.gammon.com.au/i2c

http://www.gammon.com.au/spi
http://www.gammon.com.au/electronics

Nick Gammon


The problem is when i was retrieving data from the I2C bus, the moment i open the file on the SD card, the program halts.


Was this anything to do with interrupts? Perhaps post your code.
http://www.gammon.com.au/electronics

oric_dan

Quote
http://www.gammon.com.au/i2c

http://www.gammon.com.au/spi


Wow! Good work, Nick. I hadn't seen those 2 particular pages before.

Pages like this should be referenced in an "easy to find" place on the main Arduino website, or are they?
Maybe, an extra link in the main Wire pages, etc,

http://arduino.cc/en/Reference/Wire

or the tutorial page, or somewheres where they're not buried with 1000 other links [like Playground].



Nantonos


Pages like this should be referenced in an "easy to find" place on the main Arduino website, or are they?
Maybe, an extra link in the main Wire pages, etc,

http://arduino.cc/en/Reference/Wire

or the tutorial page, or somewheres where they're not buried with 1000 other links [like Playground].


Yes, wouldn't that be lovely.

Nick Gammon

I'm not sure how to edit that page, or indeed who has permission to do so.
http://www.gammon.com.au/electronics

joeyjosefjoey

Thanks for your links Nick. I did some further research on the matter of the SPI and I2C sharing data buses, and all the schematics i saw never showed any connection between the two. With regards to the program freezing when i open a file in the SD card, that is still happening. I am using the MPU6050 accelerometers and yesterday was able to get them to work simultaneously without using the MPY6050 library. Now i am still able to initialize the card but still can't open files. This is the code having to do with the SD card:

//Initialize Card in void setup()
  if (!SD.begin(CS_pin))
  {
      Serial.println("Card Failure");
      return;
  }
  Serial.println("Card Ready");

//Open file in void loop() after filtering the 6 values for the acc. and then outputting them to serial
    int output1=movingAvarageFilter.process(acc_Front.value.x);
    int output2=movingAvarageFilter1.process(acc_Front.value.y);
    int output3=movingAvarageFilter2.process(acc_Front.value.z);     
    int output4=movingAvarageFilter3.process(acc_Rear.value.x);
    int output5=movingAvarageFilter4.process(acc_Rear.value.y);
    int output6=movingAvarageFilter5.process(acc_Rear.value.z);
   
    Serial.print(output1); Serial.print(",");
    Serial.print(output2); Serial.print(",");
    Serial.print(output3); Serial.print(",");
    Serial.print(output4); Serial.print(",");
    Serial.print(output5); Serial.print(",");
    Serial.println(output6);

   File logFile = SD.open("LOG.csv", FILE_WRITE);
  if (logFile)
  {
    logFile.println("Hello");

    logFile.close();
  }
  else
  {
    Serial.println("Couldn't open log file");
  }

Headroom

Please post you complete code and not just snippets. Also, please use the code tags
Code: [Select]
code tag

This will very much improve the codes readability on the forum.
http://trippylighting.com

http://ledshield.wordpress.com/

Go Up