A mbed Port of 'Sparkfun Si4703 Arduino Library'.
Fork of Si4703 by
SparkFun-Si4703.h@3:9ac35cc4a0b0, 2016-01-16 (annotated)
- Committer:
- vodavprasku
- Date:
- Sat Jan 16 19:26:55 2016 +0000
- Revision:
- 3:9ac35cc4a0b0
- Parent:
- 2:558ef02f39d0
hotovo
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mzcs | 0:1f830fa5c9b8 | 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 | 0:1f830fa5c9b8 | 50 | public: |
mzcs | 0:1f830fa5c9b8 | 51 | Si4703_Breakout(PinName sdioPin, PinName sclkPin, PinName resetPin, Serial *pc); |
mzcs | 0:1f830fa5c9b8 | 52 | void powerOn(); // call in setup |
mzcs | 0:1f830fa5c9b8 | 53 | void powerOff(); // call in de-setup |
mzcs | 0:1f830fa5c9b8 | 54 | void setChannel(int channel); // 3 digit channel number |
mzcs | 0:1f830fa5c9b8 | 55 | int getChannel(); // returns the current channel |
mzcs | 0:1f830fa5c9b8 | 56 | int seekUp(); // returns the tuned channel or 0 |
mzcs | 0:1f830fa5c9b8 | 57 | int seekDown(); |
mzcs | 0:1f830fa5c9b8 | 58 | void setVolume(int volume); // 0 to 15 |
mzcs | 0:1f830fa5c9b8 | 59 | uint8_t getVolume(); // Returns The Current Volume (0 .. 15) |
mzcs | 0:1f830fa5c9b8 | 60 | |
vodavprasku | 3:9ac35cc4a0b0 | 61 | void readRDS(char* message, long timeout); |
mzcs | 0:1f830fa5c9b8 | 62 | // message should be at least 9 chars |
mzcs | 0:1f830fa5c9b8 | 63 | // result will be null terminated |
mzcs | 0:1f830fa5c9b8 | 64 | // timeout in milliseconds |
mzcs | 0:1f830fa5c9b8 | 65 | uint16_t getRegister(uint8_t regNum); // Returns The Value of a Single Register (0x00 .. 0x0F) |
mzcs | 0:1f830fa5c9b8 | 66 | void printRegs(); // Prints All of The Registers To The Serial Console |
mzcs | 0:1f830fa5c9b8 | 67 | |
mzcs | 0:1f830fa5c9b8 | 68 | private: |
mzcs | 0:1f830fa5c9b8 | 69 | PinName _resetPin; |
mzcs | 0:1f830fa5c9b8 | 70 | PinName _sdioPin; |
mzcs | 0:1f830fa5c9b8 | 71 | PinName _sclkPin; |
mzcs | 0:1f830fa5c9b8 | 72 | |
mzcs | 0:1f830fa5c9b8 | 73 | mbed::I2C *i2c_; |
mzcs | 0:1f830fa5c9b8 | 74 | mbed::Serial *pc; |
mzcs | 0:1f830fa5c9b8 | 75 | DigitalOut *_reset_; |
mzcs | 0:1f830fa5c9b8 | 76 | DigitalOut *_sdio_; |
mzcs | 0:1f830fa5c9b8 | 77 | |
mzcs | 0:1f830fa5c9b8 | 78 | void si4703_init(); |
mzcs | 0:1f830fa5c9b8 | 79 | uint8_t readRegisters(); |
mzcs | 0:1f830fa5c9b8 | 80 | uint8_t updateRegisters(); |
mzcs | 0:1f830fa5c9b8 | 81 | int seek(bool seekDirection); |
mzcs | 0:1f830fa5c9b8 | 82 | |
mzcs | 0:1f830fa5c9b8 | 83 | uint16_t si4703_registers[16]; //There are 16 registers, each 16 bits large |
mzcs | 0:1f830fa5c9b8 | 84 | static const uint16_t FAIL = 0; |
mzcs | 0:1f830fa5c9b8 | 85 | static const uint16_t SUCCESS = 1; |
mzcs | 0:1f830fa5c9b8 | 86 | |
mzcs | 0:1f830fa5c9b8 | 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 |
mzcs | 0:1f830fa5c9b8 | 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 |
mzcs | 0:1f830fa5c9b8 | 89 | static const uint16_t SEEK_DOWN = 0; //Direction used for seeking. Default is down |
mzcs | 0:1f830fa5c9b8 | 90 | static const uint16_t SEEK_UP = 1; |
mzcs | 0:1f830fa5c9b8 | 91 | |
mzcs | 0:1f830fa5c9b8 | 92 | //Define the register names |
mzcs | 0:1f830fa5c9b8 | 93 | static const uint16_t DEVICEID = 0x00; |
mzcs | 0:1f830fa5c9b8 | 94 | static const uint16_t CHIPID = 0x01; |
mzcs | 0:1f830fa5c9b8 | 95 | static const uint16_t POWERCFG = 0x02; |
mzcs | 0:1f830fa5c9b8 | 96 | static const uint16_t CHANNEL = 0x03; |
mzcs | 0:1f830fa5c9b8 | 97 | static const uint16_t SYSCONFIG1 = 0x04; |
mzcs | 0:1f830fa5c9b8 | 98 | static const uint16_t SYSCONFIG2 = 0x05; |
mzcs | 0:1f830fa5c9b8 | 99 | static const uint16_t STATUSRSSI = 0x0A; |
mzcs | 0:1f830fa5c9b8 | 100 | static const uint16_t READCHAN = 0x0B; |
mzcs | 0:1f830fa5c9b8 | 101 | static const uint16_t RDSA = 0x0C; |
mzcs | 0:1f830fa5c9b8 | 102 | static const uint16_t RDSB = 0x0D; |
mzcs | 0:1f830fa5c9b8 | 103 | static const uint16_t RDSC = 0x0E; |
mzcs | 0:1f830fa5c9b8 | 104 | static const uint16_t RDSD = 0x0F; |
mzcs | 0:1f830fa5c9b8 | 105 | |
mzcs | 0:1f830fa5c9b8 | 106 | //Register 0x00 - DeviceID |
mzcs | 0:1f830fa5c9b8 | 107 | // part# = 15:12, mfgid = 11:0 |
mzcs | 0:1f830fa5c9b8 | 108 | |
mzcs | 0:1f830fa5c9b8 | 109 | //Register 0x02 - POWERCFG |
mzcs | 0:1f830fa5c9b8 | 110 | static const uint16_t SMUTE = 15; |
mzcs | 0:1f830fa5c9b8 | 111 | static const uint16_t DMUTE = 14; |
mzcs | 0:1f830fa5c9b8 | 112 | static const uint16_t SKMODE = 10; |
mzcs | 0:1f830fa5c9b8 | 113 | static const uint16_t SEEKUP = 9; |
mzcs | 0:1f830fa5c9b8 | 114 | static const uint16_t SEEK = 8; |
mzcs | 0:1f830fa5c9b8 | 115 | |
mzcs | 0:1f830fa5c9b8 | 116 | //Register 0x03 - CHANNEL |
mzcs | 0:1f830fa5c9b8 | 117 | static const uint16_t TUNE = 15; |
mzcs | 0:1f830fa5c9b8 | 118 | |
mzcs | 0:1f830fa5c9b8 | 119 | //Register 0x04 - SYSCONFIG1 |
mzcs | 0:1f830fa5c9b8 | 120 | static const uint16_t RDS = 12; |
mzcs | 0:1f830fa5c9b8 | 121 | static const uint16_t DE = 11; |
mzcs | 0:1f830fa5c9b8 | 122 | |
mzcs | 0:1f830fa5c9b8 | 123 | //Register 0x05 - SYSCONFIG2 |
mzcs | 0:1f830fa5c9b8 | 124 | static const uint16_t SPACE1 = 5; |
mzcs | 0:1f830fa5c9b8 | 125 | static const uint16_t SPACE0 = 4; |
mzcs | 2:558ef02f39d0 | 126 | static const uint16_t SEEKTH = 8; |
mzcs | 2:558ef02f39d0 | 127 | |
mzcs | 0:1f830fa5c9b8 | 128 | //Register 0x0A - STATUSRSSI |
mzcs | 0:1f830fa5c9b8 | 129 | static const uint16_t RDSR = 15; |
mzcs | 0:1f830fa5c9b8 | 130 | static const uint16_t STC = 14; |
mzcs | 0:1f830fa5c9b8 | 131 | static const uint16_t SFBL = 13; |
mzcs | 0:1f830fa5c9b8 | 132 | static const uint16_t AFCRL = 12; |
mzcs | 0:1f830fa5c9b8 | 133 | static const uint16_t RDSS = 11; |
mzcs | 2:558ef02f39d0 | 134 | static const uint16_t BLERA = 9; |
mzcs | 0:1f830fa5c9b8 | 135 | static const uint16_t STEREO = 8; |
mzcs | 0:1f830fa5c9b8 | 136 | }; |
mzcs | 0:1f830fa5c9b8 | 137 | |
mzcs | 0:1f830fa5c9b8 | 138 | #endif |