FM-test

Dependencies:   MODSERIAL mbed-rtos mbed

Fork of Master by Ohnishi_Gundan

Committer:
9uS7
Date:
Thu Sep 11 14:42:49 2014 +0000
Revision:
1:e1cfb5850088
Parent:
0:4f07ba929908
Child:
2:c610e1a7fbcd
can compile

Who changed what in which revision?

UserRevisionLine numberNew contents of line
9uS7 0:4f07ba929908 1 #include "mbed.h"
9uS7 0:4f07ba929908 2 #include "fm.h"
9uS7 0:4f07ba929908 3
9uS7 0:4f07ba929908 4
9uS7 1:e1cfb5850088 5 I2C i2c(p9,p10); // SDA,SCI
9uS7 1:e1cfb5850088 6
9uS7 0:4f07ba929908 7 void i2cSetup(unsigned int _f)
9uS7 0:4f07ba929908 8 {
9uS7 1:e1cfb5850088 9 char freqH = 0, freqL = 0;//, c, i;
9uS7 1:e1cfb5850088 10 unsigned int frequencyB, freq, freqB;
9uS7 1:e1cfb5850088 11 const int addr = 0x11 << 1;
9uS7 1:e1cfb5850088 12
9uS7 0:4f07ba929908 13 freq = _f; //freq/10.MHz 760~910
9uS7 0:4f07ba929908 14 if(freq > 870){
9uS7 0:4f07ba929908 15 freqB = freq - 870;
9uS7 0:4f07ba929908 16 freqH = freqB>>2;
9uS7 0:4f07ba929908 17 freqL = (freqB&3)<<6; // Shift channel selection for matching register 0x03
9uS7 0:4f07ba929908 18 }else{
9uS7 0:4f07ba929908 19 freqB = freq-760;
9uS7 0:4f07ba929908 20 freqH = freqB>>2;
9uS7 0:4f07ba929908 21 freqL = (freqB&3)<<6;
9uS7 0:4f07ba929908 22 }
9uS7 0:4f07ba929908 23
9uS7 0:4f07ba929908 24 i2c.start();
9uS7 0:4f07ba929908 25 i2c.write(addr);
9uS7 0:4f07ba929908 26 i2c.write(0x02);
9uS7 0:4f07ba929908 27 i2c.write(0xC0);
9uS7 0:4f07ba929908 28 i2c.write(0x03);
9uS7 0:4f07ba929908 29 i2c.stop();
9uS7 0:4f07ba929908 30 wait(0.5); // wait 500ms
9uS7 0:4f07ba929908 31
9uS7 0:4f07ba929908 32 i2c.start();
9uS7 0:4f07ba929908 33 i2c.write(addr);
9uS7 0:4f07ba929908 34 i2c.write(0x02);
9uS7 0:4f07ba929908 35 i2c.write(0xC0);
9uS7 0:4f07ba929908 36 i2c.write(0x0D);
9uS7 0:4f07ba929908 37 i2c.stop();
9uS7 0:4f07ba929908 38 wait(0.5);
9uS7 0:4f07ba929908 39
9uS7 0:4f07ba929908 40 if(freq > 870){
9uS7 0:4f07ba929908 41 freqL=freqL | 0x10;
9uS7 0:4f07ba929908 42 }else{
9uS7 0:4f07ba929908 43 freqL=freqL | 0x14;
9uS7 0:4f07ba929908 44 }
9uS7 0:4f07ba929908 45 i2c.start();
9uS7 0:4f07ba929908 46 i2c.write(addr);
9uS7 0:4f07ba929908 47 i2c.write(0x03);
9uS7 0:4f07ba929908 48 i2c.write(freqH);
9uS7 0:4f07ba929908 49 i2c.write(freqL);
9uS7 0:4f07ba929908 50 i2c.stop();
9uS7 0:4f07ba929908 51 wait(0.5);
9uS7 0:4f07ba929908 52
9uS7 0:4f07ba929908 53 char temp0 = 0x00;
9uS7 0:4f07ba929908 54 char temp1 = 0x00;
9uS7 0:4f07ba929908 55 i2c.read(addr,&temp0,1);
9uS7 0:4f07ba929908 56 i2c.read(addr,&temp1,1);
9uS7 0:4f07ba929908 57 temp0 &= 0xff;
9uS7 0:4f07ba929908 58 temp1 &= 0xf0;
9uS7 0:4f07ba929908 59 temp0 |= 0x00;
9uS7 0:4f07ba929908 60 temp1 |= 0x01;
9uS7 0:4f07ba929908 61 i2c.start();
9uS7 0:4f07ba929908 62 i2c.write(addr);
9uS7 0:4f07ba929908 63 i2c.write(0x40);
9uS7 0:4f07ba929908 64 i2c.write(temp0);
9uS7 0:4f07ba929908 65 i2c.write(temp1);
9uS7 0:4f07ba929908 66 i2c.stop();
9uS7 0:4f07ba929908 67 wait(0.5);
9uS7 0:4f07ba929908 68
9uS7 0:4f07ba929908 69 i2c.start();
9uS7 0:4f07ba929908 70 i2c.write(addr);
9uS7 0:4f07ba929908 71 i2c.write(0x42);
9uS7 0:4f07ba929908 72 i2c.write(0x03);
9uS7 0:4f07ba929908 73 i2c.write(0x0F);
9uS7 0:4f07ba929908 74 i2c.stop();
9uS7 0:4f07ba929908 75
9uS7 0:4f07ba929908 76 wait(0.5);
9uS7 0:4f07ba929908 77 }