chipKIT® Development Platform

Inspired by Arduino™

SPI multiples devices- Sd card and Barometric -help Plz

Created Sat, 14 Sep 2013 00:06:28 +0000 by Omnimusha


Omnimusha

Sat, 14 Sep 2013 00:06:28 +0000

Hi, I'm using fubarino SD, I have problems with the simultaneous use of the devices (Barometric Pressure Sensor and Sd card).

I have no problems separately, but with the simultaneous use devices are locked and do not work.

    • fubarino SD, the SS pin is the chipSelect_SD = 27 for Sd card?, I try to enable and disable digitalWrite (chipSelect_SD, HIGH) digitalWrite (chipSelect_SD, LOW);, but this always works, I can not disable sd card

any ideas? from already thank you very much

/*
  Digital Pot Control
  
  This example controls an Analog Devices AD5206 digital potentiometer.
  The AD5206 has 6 potentiometer channels. Each channel's pins are labeled
  A - connect this to voltage
  W - this is the pot's wiper, which changes when you set it
  B - connect this to ground.
 
 The AD5206 is SPI-compatible,and to command it, you send two bytes, 
 one with the channel number (0 - 5) and one with the resistance value for the
 channel (0 - 255).  
 
 The circuit:
  * All A pins  of AD5206 connected to +5V
  * All B pins of AD5206 connected to ground
  * An LED and a 220-ohm resisor in series connected from each W pin to ground
  * CS - to digital pin 10  (SS pin)
  * SDI - to digital pin 11 (MOSI pin)
  * CLK - to digital pin 13 (SCK pin)
 
*/

#include <SPI.h>
#include <SD.h>


File myFile;
const int chipSelect_SD = 27; // Change 10 to 53 for a Mega

// set pin 10 as the slave select for the digital pot:
const int slaveSelectPin = 10;

void setup() {
  // set the slaveSelectPin as an output:
  pinMode (slaveSelectPin, OUTPUT);
  digitalWrite(slaveSelectPin, HIGH);
  // initialize SPI:
  SPI.begin(); 
  
  
           pinMode(chipSelect_SD, OUTPUT);
            digitalWrite(chipSelect_SD, HIGH);
            if (!SD.begin(chipSelect_SD)) {
              Serial.println("initialization failed!");
              return;
            }

  
     myFile = SD.open("/data/demo0.txt");
}

void loop() {
  // go through the six channels of the digital pot:
  for (int channel = 0; channel < 6; channel++) { 
    // change the resistance on this channel from min to max:
    for (int level = 0; level < 255; level++) {
      digitalPotWrite(channel, level);
      delay(10);
    }
    // wait a second at the top:
    delay(100);
    // change the resistance on this channel from max to min:
    for (int level = 0; level < 255; level++) {
      digitalPotWrite(channel, 255 - level);
      delay(10);
    }
  }
  
  
                   for(uint8_t z=0;z<23;z++){ //6*3/2
                      uint8_t data = myFile.read();
                      Serial.println(data);
                      
                     
                      }
                      myFile.seek(0);
  
  
  
  

}

int digitalPotWrite(int address, int value) {
  // take the SS pin low to select the chip:
  digitalWrite(slaveSelectPin,LOW);
  //  send in the address and value via SPI:
  SPI.transfer(address);
  SPI.transfer(value);
  // take the SS pin high to de-select the chip:
  digitalWrite(slaveSelectPin,HIGH); 
}

majenko

Sat, 14 Sep 2013 08:27:59 +0000

Yes, the SD card's chip select is on pin 27.

SD cards are often tricky to get going with other devices. The software to drive them has SPI built into it, and it does all sorts of strange things with it. From what I remember it runs in a different data mode to most other devices, so getting it to work may involve delving into the SD library and wrapping bits that do the SD work in commands to reset the mode to what it should be, and also wrapping your SPI calls with code to set the mode yet again.

However, there is a simpler way!

The Fubarino SD has a second SPI channel. I forget exactly where it is, but it's something like pins 8 to 11 or thereabouts. Check the manual for which pins do what.

You can use the DSPI.h library instead of the SPI.h library to access the other SPI channels, so to get at the second channel you would do something like:

#include <DSPI.h>

DSPI1 otherSPI;
/...

otherSPI.transfer(23);

Once you have worked out which pins it is, and got it wired correctly, all should be well.


Omnimusha

Sat, 14 Sep 2013 19:02:36 +0000

hello again, Majenko.

I have a problem, does not compile "error: 'DSPI1' does not name a type"

with DSPI0, compiles and runs the device, but the pins belong to the pin:

define pinSS 27

define pinMOSI 26

define pinMISO 25

define pinSCK 24

regards!!


majenko

Sat, 14 Sep 2013 19:45:00 +0000

Hmmm... It would appear that the Fubarino SD was never set up to use any more than one SPI port... bit silly really...

Okay... You can modify your board definition to give you a second SPI port.

