I am trying to read the values of temperature register 0x11 but in return I am getting 0.
But the datasheet says that if there is no data it will return the register's address.
Below is the code I am using
#include<SPI.h>
SPISettings setting(10000000, MSBFIRST, SPI_MODE0);
int SS_PIN = 5;
void setup()
{
Serial.begin(9600);
pinMode(SS_PIN, OUTPUT);
SPI.begin();
}
void loop()
{
SPI.beginTransaction(setting);
//digitalWrite(SS_PIN, LOW);
//SPI.transfer(0x64);
int Data = read8bits(0x11);
Serial.println();
Serial.print("Temp register data: -");
Serial.print(Data);
}
int read8bits(byte regs)
{
int val;
digitalWrite(SS_PIN, LOW);
delay(10);
SPI.transfer(regs);
delay(1);
val = SPI.transfer(0);
delay(1);
digitalWrite(SS_PIN, HIGH);
return val;
}
I want to read data of the registers of ADE7758.
I don't want to use the ADE7758 library.
Hi there!
According to the following article, the transfer() function will return a value after the argument is sent over the bus. With "SPI.transfer(0);" you are sending the value zero via the bus, and what you are getting back is a zero.
Perhaps, and this may be completely wrong, is there enough time for the first transfer to complete before the next one starts? Perhaps increase the 1ms delays to 5ms and see what difference that could make.
As an additional check, add a variable to see what is returned from the "SPI.transfer(regs);" and see what that variable reads.
gauravntpl:
I don't want to use the ADE7758 library.
I'm not familiar with that device, nor its library. But, if there is a library, it presumably comes with example code. I'd first try running those examples to make sure the hardware setup is working. Then, if that's successful, just look at the library's source code to see how it communicates with the device. Write your library-free code using the same techniques. Why work so hard to develop the right techniques when someone else already has?