Go Down

Topic: spi trouble when adding second device (Read 947 times) previous topic - next topic

japie

Hello,

I ran into a very strange problem this weekend.
I made an extension board for engine data logging with a DS1307, analog inputs for pressure, 2 rpm counters and an sdcard on it, all working very well for the last year.
This week I build one for a friends tractor puller but with an Mega instead of an UNO, due to I2C and SPI pin differences I am using softI2C and softSPI on the Mega for that, no problem also that is working very well.
For temperatures I use another board, the KTA-259 http://oceancontrols.com.au/KTA-259.html which also uses SPI placed on top.
On the UNO all is working very well but on the Mega the moment I add the KTA board the sdcard is failing, nomather how or what I initialize first or not at all, when the KTA board is plugged in sd card stops working.
My pin layout is as follows:

9 - CS -> KTA259
10 - SS -> sdcard
11 - MOSI -> sdcard
12 - MISO -> sdcard + KTA259
13 - SCK -> sdcard + KTA259

The only thing I can think of is that the KTA-259 is somehow blocking either or both pins 12 & 13 but have no idea how or why, maybe someone over here can shine some light on this?

p.s. It is not code/lib related since all parts separately work with the code, the moment I add the KTA board it looks like the sdcard pins are "stolen" or interfered in some way...

SurferTim

Try the SD first. Disable the KTA259 SPI first, then see if the SD works ok alone.
Code: [Select]
void setup() {
  Serial.begin(9600);

  // disable the KTA259 SPI
  pinMode(9, OUTPUT);
  digitalWrite(9, HIGH);

  Serial.print(F("Starting SD..."));
  if(!SD.begin(10)) Serial.println(F("failed"));
  else Serial.println(F("ok"));

Does the SD start ok?

japie

@TimThe SurfDude:

Indeed, no problems with the sdcard at all when disabling the KTA with this.

Also tested a sketch with reading temps and before calling that function disabling the kta's SPI and it does read temps then, will write a test sketch to see of the card is accessible during kta SPI function...

Thanks!

SurferTim

Now disable the SD and try accessing the KTA.
Code: [Select]
void setup() {
  Serial.begin(9600);

  // disable the SD
  pinMode(10, OUTPUT);
  digitalWrite(10, HIGH);

  // now try accessing your KTA here
}

I think you are catching on to this.  :)

japie

Strange thing is that when I add
Quote
digitalWrite(9, HIGH);

SDcard starts working AND the kta remains working??? But that is what I wanted... ;-)
I must say that since I use softSPI and softI2C on the Mega it is starting to behave very strange, the DS1307 initialization code trows an error but when I open the serial console (and by that restarting the program) it does not trow an error.
Also I have a led connected to pin16 that won't go off.
But those are minor things, main headache was the SPI problem, thank you for helping!

SurferTim

#5
Apr 28, 2013, 07:22 pm Last Edit: Apr 28, 2013, 07:25 pm by SurferTim Reason: 1
Quote
SDcard starts working AND the kta remains working??? But that is what I wanted... ;-)

OH NO!! I'll call Delta Force and send in an extraction team!!

edit: I always forget the smiley face.  :)

japie

Remain calm and step away from the arduino... :-)

Thanks Tim you made my day!!!

SurferTim

Quote
Thanks Tim you made my day!!!

...and you made mine!  :)

Go Up