Thread: Arduino - Reading data from slave

  1. #1
    Registered User
    Join Date
    Sep 2017
    Posts
    1

    Arduino - Reading data from slave

    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);
    }
    Last edited by kevnas1; 09-13-2017 at 07:05 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with reading a photoresistor from an Arduino Uno
    By echo225 in forum C++ Programming
    Replies: 5
    Last Post: 09-29-2016, 07:16 PM
  2. GPS data arduino
    By DA93 in forum C Programming
    Replies: 0
    Last Post: 03-24-2016, 08:47 AM
  3. Replies: 0
    Last Post: 05-05-2015, 08:14 PM
  4. Reading button input on Arduino board
    By jimbolad in forum C Programming
    Replies: 5
    Last Post: 03-08-2013, 01:19 AM
  5. No slave disks in LA.
    By adrianxw in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 11-30-2003, 12:00 PM

Tags for this Thread