Hi.
I have written this code for I2C communication with a slave device.
It doesn't return anything if I run it as it is but if make this change Wire.requestFrom(DAC_REG0_1 ,3); which I think is the wrong thing to do somehow I get zero's on the serial terminal. Is there something I am missing.
Inside The control status reg (adress 0x40) contains the other register adresses (DAC_REG0_1 0x30 etc..) I am trying to read the contents of these adresses.
Code:
#include <Wire.h>
int CONTROL_STATUS_REGISTER = 0x40; /* reg adress */
#define DAC_REG0_1 0x30
#define PADC_DATA1 0x22
#define MICRO_INTERFACE_CONTROL 0x0C
int DACREG0;
int PADCDATA;
int MIC;
void setup()
{
Wire.begin(); /*INITIATE WIRE LIBRARY*/
Serial.begin(9600); /*INITIATE SERIAL COM */
delay(1000);
}
void loop()
{
/*begin transmission to cntrl status reg*/
Wire.beginTransmission(CONTROL_STATUS_REGISTER);
/*ask the particular register for data*/
Wire.requestFrom(CONTROL_STATUS_REGISTER,3);/*request the transmitted data...the 3 bytes from the 3 registers*/
if(Wire.available())/* Wire.available returns numnber of bytes available for retreval*/
{
DACREG0 = Wire.read()<=3; /* ..if it matches with 3 wire.read will read the 3 bytes*/
PADCDATA = Wire.read();
MIC = Wire.read();
}
Serial.print("DACREG0= ");
Serial.print(DACREG0);
Serial.print(" PADCDATA= ");
Serial.print(PADCDATA);
Serial.print(" MIC= ");
Serial.println(MIC);
delay(1000);
}