|
|
View previous topic :: View next topic |
Author |
Message |
Skirmitt
Joined: 19 May 2009 Posts: 60
|
TEA5767 basic program |
Posted: Thu Dec 01, 2011 9:16 am |
|
|
I received a TEA5767 module today. This is a FM Radio chip that communicates through i2c. First I want to make a basic program that works to test the module itself. I have pullups 4K7 on the SDA and SCL lines. I don't get anything out of it.
Datasheet: http://www.sparkfun.com/datasheets/Wireless/General/TEA5767.pdf
Code: |
#include <16F886.h>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOLVP
#use delay(clock=4000000)
#define DAL_SCL PIN_C3
#define DAL_SDA PIN_C4
#use i2c(master, slow, sda=DAL_SDA, scl=DAL_SCL)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
unsigned char frequencyH=0;
unsigned char frequencyL=0;
unsigned int frequencyB;
double frequency=0;
void main()
{
delay_ms(2000);
frequency=91.3; //starting frequency
frequencyB=4*(frequency*1000000+225000)/32768; //calculating PLL word
frequencyH=frequencyB>>8;
frequencyL=frequencyB&0XFF;
i2c_start();
i2c_write(0x60); //adres om te schrijven
i2c_write(frequencyH);
i2c_write(frequencyL);
i2c_write(0xB0);
i2c_write(0x10);
i2c_write(0x00);
i2c_stop();
}
|
Has anyone something that does work or am I doing something very wrong here ? |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19549
|
|
Posted: Thu Dec 01, 2011 10:11 am |
|
|
Double check the I2C address. It is _not_ 0x60.
Historically, I2C, has a _seven bit_ address, left shifted by one, with the R/W bit below this. Microchip, together with a lot of other manufacturers give the 8bit value that results. However if you look at the data sheet for this device, the address is given as a 7bit value. So the 'PIC format' address for this device, is 0xC0 for write, and 0xC1 for read. Look at table4 in the data sheet, which shows this.
Comments:
The PIC16 chips, don't have a double data type. Does nothing, same as float...
FrequencyB is an 8bit value (remember an INT in CCS is 8bit). Shift this right 8bits, and you have nothing.... FrequencyB _needs_ to be declared as an int16.
Best Wishes |
|
|
Skirmitt
Joined: 19 May 2009 Posts: 60
|
|
Posted: Thu Dec 01, 2011 10:26 am |
|
|
Just found that out, I based the code on an Arduino sample I found.
This works great now:
Code: |
frequency=102.1*1000000; //starting frequency
frequencyB=(4*(frequency+225000))/32768; //calculating PLL word
frequencyH=frequencyB>>8;
frequencyL=frequencyB&0XFF;
i2c_start();
i2c_write(0xC0); //adres om te schrijven
i2c_write(frequencyH);
i2c_write(frequencyL);
i2c_write(0xB0);
i2c_write(0x10);
i2c_write(0x00);
i2c_stop();
|
|
|
|
Skirmitt
Joined: 19 May 2009 Posts: 60
|
|
Posted: Fri Dec 02, 2011 1:59 am |
|
|
Oh and thanks for letting me this know:
Quote: | The PIC16 chips, don't have a double data type. Does nothing, same as float... |
I didn't know that ! |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|