# Understanding a datasheet.

I currently trying to i2c a synthersiser chip on a transmitter, but I cannot understand the datasheet at all.

I currently have this thread going http://arduino.cc/forum/index.php/topic,165805.0.html if you want to read the background on this post.

The chip im trying to control is http://datasheet.eeworld.com.cn/pdf/MITEL/86480_SP5055.pdf its not a big pdf file and the info required is on page 4,

I am talking to the chip but im not talking to it correctly.

``````void loop()
{

Wire.beginTransmission(0x61);
Wire.write(40);
Wire.write(40);
Wire.write(40);
Wire.write(10);

int r = Wire.endTransmission();

Serial.println(r)+'\n';
delay(550);
}
``````

The above code will set the transmitter to about 1285mhz. I know this is the wrong way to do talk to this chip but it seems to be the only way that's working for me.

The datasheet says "The programmed frequency can be calculated by multiplying the programmed division ratio by 16 times the comparison frequency Fcomp."

Fair enough, but how tdo I convert that to a byte (8bits).

Thanks.

Fair enough, but how tdo I convert that to a byte (8bits).

You split the 16 bit number into two bytes. When you talk to the chip you send five bytes at a time.

``````Upper = value >> 8;
Lower = value & 0xff;
``````

The datasheet says “The programmed frequency can be calculated by
multiplying the programmed division ratio by 16 times the
comparison frequency Fcomp.”

Your comparison frequency is Xtal/512 = for 4MHz crystal it is 7.8kHz

So your output frequency = DIVIDER * 16 * Xtal/512
DIVIDER (16bit unsigned) = frequency/(16*Xtal/512)

``````unsigned char byte2, byte3;
unsigned int divider;
unsigned long frequency;
unsigned long xtal;
...
divider = (frequency * 32L) / xtal ;
byte2 = (divider >> 8) & 0x7F;  //high byte
byte3 = divider & 0xff; //low byte
..
``````

A simple algorithm

Thanks pito I will give that a try.

Question, I have to send 5 bytes to this device to get it to do something, the first byte sent should be the address.
Is the Wire.begineTransmission(0x60); classed as the first byte?

Have tried the following code and still no joy …

``````void loop()
{
//Wire.beginTransmission(0x60);
unsigned char byte2, byte3;
unsigned int divider;
unsigned long frequency = 1248.500;
unsigned long xtal = 7.8;

divider = (frequency * 32L) / xtal ;
byte2 = (divider >> 8) & 0x7F;  //high byte
byte3 = divider & 0xff; //low byte

Wire.beginTransmission(0x61);
Wire.write(11000010);
Wire.write(byte2);
Wire.write(byte3);
Wire.write(11001110);
Wire.write(11001110);

int r = Wire.endTransmission();

Serial.println(r)+'\n';
delay(550);
}
``````

unsigned long frequency = 1248.500; unsigned long xtal = 7.8;

shall be:

``````unsigned long frequency = 1248500000;  // in Hz
unsigned long xtal = 4000000; // Xtal 4MHz in Hz
``````

or better

``````unsigned long frequency = 1248500;  // in kHz
unsigned long xtal = 4000; // Xtal 4MHz in kHz
``````

Wire.beginTransmission(0x61); Wire.write(11000010); Wire.write(byte2); Wire.write(byte3); Wire.write(11001110); Wire.write(11001110);

int r = Wire.endTransmission();

I think, based on the datasheet, you have to send 5bytes only:

``````Wire.beginTransmission(0x61);  // byte1 = address (7bit only) (11000010>>1)
Wire.write(byte2);
Wire.write(byte3);
Wire.write(B11001110); // byte4
Wire.write(B11001110); //byte5
int r = Wire.endTransmission();
``````

Pito, what can i say ... you are the best.

Just been back out to the workshop and tried your code, and it worked perfectly.

You have made me a very happy man tonight.

I would of never been able to work that out.

Thanks so much.

This compiles at least
It will increment the frequency by 1MHz each loop.

``````#include <Wire.h>

void setup() {
// put your setup code here, to run once:
Wire.begin(); // join i2c bus (address optional for master)
Serial.begin(115200);
}

void loop() {
// put your main code here, to run repeatedly:

unsigned char byte2, byte3;
unsigned int divider;

unsigned long freq_step = 1000; // in kHz

unsigned long frequency = 1248500;  // in kHz
unsigned long xtal = 4000; // Xtal 4MHz in kHz

while(1) {

divider = (frequency * 32L) / xtal ;
byte2 = (divider >> 8) & 0x7F;  // high byte
byte3 = divider & 0xff; // low byte

Wire.beginTransmission(0x61);  // byte1 = address (7bit only) (11000010>>1)
Wire.write(byte2); // byte2
Wire.write(byte3); // byte3
Wire.write(B11001110); // byte4
Wire.write(B11001110); // byte5
int r = Wire.endTransmission();

frequency = frequency + freq_step; //increment the frequency

Serial.print(r);
Serial.println("\n");
delay(2000);

}

}
``````

Pito, thanks for the second bit of code, will give it a try in the morning.

Will let you know if it works ok.

Thanks.

Pito, your scan code works perfectly.

Im currently adding a LCD and buttons to the project, these chips have a signal detector on them so i shall be adding a auto scan function to it as well now using your scan code.

I cannot thank you enough for your time helping me.

Once i have finished it, i will post the complete code on here.

Thankyou.