I've been pounding at this all day, and I'm missing something. If somebody can point my nose I would appreciate it.
I picked up a couple of RDA5807SP I2C based FM Radio Receiver IC's off the FleaBay a few days ago. They came in the mail, and I'm anxious to hook them up to my arduino. They're I2C controlled, they have a couple of registers storing what looks like 2 bytes of data each, and we can manipulate these registers to control the radio. I'm fairly new to I2C, but starting to get my feet wet, and I just can't seem to get the hang of the appropriate read/write on this thing. I write values to the registers, but when I read them back, they're different from what I wrote. I'm not sure where to go from here.
See my attached code.
So for example, lets say I want to write the register at 0x05, and set bits 0-3 as the value 1 (forget the other bits, they're not important yet), I'm doing whats shown below. But its not working. When I read it back, its not how I set it. What am I doing wrong?
#include <Wire.h>
int device_address = 96;
int seekPin = 12;
int seekPinState = 0;
void setup(){
pinMode (seekPin,INPUT);
Wire.begin();
Serial.begin(9600);
getVolume();
maxVolume();
getVolume();
}
void loop(){
Serial.print("Device addres is: ");
Serial.println(device_address);
seekPinState = digitalRead(seekPin);
if (seekPinState == 1) {
Serial.println("High!");
}
getVolume();
delay(5000);
}
void maxVolume(){
Serial.println("Setting Volume");
Wire.beginTransmission(device_address);
Wire.write(5);
Wire.write(136); // first byte 10001000
Wire.write(175); // second byte 10101111 <-- This is the 1111 for the first 3 bits of the byte.
Wire.endTransmission();
}
void getVolume(){
Wire.requestFrom(device_address, 2);
while (Wire.available() == 0);
int byte1 = Wire.read();
int byte2 = Wire.read();
String binaryByte1 = String(byte1, BIN);
String binaryByte2 = String(byte2, BIN);
Serial.print("The currnet volume setting is: ");
Serial.print(binaryByte1);
Serial.print(":");
Serial.println(binaryByte2);
}