Hello,
I wrote this code to read an eeprom ST M95160 but I do not understand why it run perfectly on Arduino NANO, and not on a Arduino DUE.
I had to write this code because Arduino DUE SPI libraries (which operate with the dedicated SPI connector) do not work with this eeprom (also using Extended SPI functions).
Does anyone know why this simple code should not work on Arduino DUE?
#define SS_PIN 10
#define MOSI_PIN 11
#define MISO_PIN 12
#define CLK_PIN 13
void setup() {
pinMode(SS_PIN, OUTPUT);
pinMode(MOSI_PIN, OUTPUT);
pinMode(MISO_PIN, INPUT);
pinMode(CLK_PIN, OUTPUT);
digitalWrite(SS_PIN, HIGH);
Serial.begin(115200);
}
void SS_HIGH(){
delayMicroseconds(4);
digitalWrite(SS_PIN,HIGH);
}
void CLK_HIGH(){
digitalWrite(CLK_PIN,HIGH);
}
void MOSI_HIGH(){
digitalWrite(MOSI_PIN, HIGH);
}
void sendByte(byte data){
CLK_LOW();
for (int i=7; i>=0; i--){
CLK_LOW();
delay(1);
if (bitRead(data,i)){
MOSI_HIGH();
}
else {
MOSI_LOW();
}
CLK_HIGH();
delay(1);
}
CLK_LOW();
}
byte receiveByte(){
byte data = 0;
SS_LOW();
for (int i=7; i>=0; i--){
CLK_LOW();
delay(1);
bitWrite(data,i,(digitalRead(MISO_PIN)));
CLK_HIGH();
delay(1);
}
SS_LOW();
Serial.print(data,BIN); //for debug
return data;
}
void SS_LOW(){
digitalWrite(SS_PIN,LOW);
delayMicroseconds(1);
}
void CLK_LOW(){
digitalWrite(CLK_PIN,LOW);
}
void MOSI_LOW(){
digitalWrite(MOSI_PIN, LOW);
}
void loop() {
SS_LOW();
sendByte(B00000011);
sendByte(B00000000);
sendByte(B00000001);
for (int i=0; i<=2047; i++){
byte data = receiveByte();
}
Serial.println(" "); //for debug
SS_HIGH();
delay(40);
}
To be more precise, if I connect the oscilloscope to pins 10 11 12 13, on Arduino DUE the only thing I can see is pin 13 (CLK_PIN), the others do not "move".
sketch_aug08a.ino (1.29 KB)