B4R Question rWire

newbie

Member
Licensed User
i want to translate this simple Sub from Arduino sketch
B4X:
void myRtcGet()
{ byte rSec, rMin, rHour, rDOW, rDay, rMonth, rYear;

  Wire.beginTransmission(DS3231_I2C_ADDRESS);  // Open I2C line in write mode
  Wire.write(0x00);  // Set the register pointer to (0x00)
  Wire.endTransmission();  // End Write Transmission

  Wire.requestFrom(DS3231_I2C_ADDRESS, 7);  // Open the I2C line in send mode

  rSec  = bcdToDec(Wire.read() & 0x7f); // Read seven bytes of data
  rMin  = bcdToDec(Wire.read());
  rHour  = bcdToDec(Wire.read() & 0x3f);  
  rDOW  = bcdToDec(Wire.read());
  rDay  = bcdToDec(Wire.read());
  rMonth  = bcdToDec(Wire.read());
  rYear  = bcdToDec(Wire.read());
  setTime(rHour,rMin,rSec,rDay,rMonth,rYear);
}
to b4r, why does it not work ????
B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'Public variables can be accessed from all modules.
   Private w1 As WireMaster
   Private w1Adress As Int = 0x68
End Sub

Sub GetClockData
  Log("Init Ds3231")
  w1.Initialize
  w1.WriteTo(w1Adress,Array As Byte(0, 0))
   
  Dim data() As Byte = w1.RequestFrom(w1Adress,7)
  If data.Length = 7 Then  
  Log("Data:",(data))
  Else
  Log("Missing data...")
    Log("Data:",(data))
  End If
End Sub
thanks for any help
 

Cableguy

Expert
Licensed User
[QUOTE=" why does it not work ??[/QUOTE]

In what way does it not work? Have you tried to log the received Data before the "if Data.length = 7" just to see if any data is coming through?
 
Upvote 0
Top