View previous topic :: View next topic |
Author |
Message |
einar
Joined: 27 Jan 2016 Posts: 3
|
BK1080+mcu |
Posted: Sun Jan 31, 2016 6:05 am |
|
|
Hi everyone,
want the BK1080 FM receiver to control by PIC mcu.
I know that to REG0 must be sent device ID byte, which is 0x80.
The REG1 is 7-bit start register address(0x20) + 0 for write.
Next are the BK1080 setting registers.
Code: |
i2c_start (0x20, 0);
i2c_write (0b00010010);i2c_write (0b00000001);//REG2
i2c_write (0b00000000);i2c_write (0b00000000);//REG3
|
and so on.
I'm very beginner in C, so I can't add right syntax to get it worked.
Found RDA5807M+PIC12F1822 project and it works ok.
with best regards |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9170 Location: Greensville,Ontario
|
|
Posted: Sun Jan 31, 2016 7:15 am |
|
|
general comments....
Whenever posting, you should post a 'link' to the device you're using as well as which PIC, compiler version and whether you're using real hardware(kit,PCB, etc) or a 'simulation'.
Most 'devices' or 'peripherals' these days are 3 volt devices and as such most do NOT directly interface to PICs running at 5 volts,so it is very important to tell us these details.
Also
Download the I2C scanner program from the code library and run it. It will confirm IF your PIC is connected to the I2C device and at what address.
You should do this whenever using I2C.
Also
Be sure to code+run a '1Hz LED' program. This will confirm the PIC and basic code does work for you. You'll never get programs to run right if the hardware isn't correct !
Jay |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19361
|
|
Posted: Sun Jan 31, 2016 9:01 am |
|
|
First thing is to prove your PIC is working as Temtronic says.
Then use the I2C scanner program in the code library, and see that the device is responding, and on what address it responds. You'll find it is _not_ 0x20.
In I2C, the general sequence is:
I2C_start
Send the _device_ address. (this is not 0x20).
Send the register address. (this is the one that is 0x20).
Then send data.
I2C_stop.
Now your device is 'unusual' in that the direction bit is sent with the register address. It is normally sent with the device address.
To read you do the first three operations above, with the read bit set to '1', then send another i2C_start, and then read the data (normally you should send NACK on the last byte), followed by stop.
So the third thing to do, is start sending the device address properly... |
|
![](templates/subSilver/images/spacer.gif) |
einar
Joined: 27 Jan 2016 Posts: 3
|
|
Posted: Mon Feb 01, 2016 1:59 pm |
|
|
hi, thanx for answers,
just wanted to say
i2c_start (0x20, 0);
i2c_write (0b00010010);i2c_write (0b00000001);//REG2
i2c_write (0b00000000);i2c_write (0b00000000);//REG3
works with RDA5807M FM chip + PIC12F1822 ok.
The BK1080 needs to add device ID (0x80) to REG0 first, but RDA5807M not.
The data registers are different of cource.
I'm using the same project as with RDA5807M, just BK1080 instead.
best regards |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19361
|
|
Posted: Mon Feb 01, 2016 2:36 pm |
|
|
You are wrong.
0x20, is the device address of the RDA5807M.....
_All_ I2C communications have to start with a device address. Otherwise you could not have multiple devices on the bus.
The address for each device is in the data sheet. Sometimes it is adjustable. |
|
![](templates/subSilver/images/spacer.gif) |
einar
Joined: 27 Jan 2016 Posts: 3
|
|
Posted: Mon Feb 01, 2016 5:05 pm |
|
|
sure, you are right.
so, it comes out like there are device address and register to start in one + write 0 bit 'i2c_start (0x20, 0)' ?
but, how to make, when device ID(address) is 0x80 and then start to write registers from REG2 ? |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9170 Location: Greensville,Ontario
|
|
Posted: Mon Feb 01, 2016 8:06 pm |
|
|
You really need to read the datasheet and application papers for your BK1080 chip. EVERY I2C device is NOT the same as any other. The mfr of the radio chip will explain in detail the steps needed to make it work, they will say what addresses ( registers) are to be used as well as what bit control 'this and that'.
You might want to Google the BK1080 to look at what others have done with it as you cannot be the only person using it. If you bought a premade module, the vendor may have application notes, a forum or other such site available.
Jay |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19361
|
|
Posted: Tue Feb 02, 2016 1:41 am |
|
|
The code being posted is from another compiler.
Some 'combine' sending the start with the address as one operation.
For 99% of devices this would be OK, and means one command instead of two. However there are things like 10bit addressed devices, where this would not work.
So, in CCS I2C is kept as separate entities, with each command corresponding exactly to a transaction on the I2C bus.
I2C_start
I2C_stop
I2C_write
I2C_read (with optional NACK)
The data transactions handle one byte each, so have to be repeated for all the bytes.
Read the I2C specification.
Then read the data sheet for the chip.
Then work out the sequence of operations needed to talk to the chip. |
|
![](templates/subSilver/images/spacer.gif) |
|