Hi All,
I have a CERES PCB. And i need to communicate with the PCB using SPI bus. The problem is I very low on knowledge regarding any types of communication. Below is the command list i need to do. I have practice the SPI code with only 1 data transfered to Slave. But when i try to do on my actual project, I'm become confused with the Address, MOSI cmd+add. I dont know which data need to be send and how.
I tried to play around but i keep getting rubbish data
My code:
#include <SPI.h>
const int chipSelectPin = 10;
void setup() {
Serial.begin(9600);
pinMode(chipSelectPin, OUTPUT);
SPI.begin();
SPI.beginTransaction(SPISettings(16000000, MSBFIRST, SPI_MODE0));
byte commandSelAdc2Vdd[] = {0x40, 0x84, 0x00, 0x00, 0x02, 0x00};
byte commandEnAcd2[] = {0x40, 0x24, 0x00, 0x20, 0x00, 0x00};
byte commandReadAcd2[] = {0x00, 0x14, 0x00, 0x00, 0x00, 0x00};
byte* commands[] = {commandSelAdc2Vdd, commandEnAcd2, commandReadAcd2};
int numCommands = sizeof(commands) / sizeof(commands[0]);
for (int i = 0; i < numCommands; i++) {
digitalWrite(chipSelectPin, LOW);
SPI.transfer(commands[i], sizeof(commandSelAdc2Vdd));
digitalWrite(chipSelectPin, HIGH);
delay(100);
digitalWrite(chipSelectPin, LOW);
byte response[4];
SPI.transfer(response, sizeof(response));
digitalWrite(chipSelectPin, HIGH);
Serial.print("Response for Command ");
if (i == 0)
{
Serial.print("commandSelAdc2Vdd: ");
} else if (i == 1)
{
Serial.print("commandEnAcd2: ");
}else{
Serial.print ("commandReadAcd2: ");
}
for (int j = 0; j < 4; j++) {
Serial.print(response[j],HEX);
Serial.print(" ");
}
Serial.println();
delay(500);
}
}
void loop() {
}