1

I am using I2C communications to control a AD5694RBRUZ (http://www.analog.com/media/en/technical-documentation/data-sheets/AD5696R_5695R_5694R.pdf) with my Arduino Nano. If i enter two bytes it wil Wire.write only the first line from top to bottom. In the datasheet it is shown that you muust first fill the command byte, then the high and last the low byte. How can i fill the low byte? I have now scraped the idea to input two bytes separately and decided to input one uint16_t byte. How do i fill the low byte at the same time as the high byte, or if it possible how to input the uint16_t value?

My code is as follows:

#include <Wire.h>
#define Address 0x0D
void setup()
{
Serial.begin(9600);
Wire.begin();
AddressWrite(0x3F,0x05B0);
Serial.print ("Biti = ");
Serial.println (AddressRead(0x01));
}
void loop()
{
}
void AddressWrite (byte Naslov, uint16_t Cifra1)
{
byte Hi, Lo;
Hi = highByte(Cifra1);
Lo = lowByte(Cifra1);
Wire.beginTransmission(Address);
Wire.write(Naslov);
Wire.write(Cifra1);
Wire.endTransmission();
Serial.print ("Biti Hi = ");
Serial.println (Hi);
Serial.print ("Biti Lo = ");
Serial.println (Lo);
Serial.print ("Biti Cifra = ");
Serial.println (Cifra1);
}
byte AddressRead (byte naslov)
{
Wire.beginTransmission(Address);
Wire.write(naslov);
Wire.requestFrom(Address,2);
while(!Wire.available())
 {
 }
return Wire.read();
}

Thank you for your time and help.

asked Sep 26, 2017 at 7:09

1 Answer 1

0

You can use a number of Wire.write to write data. The AD5694R should get three bytes and two bytes can be read from it. There is a "multiple dac readback sequence", but that is an extra.

Your AddressWrite requires an extra Wire.write.
Your AddressRead is missing a Wire.endTransmission and the while(!Wire.available()) should be removed.

void AddressWrite (byte Naslov, uint16_t Cifra1)
{
 byte Hi, Lo;
 Hi = highByte(Cifra1);
 Lo = lowByte(Cifra1);
 Wire.beginTransmission(Address);
 Wire.write(Naslov); // command byte
 Wire.write(Hi); // msb first
 Wire.write(Lo); // lsb second
 Wire.endTransmission();
}
uint16_t AddressRead (byte naslov)
{
 Wire.beginTransmission(Address);
 Wire.write(naslov); // command byte
 Wire.endTransmission(false); // repeated start
 uint16_t hi, lo, result;
 Wire.requestFrom(Address,2);
 hi = Wire.read();
 lo = Wire.read();
 result = word(hi,lo); 
 return result;
}

I have added a repeated start, because that is according to the datasheet.

Could you make the names more according to the datasheet ? For example 'command' or 'commandByte' instead of 'Naslow'. And perhaps better names for the functions, for example 'writeAD5694R' instead of 'AddressWrite'.

answered Sep 26, 2017 at 7:52
1
  • Thank you hor the help may good man. The names have been decided by my boss, but i will inform him of your words of wisdom. Oh and one more thing. MAY YOUR BLOOD LINE LAST A 1000 YEARS. THANK YOU MY HERO!!! Commented Sep 26, 2017 at 7:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.