Pages: 1 [2]   Go Down
Author Topic: Problem using both SPI library and SD library in Arduino UNO program  (Read 4902 times)
0 Members and 1 Guest are viewing this topic.
Colorado, USA
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi Dave2Satellite - I read your thread with great interest as I am in the same position.  In my case I'm using the SD library with an A/D on the SPI line - an LTC1859CG#PBF to be precise.  The SD card works fine but the A/D returns all 1's.  I placed a data analyzer on the lines and it appears like the SD card is sending garbage on the MISO line after the file is closed and the A/D interprets the garbage as 1's.  The A/D still doesn't work properly when I upload a sketch that contains only the A/D and SPI - without the SD stuff.  I have to remove power to the arduino to get the A/D working properly by itself with no SD references.  Also - if I remove the SD card while the A/D is reading garbage then the A/D starts working magically (the MISO line settles back to normal operation).  I went back and tried to implement the SdFat library but it didn't work - same results.  You mentioned you only made a few modifications - were any of them to the SdFat library by chance?  Any help is greatly appreciated! - -Leah
Logged

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

I made no changes to the SdFat library, I only had to modify the programs we had written.  They were the includes, definitions and the function calls, which was nothing of significance in respect to the actual code for SPI and SD/SdFat.  We did not look at any of the SPI lines during use, sorry. 

It sounds a bit like you are having a different problem than we had, I would recommend starting a new topic with a detailed explanation of your setup.  You have a few funky things going on that are new to us, as we narrowed our problem to the SD/SPI library and ruled out the hardware.  However, we did come to this conclusion: The Arduino SD library should not be used with more than one device on a SPI bus, you should use the SdFat library to get multiple devices to work on a SPI bus.
Logged

Miramar Beach, Florida
Offline Offline
Faraday Member
**
Karma: 115
Posts: 5380
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
The Arduino SD library should not be used with more than one device on a SPI bus, you should use the SdFat library to get multiple devices to work on a SPI bus.
...unless the other device is the w5100 ethernet IC, then the standard SD library will work fine.

@LeahM: Try disabling the SD SPI in setup. If D4 is not the slave select, change that.
Code:
pinMode(4,OUTPUT);
digitalWrite(4,HIGH);
// then do your AD stuff
You must disable it or initialize it.  Otherwise, it will cause garbage on the SPI bus.

If you initialize it, insure you disable your AD device SPI first. Otherwise, it could cause garbage on the SPI and mess up the SD startup.
« Last Edit: March 26, 2013, 08:36:48 pm by SurferTim » Logged

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

Hi SurferTim - I tried you suggestion and it didn't work.  I thought since the MISO line is going wonky that I'd try isolating the MISO on the SD card when it's not in use - but that didn't work either.  I'll go ahead and start a new thread.  Thanks! 
Logged

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

Hi,
I am using the arduino mega 2560 with the yei 3 space sensor embedded module. I was planning on using the tx1(pin 18) and rx1(pin 19) to communicate asynchronously with the mega. However I dont seem to be getting any output. I then tried to use the SPI communication protocol from the code pasted in the first question but I am getting 0 outputs for all 3. Can someone provide some code with for communication with the arduino mega. thanks
#include<string.h>

void setup()
{
   Serial.begin(9600);
   Serial1.begin(9600);
   pinMode(18,OUTPUT);
   pinMode(19,INPUT);
}

char inData[30]; // Allocate some space for the string
char inChar; // Where to store the character read
byte index = 0; // Index into array; where to store the character

char a[32];
float b;
float c;
float d;
char str1[15];

void loop()
{
   Serial1.print("smiley-mad\n");  // over here the face is a ": 0" without the space
   while (Serial1.available() > 0)
   {
      int red = Serial1.read();
      if (Serial1.read() == '\n')
      {
         Serial.print(red, HEX);
      }
   }   
}

This is what I tried for async communication
Logged

Pages: 1 [2]   Go Up
Jump to: