Show Posts
|
|
Pages: [1] 2 3
|
|
1
|
Using Arduino / Networking, Protocols, and Devices / Re: RDA5807SP FM Radio Receiver - i2C
|
on: May 01, 2012, 07:25:16 pm
|
I see what you're referencing.... but I'm not sure I understand how to implement it. How does it know what register I'm trying to write to if I don't specify the address? When reading use an address byte. When writing do not use an address byte.
The following snip-it works: '========================[Write/Read data to/from FM module ]===================== Write_ConfigRegs: ' Write Data to Configure Registers I2COUT SDA, WrFM, [Conf2.Highbyte, Conf2.Lowbyte, Conf3.Highbyte, Conf3.Lowbyte, Conf4.Highbyte, Conf4.Lowbyte, Conf5.Highbyte, Conf5.Lowbyte, Conf6.Highbyte, Conf6.Lowbyte] RETURN
Read_Status: I2CIN SDA, RdFM, 0, [Status1,Status2,status3,status4] DEBUG CRSRXY,10,1,"Status : ", HEX2 status1, " ", HEX2 status2, " ", HEX2 status3, " ", HEX2 status4, " " RETURN '================================================= =========================
|
|
|
|
|
2
|
Using Arduino / Networking, Protocols, and Devices / Re: RDA5807SP FM Radio Receiver - i2C
|
on: April 29, 2012, 09:19:08 pm
|
Yep I added some serial debug to tell me if things fail...Take a look, maybe my error handling has an error  Current state of code: #include <Wire.h>
int device_address = 17; 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); byte val_hi = 0x88; // 10001000 byte val_lo = 0xA8; // 10101000 Wire.write(val_hi); // hi byte Wire.write(val_lo); // lo byte Wire.endTransmission(); if (Wire.endTransmission() != 0) { Serial.println("Error on TX"); // error message return; } }
void getVolume(){ Wire.beginTransmission(device_address); Wire.write(5); Wire.endTransmission(); Wire.requestFrom(device_address, 2); Wire.endTransmission(); if (Wire.requestFrom(device_address, 2) != 2) { Serial.println("Error in RX"); //error message return; } byte byte1 = Wire.read(); byte byte2 = Wire.read();
Serial.print("The currnet volume setting is: "); Serial.print(byte1, BIN); Serial.print(":"); Serial.println(byte2, BIN); }
|
|
|
|
|
3
|
Using Arduino / Networking, Protocols, and Devices / Re: RDA5807SP FM Radio Receiver - i2C
|
on: April 29, 2012, 08:49:08 pm
|
When I try 16 (0x10) I get 00000001 00111111. I get the same result after a 'set' When I try 17 (0x11) I get 11111111 11111111. I get the same result after a 'set'. This is what clued me in initially that I should use the third address. So I've clearly picked an oddball piece of hardware, ehh?  lol What I wish I could do is really 'see' the bitstream as I run the routine. See what crosses the bus, and see what comes back. I guess I just don't trust it until I prove it. But that's just me ranting about not believing what I'm seeing 
|
|
|
|
|
4
|
Using Arduino / Networking, Protocols, and Devices / Re: RDA5807SP FM Radio Receiver - i2C
|
on: April 29, 2012, 08:09:44 pm
|
I also added in the error handling stuff - I'm not getting errors either way, so I believe that we're getting a return of 0 indicating success, and I also believe we're getting 2 bytes back, as we should. Something you said earlier has me a bit confused After staring at it for a while I think they are saying that the device address is in fact the register. So, for example, say we want to set some bits in register 2:
Yes there are multiple registers. of Primary interest to me is Register 2, 3,4,5,10, and 11. But I believe it's using a standard i2c style address (we see 3 devices in a bus scan).
|
|
|
|
|
5
|
Using Arduino / Networking, Protocols, and Devices / Re: RDA5807SP FM Radio Receiver - i2C
|
on: April 29, 2012, 08:00:36 pm
|
Running the scanner produces the following ( I used a similar script when I was getting started, thats how I was able to get the device address to begin with...... I have no idea why 3 devices are showing up, this is a single device). I2C scanner. Scanning ... Found address: 16 (0x10) Found address: 17 (0x11) Found address: 96 (0x60) Done. Found 3 device(s).
As far as the while loop goes - I haven't noticed anything 'breaking' regardless of how that was set, so I haven't really focused there yet. As far as the values go.... I try and set this byte val_hi = 0x88; // 10001000 byte val_lo = 0xA8; // 10101000 but I get this back The currnet volume setting is: 1110:11100000 (Leading zeroes supressed, I assume). So sent vs rcvd TX - 1000100010101000 RX - 0000111011100000 Somehow I missed your error handling comments from before - I'm going to try those now, they look useful.
|
|
|
|
|
6
|
Using Arduino / Networking, Protocols, and Devices / Re: RDA5807SP FM Radio Receiver - i2C
|
on: April 29, 2012, 07:39:44 pm
|
I am so totally banging my head against the wall on this. I've learned quite a bit (I think) from the comments thus far, I think I get the jist of what is supposed to be happening here..... but its not happening that way. For example: I'm structuring two bytes byte val_hi = 0x88; // 10001000 byte val_lo = 0xA8; // 10101000
I send them Wire.beginTransmission(device_address); Wire.write(5); Wire.write(val_hi); // hi byte Wire.write(val_lo); // lo byte Wire.endTransmission();
And when I read them back void getVolume(){ Wire.beginTransmission(device_address); Wire.write(5); Wire.endTransmission(); Wire.requestFrom(device_address, 2); Wire.endTransmission();
while (Wire.available() < 2); byte byte1 = Wire.read(); byte byte2 = Wire.read();
// 10001000 10101111
Serial.print("The currnet volume setting is: "); Serial.print(byte1, BIN); Serial.print(":"); Serial.println(byte2, BIN);
I get this The currnet volume setting is: 1110:11100000 (Leading zeroes supressed, I assume). So WTF. I set a value, I read it, and I get something totally different back. Complete current code for reference... Some garbage still in there of course #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); byte val_hi = 0x88; // 10001000 byte val_lo = 0xA8; // 10101000 Wire.write(val_hi); // hi byte Wire.write(val_lo); // lo byte Wire.endTransmission();
}
void getVolume(){ Wire.beginTransmission(device_address); Wire.write(5); Wire.endTransmission(); Wire.requestFrom(device_address, 2); Wire.endTransmission();
while (Wire.available() < 2); byte byte1 = Wire.read(); byte byte2 = Wire.read();
// 10001000 10101111
Serial.print("The currnet volume setting is: "); Serial.print(byte1, BIN); Serial.print(":"); Serial.println(byte2, BIN); }
|
|
|
|
|
7
|
Using Arduino / Networking, Protocols, and Devices / Re: RDA5807SP FM Radio Receiver - i2C
|
on: April 29, 2012, 02:00:07 pm
|
|
Ok so after reviewing the binary math stuff, I think I get it. SO let me ask you this.... I probably want to read the register, store the result, perform a binary OR against the data, adding the bits I want to change, and then push the whole string back out , correct? There's nothing that's going to let me just send selected bits over I2C is there? Just making sure, but I think I need to be sending the whole byte(s).
Josh
|
|
|
|
|
12
|
Using Arduino / Networking, Protocols, and Devices / Re: RDA5807SP FM Radio Receiver - i2C
|
on: April 29, 2012, 07:54:07 am
|
The chip is the same as the FM receiver that Parallax sells, so I've been using their datasheet and example code as reference. http://www.parallax.com/portals/0/downloads/docs/prod/audiovis/27984-FM-RadioReceiver-v1.0.pdfhttp://www.parallax.com/portals/0/downloads/docs/prod/audiovis/ParallaxFMRadio-spin.zipSome additional things I don't quite 'get' .... When I send a bitstream to try and write the register, do I send it with bit 7 first, then 6, 5, etc (like you'd write it in binary on paper) or does it go LSB first (unlike how you'd write it on paper). Do I have to send it one byte at a time, or can I send the full two bytes at once? I think if I can get my arms around the proper way to read and write the registers, I'll be home free. Thx
|
|
|
|
|
13
|
Using Arduino / Networking, Protocols, and Devices / Re: RDA5807SP FM Radio Receiver - i2C
|
on: April 28, 2012, 11:26:39 pm
|
|
My timing must be lucky - I was getting both bytes in time... but your recommended modification is certainly a good idea, I've implemented it. So the fact remains, when I set the values, and then try to read them, they come back different. I think this is more than likely a learning curve issue... I've gotta be doing something wrong.
|
|
|
|
|
14
|
Using Arduino / Networking, Protocols, and Devices / RDA5807SP FM Radio Receiver - i2C
|
on: April 28, 2012, 11:09:31 pm
|
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); }
|
|
|
|
|