Nicholas Ciulla / Mbed 2 deprecated CiullaNguyenIUPUI495_GestureControlledFMRadio

Dependencies:   APDS_9960 TextLCD mbed

Fork of Si4703 by kris gjika

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     void powerOn();                 // call in setup
00053     void powerOff();                    // call in de-setup
00054     void setChannel(int channel);   // 3 digit channel number
00055     int getChannel();               // returns the current channel
00056     int seekUp();                   // returns the tuned channel or 0
00057     int seekDown();                 
00058     void setVolume(int volume);     // 0 to 15
00059     uint8_t getVolume();    // Returns The Current Volume (0 .. 15)
00060  
00061 /*  void readRDS(char* message, long timeout);   */
00062                                     // message should be at least 9 chars
00063                                     // result will be null terminated
00064                                     // timeout in milliseconds
00065     uint16_t getRegister(uint8_t regNum); // Returns The Value of a Single Register (0x00 .. 0x0F)
00066     void printRegs(); // Prints All of The Registers To The Serial Console
00067  
00068   private:
00069     PinName _resetPin;
00070     PinName _sdioPin;
00071     PinName _sclkPin;
00072  
00073     mbed::I2C *i2c_;
00074     mbed::Serial *pc;
00075     DigitalOut *_reset_;
00076     DigitalOut *_sdio_;
00077  
00078     void si4703_init();
00079     uint8_t readRegisters();
00080     uint8_t updateRegisters();
00081     int seek(bool seekDirection);
00082  
00083     uint16_t si4703_registers[16]; //There are 16 registers, each 16 bits large
00084     static const uint16_t  FAIL = 0;
00085     static const uint16_t  SUCCESS = 1;
00086  
00087     static const int  SI4703 = 0x20; //0b._001.0000 = I2C address of Si4703 - note that the Wire function assumes non-left-shifted I2C address, not 0b.0010.000W
00088     static const uint16_t  I2C_FAIL_MAX = 10; //This is the number of attempts we will try to contact the device before erroring out
00089     static const uint16_t  SEEK_DOWN = 0; //Direction used for seeking. Default is down
00090     static const uint16_t  SEEK_UP = 1;
00091  
00092     //Define the register names
00093     static const uint16_t  DEVICEID = 0x00;
00094     static const uint16_t  CHIPID = 0x01;
00095     static const uint16_t  POWERCFG = 0x02;
00096     static const uint16_t  CHANNEL = 0x03;
00097     static const uint16_t  SYSCONFIG1 = 0x04;
00098     static const uint16_t  SYSCONFIG2 = 0x05;
00099     static const uint16_t  SYSCONFIG3 = 0x06;
00100     static const uint16_t  TEST1 = 0x07;
00101     static const uint16_t  STATUSRSSI = 0x0A;
00102     static const uint16_t  READCHAN = 0x0B;
00103     static const uint16_t  RDSA = 0x0C;
00104     static const uint16_t  RDSB = 0x0D;
00105     static const uint16_t  RDSC = 0x0E;
00106     static const uint16_t  RDSD = 0x0F;
00107  
00108     //Register 0x00 - DeviceID
00109 //   part# = 15:12, mfgid = 11:0
00110  
00111     //Register 0x02 - POWERCFG
00112     static const uint16_t  SMUTE = 15;
00113     static const uint16_t  DMUTE = 14;
00114     static const uint16_t  SKMODE = 10;
00115     static const uint16_t  SEEKUP = 9;
00116     static const uint16_t  SEEK = 8;
00117     static const uint16_t  DISABLE = 6;
00118     static const uint16_t  ENABLE = 0;
00119  
00120     //Register 0x03 - CHANNEL
00121     static const uint16_t  TUNE = 15;
00122  
00123     //Register 0x04 - SYSCONFIG1
00124     static const uint16_t  RDS = 12;
00125     static const uint16_t  DE = 11;
00126  
00127     //Register 0x05 - SYSCONFIG2
00128     static const uint16_t  SPACE1 = 5;
00129     static const uint16_t  SPACE0 = 4;
00130     static const uint16_t  SEEKTH = 8;
00131  
00132     //Register 0x06 - SYSCONFIG3
00133     static const uint16_t  SKSNR  = 4;
00134     static const uint16_t  SKCNT  = 0;
00135  
00136     //Register 0x0A - STATUSRSSI
00137     static const uint16_t  RDSR = 15;
00138     static const uint16_t  STC = 14;
00139     static const uint16_t  SFBL = 13;
00140     static const uint16_t  AFCRL = 12;
00141     static const uint16_t  RDSS = 11;
00142     static const uint16_t  BLERA = 9;
00143     static const uint16_t  STEREO = 8;
00144     static const uint16_t  RSSI = 0;
00145 };
00146  
00147 #endif