Hello all,
I am a new arduino programmer and I've found the post about STEVAL-ISV009v1 via SPI
I copy the code but I don't understand somethings at Reply #8 and Reply #10 ,
Why do we need to convert the two values to an integer and we must to put the code at Reply #8 in the program?
Where do the code at Reply #10 put in?
Is the code right as below?
I hope to hear your reply soon.
Thanks,
Teechan
The code:
#include <SPI.h> // include the SPI library:
int slaveSelectPin = 10; // set pin 10 as the slave
void setup()
{
Serial.begin(9600);
pinMode (slaveSelectPin, OUTPUT); // set the slaveSelectPin as an output:
pinMode(SCK, OUTPUT);
pinMode(MOSI, OUTPUT);
digitalWrite(SCK, LOW);
digitalWrite(MOSI, LOW);
digitalWrite(slaveSelectPin, HIGH);
SPI.begin(); // initialize SPI:
SPI.setBitOrder(MSBFIRST);
}
void loop()
{
SPI.transfer(0x02); // shut down
SPI.transfer(0x03); // turn on
delay(100);
digitalWrite(slaveSelectPin,LOW);
byte Readspanning1 = SPI.transfer(0x05); // read spanning
byte Readspanning2 = SPI.transfer(0x01); // nop
byte Readspanning3 = SPI.transfer(0x01); // nop
digitalWrite(slaveSelectPin,HIGH);
Serial.print(" spanning = ");
Serial.print(Readspanning2);
Serial.print(" spanning1 = ");
Serial.print(Readspanning3);
}