SPI unexpected behavior

Hi guys,
I'm trying to read some MEMS sensors over SPI using Arduino Due. If I declare the SS pin inside SPI.begin(), I get quite the expected behavior, though sometime it returns me 0xFF. Instead, if I use digitalWrite(), all I get is 0xFF regardless of the ClockDivider or the DataMode. It seems to be related to the SS pin not going low properly.
I currently do not have the possibility to use an oscilloscope.
Do you have any suggestion, like using some pull-ups/pull-downs?
This way it is impossible for me to have a reliable connection. It is simply not working the way it should. The sensor I'm testing is a LPS25HB from ST.
Thanks to everyone

#include <SPI.h>
void setup() {
   SPI.begin(52);
  Serial.begin(115200);
  Serial.setTimeout(200);
  SPI.setClockDivider(52,200);
  SPI.setBitOrder(52,MSBFIRST);
  SPI.setDataMode(52,SPI_MODE0);
  Serial.println("Starting...");
  delay(500);
  SPI.transfer(52,0x0F|0x80, SPI_CONTINUE);
  uint8_t asd=SPI.transfer(52,0x00);
  Serial.println(asd, BIN);
  delay(500);
}
#include <SPI.h>
void setup() {
pinMode(52,OUTPUT);
pinMode(52,HIGH);
   SPI.begin();
  Serial.begin(115200);
  Serial.setTimeout(200);
  SPI.setClockDivider(200);
  SPI.setBitOrder(MSBFIRST);
  SPI.setDataMode(SPI_MODE0);
  Serial.println("Starting...");
  delay(500);
digitalWrite(52,LOW);
  SPI.transfer(0x0F|0x80, SPI_CONTINUE);
  uint8_t asd=SPI.transfer(0x00);
digitalWrite(52,HIGH);
  Serial.println(asd, BIN);
  delay(500);
}

telli:
Hi guys,
I'm trying to read some MEMS sensors over SPI using Arduino Due. If I declare the SS pin inside SPI.begin(), I get quite the expected behavior, though sometime it returns me 0xFF. Instead, if I use digitalWrite(), all I get is 0xFF regardless of the ClockDivider or the DataMode. It seems to be related to the SS pin not going low properly.

digitalWrite(52,LOW);

SPI.transfer(0x0F|0x80, SPI_CONTINUE);
 uint8_t asd=SPI.transfer(0x00);
digitalWrite(52,HIGH);
 Serial.println(asd, BIN);
 delay(500);
}

Ok,
On your second example, your SPI.tranfer(0x0f|0x80,SPI_CONTINUE)
is being interpreted as SPI.transfer(CS=0x8F,value=SPI_CONTINUE,SPI_LAST);

change your example to

digitalWrite(52,LOW);
  SPI.transfer(0x0F|0x80);
  uint8_t asd=SPI.transfer(0x00);
digitalWrite(52,HIGH);
  Serial.println(asd, BIN);
  delay(500);

You were mixing the 'enhanced' and standard mode SPI usage.

Chuck.


Check out my Kickstarter Project Memory Panes an expansion RAM Shield for Mega2560's. It adds 1MB of RAM for those projects where 8KB is not enough.