View previous topic :: View next topic |
Author |
Message |
bzuidgeest
Joined: 07 Jan 2005 Posts: 3
|
tea5767 help needed |
Posted: Fri Jan 07, 2005 3:52 pm |
|
|
Hi all,
I need some help controlling a philips tea5767 chip. This is a fm radio ic that can be completely controlled by i2c. When writing to it everything seems to work. It seem to get ack's. so something seems to be listening. Because I don't get any audio signal from it, I want to read some data from this chip. Unfortunately the only thing I get back are zero's. So I'll post my code and hope anybody here got some insights/experience on this chip.
As a side note: the datasheet says bytes should be transmitted MSB first. Is this what the i2c_write function is doing?? It doesn't say in the help file.
bart
Code: |
#include <16f877.h>
#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use rs232(baud=9600, xmit=PIN_C6,rcv=PIN_C7)
#use I2C(master, slow, sda=PIN_C1, scl=PIN_C2)
// radio stuff
void radioInit(void);
//void radioSearchUp(void);
//void radioSearchDown(void);
void radioStatus(void);
void main()
{
SET_TRIS_B(0x00);
OUTPUT_B(0x00);
delay_ms(100);
SET_TRIS_D(0x00);
OUTPUT_D(0x00);
printf("1.1\n\r");
radioInit();
while (1)
{
radioStatus();
// heartbeat led on
output_high(PIN_B4);
//delay_ms(100);
// heartbeat led off
//output_low(PIN_B4);
//delay_ms(100);
}
}
radioInit()
{
i2c_start(); // Start condition
printf("\n\rstart");
while(i2c_write(0xC0));// Device address
printf("\n\raddress");
while(i2c_write(0x1F));
printf("\n\r byte1");
while(i2c_write(0x7C));
printf("\n\r byte2");
while(i2c_write(0x30));
printf("\n\r byte3");
while(i2c_write(0x00));
printf("\n\r byte4");
while(i2c_write(0x00));
printf("\n\r byte5");
i2c_stop(); // Stop condition
printf("\n\rstop");
delay_ms(50);
}
radioStatus()
{
int data;
printf("\n\rR");
i2c_start(); // Start condition
i2c_write(0xC1);// Device address
data = i2c_read();
printf("\r\n%U", data);
data = i2c_read();
printf("\r\n%U", data);
data = i2c_read();
printf("\r\n%U", data);
data = i2c_read();
printf("\r\n%U", data);
data = i2c_read();
printf("\r\n%U", data);
i2c_stop(); // Stop condition
}
|
|
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Fri Jan 07, 2005 4:08 pm |
|
|
The last call to i2c_read() before the i2c_stop() statement
must have a 0 parameter. Example:
i2c_read();
i2c_read();
i2c_read(0); // Last call does a NAK |
|
|
bzuidgeest
Joined: 07 Jan 2005 Posts: 3
|
|
Posted: Sat Jan 08, 2005 8:35 am |
|
|
Ok I changed the last i2c_read() statement to i2c_read(0); But I'm still receiving only zero's back. |
|
|
Ttelmah Guest
|
|
Posted: Sat Jan 08, 2005 10:53 am |
|
|
Yes, the internal I2C, does send MSB first. This is 'standard' for I2C, and is shown in the chip's data sheet, if you look at the timing diagrams.
You could try waiting for the address to be acknowledged on the read, as you do on the write.
Best Wishes |
|
|
Kenny
Joined: 07 Sep 2003 Posts: 173 Location: Australia
|
|
Posted: Sun Jan 09, 2005 1:16 am |
|
|
The code looks OK, although I haven't used this chip.
It looks like the writes were unsuccessful. First thing I would try is to remove all the printf
statements - instead, in the read operation save the bytes into an array and output them after the i2c_stop().
Some things to check:
1. Bus Enable pin set high for at least 10uS before write or read operation (or tied high permanently).
2. Bus Mode pin tied low to select i2c instead of 3-wire interface.
3. i2c bus pullups in the range 2k2 to 4k7.
4. If possible, check waveforms with an oscilloscope.
5. Test the write operation as follows:
Check that the SWP1 and SWP2 pins can be be set high and low by setting and clearing SWP1 (bit 0 of byte 3)
and SWP2 (bit 7 of byte 4) respectively. There needs to be 10k pullups on these pins as shown in the test schematic,
and SI (bit 0 of of byte 4) needs to be cleared for this to work.
If this works then the write operation was successful, and the read operation should work.
HTH |
|
|
bzuidgeest
Joined: 07 Jan 2005 Posts: 3
|
|
Posted: Sun Jan 09, 2005 5:20 am |
|
|
Hi kenny,
I had not considered testing the way you subscribe in point 5. Exelent idea! I considered the writes to be working because the bytes i send get acknoledged. It's the reason there are while statements around all i2c_write statements. I will also follow up on Ttelmah's idea.
Hope it works,
bart |
|
|
|