Hi,
I am new to arduino.
I want to print 24 bit value from an adc register .Will the following do?
//read adc register
byte High=SPI.transfer(0x00);
byte Middle=SPI.transfer(0x00);
byte low=SPI.transfer(0x00);
adcvalue=(High<<16) | (Middle<< 8 ) | (low);
Serial.print(adcvalue);
In the above,is it ensured that the most signigicant 8 bits will go to "High" variable.middle 8 bits to "Middle" variable and least significant 8 bits to "low" variable?
I am not getting the output.Now,when I try to read the id,the output is printed as 3,instead of 2.
My code to read AD7193 id is given below.
#include <SPI.h>
void setup()
{
Serial.begin(9600);
SPI.begin(4);
SPI.setClockDivider(4,21);
pinMode(4,OUTPUT);
}
void loop()
{
digitalWrite(4,LOW);
SPI.transfer(4,0x60,SPI_CONTINUE);//command for communication register to read id register
byte result = SPI.transfer(4,0x00,SPI_CONTINUE);//read id reg value
Serial.println(result&0x0F);//id is 2
delay(1000);
}
void loop()
{
digitalWrite(4,LOW);
SPI.transfer(4,0x60,SPI_CONTINUE);//command for communication register to read id register
byte result = SPI.transfer(4,0x00,SPI_CONTINUE);//read id reg value
Serial.println(result&0x0F);//id is 2
delay(1000);