Pins are: SCK = 7 SDI = 8 SDO = 9

Find the file "Board_Defs.h" in the hardware/pic32/variants/Fubarino_SD folder, and replace it with the one in the attached zip file.

Then restart the IDE (if it was running), and try compiling with DSPI1 again. It should work.


Omnimusha

Sat, 14 Sep 2013 20:09:59 +0000

does not work, shoot me all these errors, I'm using version "mpide-0023-windows-20130715"

C:\Users\Omnimusha\Desktop\mpide-0023-windows-20130715.\hardware\pic32\libraries\DSPI\DSPI.cpp: In constructor 'DSPI1::DSPI1()': C:\Users\Omnimusha\Desktop\mpide-0023-windows-20130715.\hardware\pic32\libraries\DSPI\DSPI.cpp:1001:21: error: '_SPI3_BASE_ADDRESS' was not declared in this scope C:\Users\Omnimusha\Desktop\mpide-0023-windows-20130715.\hardware\pic32\libraries\DSPI\DSPI.cpp:1002:8: error: '_SPI_3_VECTOR' was not declared in this scope C:\Users\Omnimusha\Desktop\mpide-0023-windows-20130715.\hardware\pic32\libraries\DSPI\DSPI.cpp:1003:10: error: '_SPI3_IPL_IPC' was not declared in this scope C:\Users\Omnimusha\Desktop\mpide-0023-windows-20130715.\hardware\pic32\libraries\DSPI\DSPI.cpp:1003:38: error: '_SPI3_SPL_IPC' was not declared in this scope C:\Users\Omnimusha\Desktop\mpide-0023-windows-20130715.\hardware\pic32\libraries\DSPI\DSPI.cpp:1006:7: error: '_SPI3_ERR_IRQ' was not declared in this scope C:\Users\Omnimusha\Desktop\mpide-0023-windows-20130715.\hardware\pic32\libraries\DSPI\DSPI.cpp:1006:23: error: '_SPI3_RX_IRQ' was not declared in this scope C:\Users\Omnimusha\Desktop\mpide-0023-windows-20130715.\hardware\pic32\libraries\DSPI\DSPI.cpp:1006:38: error: '_SPI3_TX_IRQ' was not declared in this scope


majenko

Sat, 14 Sep 2013 20:18:32 +0000

Right...

There a couple of different versions of the Fubarino SD. Which chip is on your board?


Omnimusha

Sat, 14 Sep 2013 20:30:52 +0000

I'm using version, Fubarino SD v1.4, with the ide "mpide-0023-windows-20130715" that ide is using you?, what you sent me, it does not compile.


majenko

Sat, 14 Sep 2013 20:46:24 +0000

Ah, the 1.4. That's the one from seeeeee....ed?

That only has the 440 chip on it, not the 795 chip of the 1.5... That only has 1 SPI port :(

Ok, ignore all I have said so far, it won't work with that version of the SD...

You might be better off bit-banging SPI (or using shiftIn() and shiftOut()) to control your barometric sensor...


Omnimusha

Sat, 14 Sep 2013 21:42:36 +0000

I have done the barometric function, with the library # include <SoftSPI.h>, and also works the sd Card # include <SD.h>, work together.

include <SoftSPI.h>

SoftSPI spi;

define pinSS 10

define pinMOSI 9

define pinMISO 8

define pinSCK 7

Now, what is the maximum speed that can be put SoftSPI library?

/ / Spi.setSpeed ​​(Full_speed)???

and the sd card, and put masxima speed?


Omnimusha

Sat, 14 Sep 2013 23:30:28 +0000

another problem, the library <SoftSPI.h> or digital pins, for my purposes, it is very slow, SPI compared. if or when devices are connected the SPI.

I tested with, / / shiftOut (.........), but also very slow


Omnimusha

Mon, 16 Sep 2013 04:44:42 +0000

i found what the problem. the problem is the SD library card, the Slave Select pin CS pin = 10, why?

because when I put digitalWrite (10, HIGH); arduino should ignore the SD card. The clock on the SD card, do not have to, listen to the arduino.

and if. sd card is listening, so is the conflict

as fix this?


unexpectedly

Mon, 16 Sep 2013 07:46:23 +0000

Try changing the SD Card library code to look at the proper pin instead of 10?

Pin 10 is the typical Arduino SPI CS/SS pin, so whoever wrote the code assumed you would use that pin.

Majenko: I saw on your adafruit 1.8" TFT shield there was microSD card in it... did you get SD Card lib working on it? I still haven't tried...


Omnimusha

Mon, 16 Sep 2013 14:03:44 +0000

sorry is pin 27, while writing the previous post I got it wrong

found what the problem. the problem is the SD library card, the Slave Select pin CS pin = 27, why?

because when I put digitalWrite (27, HIGH); fubarino SD, should ignore the SD card. The clock on the SD card, do not have to, listen to the fubarino SD.

and if. sd card is listening, so is the conflict

as fix this?