Hello
I am using Arduino UNO ( atmega32p), in I2C mode, and i am trying to communicate with an SPI accelerometer, and i have used SC18IS602 as an I2C to SPI converter.
///////// Just to inform everyone, I know that i can directly connect Arduino with an SPI device, But i want to communicate this way, its a project from my university///////
Every thing works fine in this code, the only problem is that i am not able to read the Buffer of SC18IS602 to read the data from my sensor.
I connected a scope to the MISO pin of my sensor and it is transmitting the data to the Bridge device but i am not able to read this data from arduino.
Here is my Code
#include <Wire.h>
char address = 0x28;
unsigned char regid1 = 0;
unsigned char regid2 =0;
unsigned char regid3 = 0;
unsigned char regid4 =0;
#define RESET_PIN 4
void setup() {
//Reset SC18
delay(5000);
pinMode(RESET_PIN,OUTPUT);
digitalWrite(RESET_PIN,HIGH);
delay(100);
digitalWrite(RESET_PIN,LOW);
delay(100);
digitalWrite(RESET_PIN,HIGH);
delay(1000); // Let the device to become stable
Serial.begin(9600);
Wire.begin();
/////////// SPI Configuration for Accelerometer /////////
Wire.beginTransmission(address);
Wire.write(0xf0);
Wire.write(0x02);
Wire.endTransmission();
delay(100);
////////////// Enable chip select pin and send some dummy data//////////////////
Wire.beginTransmission(address);
Wire.write(0x01); // CS0
Wire.write(0x06); // Dummy Data
Wire.endTransmission();
delay(100);
}
void loop() {
// Sending the read command to the Accelerometer
Wire.beginTransmission(address);
Wire.write(0x01); // Chip select SS0
Wire.write(0x80); // Accelerometer register ID with Read BIT
Wire.write(0x90); // Dummy Data
Wire.endTransmission();
/// Until this point my code is fine, as i can see the data on MISO using Osciloscope
// reading the buffer —>> This part is not working, i am not able to read the buffer , its printing FF or 00
Wire.requestFrom(address,byte(4));
regid1 = Wire.read();
regid2 = Wire.read();
regid3 = Wire.read();
regid4 = Wire.read();
Serial.print(regid1,HEX);
Serial.print("\n");
Serial.print(regid2,HEX);
Serial.print("\n");
Serial.print(regid3,HEX);
Serial.print("\n");
Serial.print(regid4,HEX);
Serial.print("\n");
}