Pages: [1]   Go Down
Author Topic: Simultaneous SPI and I2C communication  (Read 1032 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8439
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
the data buses are shared between I2C and SPI
In what way? They are separate AFAIK.

_____
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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 =/
Logged

nr Bundaberg, Australia
Offline Offline
Tesla Member
***
Karma: 121
Posts: 8439
Scattered showers my arse -- Noah, 2348BC.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

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 smiley

Can you post it and also your schematic of possible?


______
Rob
Logged

Rob Gray aka the GRAYnomad www.robgray.com

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

the land of sun+snow
Offline Offline
Faraday Member
**
Karma: 149
Posts: 2790
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote

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].


Logged

Nice, France
Offline Offline
Full Member
***
Karma: 11
Posts: 234
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 452
Posts: 18694
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not sure how to edit that page, or indeed who has permission to do so.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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");
  }
Logged

Offline Offline
Sr. Member
****
Karma: 7
Posts: 264
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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

This will very much improve the codes readability on the forum.
Logged


Pages: [1]   Go Up
Jump to: