Moran Z. / Si4703
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers SparkFun-Si4703.h Source File

SparkFun-Si4703.h

00001 /*
00002 Library for Sparkfun Si4703 breakout board.
00003 Simon Monk. 2011-09-09
00004 
00005 This is a library wrapper and a few extras to the excellent code produced
00006 by Nathan Seidle from Sparkfun (Beerware).
00007 
00008 Nathan's comments......
00009 
00010 Look for serial output at 57600bps.
00011 
00012 The Si4703 ACKs the first byte, and NACKs the 2nd byte of a read.
00013 
00014 1/18 - after much hacking, I suggest NEVER write to a register without first reading the contents of a chip.
00015 ie, don't updateRegisters without first readRegisters.
00016 
00017 If anyone manages to get this datasheet downloaded
00018 http://wenku.baidu.com/view/d6f0e6ee5ef7ba0d4a733b61.html
00019 Please let us know. It seem to be the latest version of the programming guide. It had a change on page 12 (write 0x8100 to 0x07)
00020 that allowed me to get the chip working..
00021 
00022 Also, if you happen to find "AN243: Using RDS/RBDS with the Si4701/03", please share. I love it when companies refer to
00023 documents that don't exist.
00024 
00025 1/20 - Picking up FM stations from a plane flying over Portugal! Sweet! 93.9MHz sounds a little soft for my tastes,s but
00026 it's in Porteguese.
00027 
00028 ToDo:
00029 Display current status (from 0x0A) - done 1/20/11
00030 Add RDS decoding - works, sort of
00031 Volume Up/Down - done 1/20/11
00032 Mute toggle - done 1/20/11
00033 Tune Up/Down - done 1/20/11
00034 Read current channel (0xB0) - done 1/20/11
00035 Setup for Europe - done 1/20/11
00036 Seek up/down - done 1/25/11
00037 
00038 The Si4703 breakout does work with line out into a stereo or other amplifier. Be sure to test with different length 3.5mm
00039 cables. Too short of a cable may degrade reception.
00040 */
00041 
00042 #ifndef SparkFun_Si4703_h
00043 #define SparkFun_Si4703_h
00044 
00045 #include "mbed.h"
00046 
00047 
00048 class Si4703_Breakout
00049 {
00050 public:
00051     Si4703_Breakout(PinName sdioPin, PinName sclkPin, PinName resetPin, Serial *pc);
00052     ~Si4703_Breakout();
00053     void powerOn();                 // call in setup
00054     void powerOff();                    // call in de-setup
00055     void setChannel(uint16_t channel);      // channel number ( e.g. : 8750 .. 10800 )
00056     uint16_t getChannel();              // returns the current channel
00057     uint16_t seek(bool seekDirection);
00058     uint16_t seekUp();                  // returns the tuned channel or 0
00059     uint16_t seekDown();                // -"-
00060     void setVolume(uint8_t volume);     // 0 to 15
00061     uint8_t getVolume();    // Returns The Current Volume (0 .. 15)
00062 
00063     /*  void readRDS(char* message, long timeout);   */
00064     // message should be at least 9 chars
00065     // result will be null terminated
00066     // timeout in milliseconds
00067     uint16_t getRegister(uint8_t regNum); // Returns The Value of a Single Register (0x00 .. 0x0F)
00068     void printRegs(); // Prints All of The Registers To The Serial Console
00069 
00070 private:
00071 
00072     PinName _resetPin;
00073     PinName _sdioPin;
00074     PinName _sclkPin;
00075 
00076     mbed::I2C *i2c_;
00077     mbed::Serial *pc;
00078     DigitalOut *_reset_;
00079     DigitalOut *_sdio_;
00080 
00081     void si4703_init();
00082     uint8_t readRegisters();
00083     uint8_t updateRegisters();
00084 
00085     uint16_t si4703_registers[16]; //There are 16 registers, each 16 bits large
00086     static const uint16_t  FAIL = 0;
00087     static const uint16_t  SUCCESS = 1;
00088 
00089     static const uint16_t  SI4703 = 0x20; //0b._001.0000 = I2C address of Si4703 - note that the Wire function assumes non-left-shifted I2C address, not 0b.0010.000W
00090     static const uint8_t  I2C_FAIL_MAX = 10; //This is the number of attempts we will try to contact the device before erroring out
00091     static const uint8_t  SEEK_DOWN = 0; //Direction used for seeking. Default is down
00092     static const uint8_t  SEEK_UP = 1;
00093 
00094     //Define the register names
00095     static const uint8_t  DEVICEID = 0x00;
00096     static const uint8_t  CHIPID = 0x01;
00097     static const uint8_t  POWERCFG = 0x02;
00098     static const uint8_t  CHANNEL = 0x03;
00099     static const uint8_t  SYSCONFIG1 = 0x04;
00100     static const uint8_t  SYSCONFIG2 = 0x05;
00101     static const uint8_t  SYSCONFIG3 = 0x06;
00102     static const uint8_t  TEST1 = 0x07;
00103     static const uint8_t  STATUSRSSI = 0x0A;
00104     static const uint8_t  READCHAN = 0x0B;
00105     static const uint8_t  RDSA = 0x0C;
00106     static const uint8_t  RDSB = 0x0D;
00107     static const uint8_t  RDSC = 0x0E;
00108     static const uint8_t  RDSD = 0x0F;
00109 
00110     //Register 0x00 - DeviceID
00111 //   part# = 15:12, mfgid = 11:0
00112 
00113     //Register 0x02 - POWERCFG
00114     static const uint8_t  SMUTE = 15;
00115     static const uint8_t  DMUTE = 14;
00116     static const uint8_t  SKMODE = 10;
00117     static const uint8_t  SEEKUP = 9;
00118     static const uint8_t  SEEK = 8;
00119     static const uint8_t  DISABLE = 6;
00120     static const uint8_t  ENABLE = 0;
00121 
00122     //Register 0x03 - CHANNEL
00123     static const uint8_t  TUNE = 15;
00124 
00125     //Register 0x04 - SYSCONFIG1
00126     static const uint8_t  RDS = 12;
00127     static const uint8_t  DE = 11;
00128 
00129     //Register 0x05 - SYSCONFIG2
00130     static const uint8_t  SPACE1 = 5;
00131     static const uint8_t  SPACE0 = 4;
00132     static const uint8_t  SEEKTH = 8;
00133 
00134     //Register 0x06 - SYSCONFIG3
00135     static const uint8_t  SKSNR  = 4;
00136     static const uint8_t  SKCNT  = 0;
00137 
00138     //Register 0x0A - STATUSRSSI
00139     static const uint8_t  RDSR = 15;
00140     static const uint8_t  STC = 14;
00141     static const uint8_t  SFBL = 13;
00142     static const uint8_t  AFCRL = 12;
00143     static const uint8_t  RDSS = 11;
00144     static const uint8_t  BLERA = 9;
00145     static const uint8_t  STEREO = 8;
00146     static const uint8_t  RSSI = 0;
00147 };
00148 
00149 #endif