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