Skip to content

Instantly share code, notes, and snippets.

@jeffThompson
Created June 4, 2017 18:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jeffThompson/5e48c8915148e6e0bac7d85c9a3da948 to your computer and use it in GitHub Desktop.
Save jeffThompson/5e48c8915148e6e0bac7d85c9a3da948 to your computer and use it in GitHub Desktop.
/*
Si4703 LIBRARY FOR ATTINY CHIPS
Jeff Thompson | 2017 | jeffreythompson.org
A library for the Si4703 FM radio breakout from Sparkfun
for ATtiny chips like the ATtiny85. Mostly a little work
porting to the TinyWireM library, plus a bit of general
cleanup and formatting.
Based on code from Sparkfun, written by Nathan Seidle, Simon
Monk, and Aaron Weiss:
https://github.com/sparkfun/Si4703_FM_Tuner_Evaluation_Board
And using the Adafruit TinyWireM library instead of the
standard Wire library:
https://github.com/adafruit/TinyWireM
*/
#ifndef Si4703_ATtiny_h
#define Si4703_ATtiny_h
#include "Arduino.h"
class Si4703_ATtiny {
public:
Si4703_ATtiny(int resetPin, int sdioPin, int sclkPin);
void powerOn(); // call in setup
void setChannel(int channel); // 3 digit channel number
int seekUp(); // returns the tuned channel or 0
int seekDown();
void setVolume(int volume); // 0 to 15
void readRDS(char* message, long timeout); // message should be at least 9 chars
// result will be null terminated
// timeout in milliseconds
private:
int _resetPin;
int _sdioPin;
int _sclkPin;
void si4703_init();
void readRegisters();
byte updateRegisters();
int seek(byte seekDirection);
int getChannel();
uint16_t si4703_registers[16]; // there are 16 registers, each 16 bits large
static const uint16_t FAIL = 0;
static const uint16_t SUCCESS = 1;
static const int SI4703 = 0x10; // 0b._001.0000 = I2C address of Si4703
// note that the Wire function assumes non-left-shifted
// I2C address, not 0b.0010.000W
static const uint16_t I2C_FAIL_MAX = 10; // this is the number of attempts we will try to contact
// the device before erroring out
static const uint16_t SEEK_DOWN = 0; // direction used for seeking, default is down
static const uint16_t SEEK_UP = 1;
// define the register names
static const uint16_t DEVICEID = 0x00;
static const uint16_t CHIPID = 0x01;
static const uint16_t POWERCFG = 0x02;
static const uint16_t CHANNEL = 0x03;
static const uint16_t SYSCONFIG1 = 0x04;
static const uint16_t SYSCONFIG2 = 0x05;
static const uint16_t STATUSRSSI = 0x0A;
static const uint16_t READCHAN = 0x0B;
static const uint16_t RDSA = 0x0C;
static const uint16_t RDSB = 0x0D;
static const uint16_t RDSC = 0x0E;
static const uint16_t RDSD = 0x0F;
// register 0x02 - POWERCFG
static const uint16_t SMUTE = 15;
static const uint16_t DMUTE = 14;
static const uint16_t SKMODE = 10;
static const uint16_t SEEKUP = 9;
static const uint16_t SEEK = 8;
// register 0x03 - CHANNEL
static const uint16_t TUNE = 15;
// register 0x04 - SYSCONFIG1
static const uint16_t RDS = 12;
static const uint16_t DE = 11;
// register 0x05 - SYSCONFIG2
static const uint16_t SPACE1 = 5;
static const uint16_t SPACE0 = 4;
// register 0x0A - STATUSRSSI
static const uint16_t RDSR = 15;
static const uint16_t STC = 14;
static const uint16_t SFBL = 13;
static const uint16_t AFCRL = 12;
static const uint16_t RDSS = 11;
static const uint16_t STEREO = 8;
};
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment