Si4703 sample code ECE 4180 Georgia Tech

Dependencies:   TextLCD mbed

Fork of Si4735 by Brett Wilson

Committer:
Gjika
Date:
Tue Oct 20 14:58:05 2015 +0000
Revision:
1:563a11fe39e0
Sample Code for Si4703 Digital FM Radio Receiver

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Gjika 1:563a11fe39e0 1 /*
Gjika 1:563a11fe39e0 2 Library for Sparkfun Si4703 breakout board.
Gjika 1:563a11fe39e0 3 Simon Monk. 2011-09-09
Gjika 1:563a11fe39e0 4
Gjika 1:563a11fe39e0 5 This is a library wrapper and a few extras to the excellent code produced
Gjika 1:563a11fe39e0 6 by Nathan Seidle from Sparkfun (Beerware).
Gjika 1:563a11fe39e0 7
Gjika 1:563a11fe39e0 8 Nathan's comments......
Gjika 1:563a11fe39e0 9
Gjika 1:563a11fe39e0 10 Look for serial output at 57600bps.
Gjika 1:563a11fe39e0 11
Gjika 1:563a11fe39e0 12 The Si4703 ACKs the first byte, and NACKs the 2nd byte of a read.
Gjika 1:563a11fe39e0 13
Gjika 1:563a11fe39e0 14 1/18 - after much hacking, I suggest NEVER write to a register without first reading the contents of a chip.
Gjika 1:563a11fe39e0 15 ie, don't updateRegisters without first readRegisters.
Gjika 1:563a11fe39e0 16
Gjika 1:563a11fe39e0 17 If anyone manages to get this datasheet downloaded
Gjika 1:563a11fe39e0 18 http://wenku.baidu.com/view/d6f0e6ee5ef7ba0d4a733b61.html
Gjika 1:563a11fe39e0 19 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)
Gjika 1:563a11fe39e0 20 that allowed me to get the chip working..
Gjika 1:563a11fe39e0 21
Gjika 1:563a11fe39e0 22 Also, if you happen to find "AN243: Using RDS/RBDS with the Si4701/03", please share. I love it when companies refer to
Gjika 1:563a11fe39e0 23 documents that don't exist.
Gjika 1:563a11fe39e0 24
Gjika 1:563a11fe39e0 25 1/20 - Picking up FM stations from a plane flying over Portugal! Sweet! 93.9MHz sounds a little soft for my tastes,s but
Gjika 1:563a11fe39e0 26 it's in Porteguese.
Gjika 1:563a11fe39e0 27
Gjika 1:563a11fe39e0 28 ToDo:
Gjika 1:563a11fe39e0 29 Display current status (from 0x0A) - done 1/20/11
Gjika 1:563a11fe39e0 30 Add RDS decoding - works, sort of
Gjika 1:563a11fe39e0 31 Volume Up/Down - done 1/20/11
Gjika 1:563a11fe39e0 32 Mute toggle - done 1/20/11
Gjika 1:563a11fe39e0 33 Tune Up/Down - done 1/20/11
Gjika 1:563a11fe39e0 34 Read current channel (0xB0) - done 1/20/11
Gjika 1:563a11fe39e0 35 Setup for Europe - done 1/20/11
Gjika 1:563a11fe39e0 36 Seek up/down - done 1/25/11
Gjika 1:563a11fe39e0 37
Gjika 1:563a11fe39e0 38 The Si4703 breakout does work with line out into a stereo or other amplifier. Be sure to test with different length 3.5mm
Gjika 1:563a11fe39e0 39 cables. Too short of a cable may degrade reception.
Gjika 1:563a11fe39e0 40 */
Gjika 1:563a11fe39e0 41
Gjika 1:563a11fe39e0 42 #ifndef SparkFun_Si4703_h
Gjika 1:563a11fe39e0 43 #define SparkFun_Si4703_h
Gjika 1:563a11fe39e0 44
Gjika 1:563a11fe39e0 45 #include "mbed.h"
Gjika 1:563a11fe39e0 46
Gjika 1:563a11fe39e0 47
Gjika 1:563a11fe39e0 48 class Si4703_Breakout
Gjika 1:563a11fe39e0 49 {
Gjika 1:563a11fe39e0 50 public:
Gjika 1:563a11fe39e0 51 Si4703_Breakout(PinName sdioPin, PinName sclkPin, PinName resetPin, Serial *pc);
Gjika 1:563a11fe39e0 52 void powerOn(); // call in setup
Gjika 1:563a11fe39e0 53 void powerOff(); // call in de-setup
Gjika 1:563a11fe39e0 54 void setChannel(int channel); // 3 digit channel number
Gjika 1:563a11fe39e0 55 int getChannel(); // returns the current channel
Gjika 1:563a11fe39e0 56 int seekUp(); // returns the tuned channel or 0
Gjika 1:563a11fe39e0 57 int seekDown();
Gjika 1:563a11fe39e0 58 void setVolume(int volume); // 0 to 15
Gjika 1:563a11fe39e0 59 uint8_t getVolume(); // Returns The Current Volume (0 .. 15)
Gjika 1:563a11fe39e0 60
Gjika 1:563a11fe39e0 61 /* void readRDS(char* message, long timeout); */
Gjika 1:563a11fe39e0 62 // message should be at least 9 chars
Gjika 1:563a11fe39e0 63 // result will be null terminated
Gjika 1:563a11fe39e0 64 // timeout in milliseconds
Gjika 1:563a11fe39e0 65 uint16_t getRegister(uint8_t regNum); // Returns The Value of a Single Register (0x00 .. 0x0F)
Gjika 1:563a11fe39e0 66 void printRegs(); // Prints All of The Registers To The Serial Console
Gjika 1:563a11fe39e0 67
Gjika 1:563a11fe39e0 68 private:
Gjika 1:563a11fe39e0 69 PinName _resetPin;
Gjika 1:563a11fe39e0 70 PinName _sdioPin;
Gjika 1:563a11fe39e0 71 PinName _sclkPin;
Gjika 1:563a11fe39e0 72
Gjika 1:563a11fe39e0 73 mbed::I2C *i2c_;
Gjika 1:563a11fe39e0 74 mbed::Serial *pc;
Gjika 1:563a11fe39e0 75 DigitalOut *_reset_;
Gjika 1:563a11fe39e0 76 DigitalOut *_sdio_;
Gjika 1:563a11fe39e0 77
Gjika 1:563a11fe39e0 78 void si4703_init();
Gjika 1:563a11fe39e0 79 uint8_t readRegisters();
Gjika 1:563a11fe39e0 80 uint8_t updateRegisters();
Gjika 1:563a11fe39e0 81 int seek(bool seekDirection);
Gjika 1:563a11fe39e0 82
Gjika 1:563a11fe39e0 83 uint16_t si4703_registers[16]; //There are 16 registers, each 16 bits large
Gjika 1:563a11fe39e0 84 static const uint16_t FAIL = 0;
Gjika 1:563a11fe39e0 85 static const uint16_t SUCCESS = 1;
Gjika 1:563a11fe39e0 86
Gjika 1:563a11fe39e0 87 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
Gjika 1:563a11fe39e0 88 static const uint16_t I2C_FAIL_MAX = 10; //This is the number of attempts we will try to contact the device before erroring out
Gjika 1:563a11fe39e0 89 static const uint16_t SEEK_DOWN = 0; //Direction used for seeking. Default is down
Gjika 1:563a11fe39e0 90 static const uint16_t SEEK_UP = 1;
Gjika 1:563a11fe39e0 91
Gjika 1:563a11fe39e0 92 //Define the register names
Gjika 1:563a11fe39e0 93 static const uint16_t DEVICEID = 0x00;
Gjika 1:563a11fe39e0 94 static const uint16_t CHIPID = 0x01;
Gjika 1:563a11fe39e0 95 static const uint16_t POWERCFG = 0x02;
Gjika 1:563a11fe39e0 96 static const uint16_t CHANNEL = 0x03;
Gjika 1:563a11fe39e0 97 static const uint16_t SYSCONFIG1 = 0x04;
Gjika 1:563a11fe39e0 98 static const uint16_t SYSCONFIG2 = 0x05;
Gjika 1:563a11fe39e0 99 static const uint16_t SYSCONFIG3 = 0x06;
Gjika 1:563a11fe39e0 100 static const uint16_t TEST1 = 0x07;
Gjika 1:563a11fe39e0 101 static const uint16_t STATUSRSSI = 0x0A;
Gjika 1:563a11fe39e0 102 static const uint16_t READCHAN = 0x0B;
Gjika 1:563a11fe39e0 103 static const uint16_t RDSA = 0x0C;
Gjika 1:563a11fe39e0 104 static const uint16_t RDSB = 0x0D;
Gjika 1:563a11fe39e0 105 static const uint16_t RDSC = 0x0E;
Gjika 1:563a11fe39e0 106 static const uint16_t RDSD = 0x0F;
Gjika 1:563a11fe39e0 107
Gjika 1:563a11fe39e0 108 //Register 0x00 - DeviceID
Gjika 1:563a11fe39e0 109 // part# = 15:12, mfgid = 11:0
Gjika 1:563a11fe39e0 110
Gjika 1:563a11fe39e0 111 //Register 0x02 - POWERCFG
Gjika 1:563a11fe39e0 112 static const uint16_t SMUTE = 15;
Gjika 1:563a11fe39e0 113 static const uint16_t DMUTE = 14;
Gjika 1:563a11fe39e0 114 static const uint16_t SKMODE = 10;
Gjika 1:563a11fe39e0 115 static const uint16_t SEEKUP = 9;
Gjika 1:563a11fe39e0 116 static const uint16_t SEEK = 8;
Gjika 1:563a11fe39e0 117 static const uint16_t DISABLE = 6;
Gjika 1:563a11fe39e0 118 static const uint16_t ENABLE = 0;
Gjika 1:563a11fe39e0 119
Gjika 1:563a11fe39e0 120 //Register 0x03 - CHANNEL
Gjika 1:563a11fe39e0 121 static const uint16_t TUNE = 15;
Gjika 1:563a11fe39e0 122
Gjika 1:563a11fe39e0 123 //Register 0x04 - SYSCONFIG1
Gjika 1:563a11fe39e0 124 static const uint16_t RDS = 12;
Gjika 1:563a11fe39e0 125 static const uint16_t DE = 11;
Gjika 1:563a11fe39e0 126
Gjika 1:563a11fe39e0 127 //Register 0x05 - SYSCONFIG2
Gjika 1:563a11fe39e0 128 static const uint16_t SPACE1 = 5;
Gjika 1:563a11fe39e0 129 static const uint16_t SPACE0 = 4;
Gjika 1:563a11fe39e0 130 static const uint16_t SEEKTH = 8;
Gjika 1:563a11fe39e0 131
Gjika 1:563a11fe39e0 132 //Register 0x06 - SYSCONFIG3
Gjika 1:563a11fe39e0 133 static const uint16_t SKSNR = 4;
Gjika 1:563a11fe39e0 134 static const uint16_t SKCNT = 0;
Gjika 1:563a11fe39e0 135
Gjika 1:563a11fe39e0 136 //Register 0x0A - STATUSRSSI
Gjika 1:563a11fe39e0 137 static const uint16_t RDSR = 15;
Gjika 1:563a11fe39e0 138 static const uint16_t STC = 14;
Gjika 1:563a11fe39e0 139 static const uint16_t SFBL = 13;
Gjika 1:563a11fe39e0 140 static const uint16_t AFCRL = 12;
Gjika 1:563a11fe39e0 141 static const uint16_t RDSS = 11;
Gjika 1:563a11fe39e0 142 static const uint16_t BLERA = 9;
Gjika 1:563a11fe39e0 143 static const uint16_t STEREO = 8;
Gjika 1:563a11fe39e0 144 static const uint16_t RSSI = 0;
Gjika 1:563a11fe39e0 145 };
Gjika 1:563a11fe39e0 146
Gjika 1:563a11fe39e0 147 #endif