![]() |
PU2CLR SI470X Arduino Library
1.0.1
Arduino Library for Si470X Devices - By Ricardo Lima Caratti
|
Typedefs | |
typedef uint16_t | si470x_reg0c |
RDS Block A. More... | |
typedef uint16_t | si470x_reg0d |
RDS Block B. More... | |
typedef uint16_t | si470x_reg0e |
RDS Block C. More... | |
typedef uint16_t | si470x_reg0f |
RDS Block D. More... | |
SI470X Defined Data Types
Defined Data Types is a way to represent the SI470X registers information
Some information appears to be inaccurate due to translation problems from Chinese to English.
The information shown here was extracted from Datasheet:
SI470X stereo FM digital tuning radio documentation.
Other information seems incomplete even in the original Chinese Datasheet.
For example: Reg 10 (0x0A). There is no information about it. The Reg11 and 12 seem wrong
union si470x_reg00 |
Device ID.
Data Fields | ||
---|---|---|
struct si470x_reg00 | refined | |
uint16_t | raw |
struct si470x_reg00.refined |
union si470x_reg01 |
Chip ID.
Data Fields | ||
---|---|---|
struct si470x_reg01 | refined | |
uint16_t | raw |
struct si470x_reg01.refined |
union si470x_reg02 |
Power Configuratio.
Data Fields | ||
---|---|---|
struct si470x_reg02 | refined | |
uint16_t | raw |
struct si470x_reg02.refined |
union si470x_reg03 |
Channe.
Channel value for tune operation. If BAND 05h[7:6] = 00, then Freq (MHz) = Spacing (MHz) x Channel + 87.5 MHz.
If BAND 05h[7:6] = 01, BAND 05h[7:6] = 10, then Freq (MHz) = Spacing (MHz) x Channel + 76 MHz.
CHAN[9:0] is not updated during a seek operation. READCHAN[9:0] provides the current tuned channel and is updated during a seek operation and after a seek or tune operation completes. Channel spacing is set with the bits SPACE 05h[5:4].
The tune operation begins when the TUNE bit is set high. The STC bit is set high when the tune operation completes. The STC bit must be set low by setting the TUNE bit low before the next tune or seek may begin.
Data Fields | ||
---|---|---|
struct si470x_reg03 | refined | |
uint16_t | raw |
struct si470x_reg03.refined |
union si470x_reg04 |
System Configuration 1.
Setting STCIEN = 1 will generate a 5 ms low pulse on GPIO2 when the STC 0Ah[14] bit is set.
Setting RDSIEN = 1 will generate a 5 ms low pulse on GPIO2 when the RDSR 0Ah[15] bit is set.
Setting STCIEN = 1 and GPIO2[1:0] = 01 will generate a 5 ms low pulse on GPIO2 when the STC 0Ah[14] bit is set.
BLNDADJ value | Description |
---|---|
0 | 31–49 RSSI dBμV (default) |
1 | 37–55 RSSI dBμV (+6 dB) |
2 | 19–37 RSSI dBμV (–12 dB) |
3 | 25–43 RSSI dBμV (–6 dB) |
Data Fields | ||
---|---|---|
struct si470x_reg04 | refined | |
uint16_t | raw |
struct si470x_reg04.refined |
union si470x_reg05 |
System Configuration 2.
SEEKTH presents the logarithmic RSSI threshold for the seek operation. The Si4702/03-C19 will not validate channels with RSSI below the SEEKTH value. SEEKTH is one of multiple parameters that can be used to validate channels. For more information, see "AN284: Si4700/01 Firmware 15 Seek Adjustability and Set- tings."
BAND value | Description |
---|---|
0 | 00 = 87.5–108 MHz (USA, Europe) (Default) |
1 | 01 = 76–108 MHz (Japan wide band) |
2 | 10 = 76–90 MHz (Japan) |
3 | 11 = Reserved |
Data Fields | ||
---|---|---|
struct si470x_reg05 | refined | |
uint16_t | raw |
struct si470x_reg05.refined |
union si470x_reg06 |
System Configuration 3.
The VOLEXT bit attenuates the output by 30 dB. With the bit set to 0, the 15 volume settings adjust the volume between 0 and –28 dBFS. With the bit set to 1, the 15 volume set- tings adjust the volume between –30 and –58 dBFS.
Refer to 4.5. "Stereo Audio Processing" on page 16.
| Softmute Attenuation | Description | | 0 | 16 dB (default) | | 1 | 14 dB | | 2 | 12 dB | | 3 | 10 dB |
| Softmute Attack/Recover Rate | Description | | 0 | fastest (default) | | 1 | fast | | 2 | slow | | 3 | slowest |
Data Fields | ||
---|---|---|
struct si470x_reg06 | refined | |
uint16_t | raw |
struct si470x_reg06.refined |
union si470x_reg07 |
Test 1.
Setting AHIZEN maintains a dc bias of 0.5 x VIO on the LOUT and ROUT pins to pre- vent the ESD diodes from clamping to the VIO or GND rail in response to the output swing of another device.
Register 07h containing the AHIZEN bit must not be written during the powerup sequence and high-Z only takes effect when in powerdown and VIO is supplied. Bits 13:0 of register 07h must be preserved as 0x0100 while in pow- erdown and as 0x3C04 while in powerup.
The internal crystal oscillator requires an external 32.768 kHz crystal as shown in "Typical Application Schematic" on page 14.
The oscillator must be enabled before powerup (ENABLE = 1) as shown in Figure 9, “Initialization Sequence,” on page 21. It should only be disabled after powerdown (ENABLE = 0).
Bits 13:0 of register 07h must be preserved as 0x0100 while in powerdown and as 0x3C04 while in powerup. Refer to Si4702/03 Internal Crystal Oscillator Errata.
Data Fields | ||
---|---|---|
struct si470x_reg07 | refined | |
uint16_t | raw |
struct si470x_reg07.refined |
union si470x_reg08 |
Test 2.
If written, these bits should be read first and then written with their pre-existing val- ues. Do not write during powerup.
Data Fields | ||
---|---|---|
struct si470x_reg08 | refined | |
uint16_t | raw |
union si470x_reg09 |
Boot Configuration.
If written, these bits should be read first and then written with their pre-existing val- ues. Do not write during powerup.
Data Fields | ||
---|---|---|
struct si470x_reg09 | refined | |
uint16_t | raw |
union si470x_reg0a |
Status RSSI.
RSSI is measured units of dBμV in 1 dB increments with a maximum of approximately 75 dBμV. Si4702/03-C19 does not report RSSI levels greater than 75 dBuV.
AFCRL is updated after a tune or seek operation completes and indicates a valid or invalid channel. During normal operation, AFCRL is updated to reflect changing RF envi- ronments.
The SF/BL flag is set high when SKMODE 02h[10] = 0 and the seek operation fails to find a channel qualified as valid according to the seek parameters.
The SF/BL flag is set high when SKMODE 02h[10] = 1 and the upper or lower band limit has been reached. The SEEK 02h[8] bit must be set low to clear SF/BL.
The seek/tune complete flag is set when the seek or tune operation completes. Setting the SEEK 02h[8] or TUNE 03h[15] bit low will clear STC.
RDS Block A Errors | Description |
---|---|
0 | 0 errors requiring correction |
1 | 1–2 errors requiring correction |
2 | 3–5 errors requiring correction |
3 | 6+ errors or error in checkword, correction not possible |
Data Fields | ||
---|---|---|
struct si470x_reg0a | refined | |
uint16_t | raw |
struct si470x_reg0a.refined |
union si470x_reg0b |
Read Channel.
If BAND 05h[7:6] = 00, then Freq (MHz) = Spacing (MHz) x Channel + 87.5 MHz. If BAND 05h[7:6] = 01, BAND 05h[7:6] = 10, then Freq (MHz) = Spacing (MHz) x Channel + 76 MHz.
READCHAN[9:0] provides the current tuned channel and is updated during a seek operation and after a seek or tune operation completes. Spacing and channel are set with the bits SPACE 05h[5:4] and CHAN 03h[9:0].
RDS block Errors | Description |
---|---|
0 | 0 errors requiring correction |
1 | 1–2 errors requiring correction |
2 | 3–5 errors requiring correction |
3 | 6+ errors or error in checkword, correction not possible |
Data Fields | ||
---|---|---|
struct si470x_reg0b | refined | |
uint16_t | raw |
struct si470x_reg0b.refined |
union si47x_rds_blockb |
RDS Block B data type.
For GCC on System-V ABI on 386-compatible (32-bit processors), the following stands:
1) Bit-fields are allocated from right to left (least to most significant). 2) A bit-field must entirely reside in a storage unit appropriate for its declared type. Thus a bit-field never crosses its unit boundary. 3) Bit-fields may share a storage unit with other struct/union members, including members that are not bit-fields. Of course, struct members occupy different parts of the storage unit. 4) Unnamed bit-fields' types do not affect the alignment of a structure or union, although individual bit-fields' member offsets obey the alignment constraints.
Data Fields | ||
---|---|---|
struct si47x_rds_blockb | group0 | |
struct si47x_rds_blockb | group2 | |
struct si47x_rds_blockb | refined | |
si470x_reg0d | blockB |
struct si47x_rds_blockb.group0 |
struct si47x_rds_blockb.group2 |
struct si47x_rds_blockb.refined |
union si47x_rds_date_time |
Group RDS type 4A ( RDS Date and Time) When group type 4A is used by the station, it shall be transmitted every minute according to EN 50067. This Structure uses blocks 2,3 and 5 (B,C,D)
ATTENTION: To make it compatible with 8, 16 and 32 bits platforms and avoid Crosses boundary, it was necessary to split minute and hour representation.
Data Fields | ||
---|---|---|
struct si47x_rds_date_time | refined | |
uint8_t | raw[6] |
struct si47x_rds_date_time.refined |
union word16_to_bytes |
Converts 16 bits word to two bytes.
Data Fields | ||
---|---|---|
struct word16_to_bytes | refined | |
uint16_t | raw |
class SI470X |
KT0915 Class.
This class implements all functions that will help you to control the KT0915 devices.
Public Member Functions | |
void | setDelayAfterCrystalOn (uint8_t ms_value) |
Set the Delay After Crystal On (default 500ms) More... | |
void | getAllRegisters () |
PU2CLR SI470X Arduino Library. More... | |
void | setAllRegisters (uint8_t limit=0x07) |
Sets values to the device registers from 0x02 to 0x07. More... | |
void | getStatus () |
Gets the value of the 0x0A register. More... | |
void | waitAndFinishTune () |
Wait STC (Seek/Tune Complete) status becomes 0. More... | |
void | reset () |
Resets the device. More... | |
void | powerUp () |
Powers the receiver on. More... | |
void | powerDown () |
Powers the receiver off. More... | |
void | setup (int resetPin, int rdsInterruptPin=-1, int seekInterruptPin=-1, uint8_t oscillator_type=OSCILLATOR_TYPE_CRYSTAL) |
Starts the device. More... | |
void | setup (int resetPin, uint8_t oscillator_type) |
Starts the device. More... | |
void | setFrequency (uint16_t frequency) |
Sets the frequency. More... | |
uint16_t | getFrequency () |
Gets the current frequency. More... | |
uint16_t | getRealFrequency () |
Gets the frequency based on READCHAN register (0x0B) More... | |
uint16_t | getRealChannel () |
Gets the current channel stored in register 0x0B. More... | |
void | setChannel (uint16_t channel) |
Sets the channel. More... | |
void | seek (uint8_t seek_mode, uint8_t direction) |
Seek function. More... | |
void | setBand (uint8_t band=1) |
Sets the FM Band More... | |
void | setSpace (uint8_t space=0) |
Sets the FM Space More... | |
int | getRssi () |
Gets the Rssi. More... | |
void | setSoftmute (bool value) |
Sets the Softmute true or false. More... | |
void | setMute (bool value) |
Sets the Mute true or false. More... | |
void | setMono (bool value) |
Sets the Mono true or false (stereo) More... | |
void | setRdsMode (uint8_t rds_mode=0) |
Sets the Rds Mode Standard or Verbose. More... | |
uint8_t | getPartNumber () |
Gets the Part Number. More... | |
uint16_t | getManufacturerId () |
Gets the Manufacturer ID. More... | |
uint8_t | getFirmwareVersion () |
Gets the Firmware Version. More... | |
uint8_t | getDeviceId () |
Gets the Device identification. More... | |
uint8_t | getChipVersion () |
Gets the Chip Version. More... | |
void | setVolume (uint8_t value) |
Sets the audio volume level. More... | |
uint8_t | getVolume () |
Gets the current audio volume level. More... | |
void | setVolumeUp () |
Increments the audio volume. More... | |
void | setVolumeDown () |
Decrements the audio volume. More... | |
Protected Attributes | |
int | deviceAddress = I2C_DEVICE_ADDR |
int | resetPin |
uint16_t | currentFrequency |
uint8_t | currentFMBand = 0 |
uint8_t | currentFMSpace = 0 |
uint8_t | currentVolume = 0 |
int | rdsInterruptPin = -1 |
int | seekInterruptPin = -1 |
int | oscillatorType = OSCILLATOR_TYPE_CRYSTAL |
uint16_t | maxDelayAftarCrystalOn = MAX_DELAY_AFTER_OSCILLATOR |
|
inline |
Set the Delay After Crystal On (default 500ms)
ms_value | Value in milliseconds |
void SI470X::getAllRegisters | ( | ) |
PU2CLR SI470X Arduino Library.
SI470X Arduino Library implementation. This is an Arduino library for the SI470X, BROADCAST RECEIVER.
It works with I2C protocol and can provide an easier interface to control the SI470X device.
This library was built based on "AN230 - Si4700/01/02/03 PROGRAMMING GUIDE" and "Si4702/03-C19 - BROADCAST FM RADIO TUNER FOR PORTABLE APPLICATIONS"
This library can be freely distributed using the MIT Free Software model.
Low level functions used to operate with the SI470X registers
Gets all current register content of the device
For read operations, the device acknowledge is followed by an eight bit data word shifted out on falling SCLK edges. An internal address counter automatically increments to allow continuous data byte reads, starting with the upper byte of register 0Ah, followed by the lower byte of register 0Ah, and onward until the lower byte of the last register is reached. The internal address counter then automatically wraps around to the upper byte of register 00h and proceeds from there until continuous reads cease.
Referenced by getRealChannel(), powerDown(), powerUp(), seek(), and waitAndFinishTune().
void SI470X::setAllRegisters | ( | uint8_t | limit = 0x07 | ) |
Sets values to the device registers from 0x02 to 0x07.
For write operations, the device acknowledge is followed by an eight bit data word latched internally on rising edges of SCLK. The device acknowledges each byte of data written by driving SDIO low after the next falling SCLK edge, for 1 cycle.
An internal address counter automatically increments to allow continuous data byte writes, starting with the upper byte of register 02h, followed by the lower byte of register 02h, and onward until the lower byte of the last register is reached. The internal address counter then automatically wraps around to the upper byte of register 00h and proceeds from there until continuous writes end.
The registers from 0x2 to 0x07 are used to setup the device. This method writes the array shadowRegisters, elements 8 to 14 (corresponding the registers 0x2 to 0x7 respectively) into the device. See Device registers map in SI470X.h file.
To implement this, a register maping was created to deal with each register structure. For each type of register, there is a reference to the array element.
void SI470X::getStatus | ( | ) |
Gets the value of the 0x0A register.
This function also updates the value of shadowRegisters[0];
Referenced by getRssi().
void SI470X::waitAndFinishTune | ( | ) |
Wait STC (Seek/Tune Complete) status becomes 0.
Should be used before processing Tune or Seek.
The STC bit being cleared indicates that the TUNE or SEEK bits may be set again to start another tune or seek operation. Do not set the TUNE or SEEK bits until the Si470x clears the STC bit.
References getAllRegisters().
Referenced by seek(), and setChannel().
void SI470X::reset | ( | ) |
Resets the device.
Referenced by setup().
void SI470X::powerUp | ( | ) |
Powers the receiver on.
Starts the receiver with some default configurations
References getAllRegisters().
Referenced by setup().
void SI470X::powerDown | ( | ) |
Powers the receiver off.
References getAllRegisters().
void SI470X::setup | ( | int | resetPin, |
int | rdsInterruptPin = -1 , |
||
int | seekInterruptPin = -1 , |
||
uint8_t | oscillator_type = OSCILLATOR_TYPE_CRYSTAL |
||
) |
Starts the device.
sets the reset pin, interrupt pins and oscillator type you are using in your project.
resetPin | // Arduino pin used to reset control. |
rdsInterruptPin | // optional. Sets the Arduino pin used to RDS function control. |
seekInterruptPin | // optional. Sets the Arduino pin used to Seek function control. |
oscillator_type | // optional. Sets the Oscillator type used (Default Crystal or Ref. Clock). |
References powerUp(), rdsInterruptPin, reset(), resetPin, and seekInterruptPin.
void SI470X::setup | ( | int | resetPin, |
uint8_t | oscillator_type | ||
) |
Starts the device.
Use this if you are not using interrupt pins in your project
resetPin | // Arduino pin used to reset control. |
rdsInterruptPin | // optional. Sets the Arduino pin used to RDS function control. |
seekInterruptPin | // optional. Sets the Arduino pin used to Seek function control. |
void SI470X::setFrequency | ( | uint16_t | frequency | ) |
Sets the frequency.
frequency |
uint16_t SI470X::getFrequency | ( | ) |
Gets the current frequency.
uint16_t SI470X::getRealFrequency | ( | ) |
Gets the frequency based on READCHAN register (0x0B)
Unlike getFrequency method, this method queries the device.
uint16_t SI470X::getRealChannel | ( | ) |
Gets the current channel stored in register 0x0B.
This method is useful to query the current channel during the seek operations.
References getAllRegisters().
void SI470X::setChannel | ( | uint16_t | channel | ) |
void SI470X::seek | ( | uint8_t | seek_mode, |
uint8_t | direction | ||
) |
Seek function.
Seek begins at the current channel, and goes in the direction specified with the SEEKUP bit. Seek operation stops when a channel is qualified as valid according to the seek parameters, the entire band has been searched (SKMODE = 0), or the upper or lower band limit has been reached (SKMODE = 1).
The STC bit is set high when the seek operation completes and/or the SF/BL bit is set high if the seek operation was unable to find a channel qualified as valid according to the seek parameters. The STC and SF/BL bits must be set low by setting the SEEK bit low before the next seek or tune may begin.
Seek performance for 50 kHz channel spacing varies according to RCLK tolerance. Silicon Laboratories recommends ±50 ppm RCLK crystal tolerance for 50 kHz seek performance.
A seek operation may be aborted by setting SEEK = 0.
seek_mode | Seek Mode; 0 = Wrap at the upper or lower band limit and continue seeking (default); 1 = Stop seeking at the upper or lower band limit. |
direction | Seek Direction; 0 = Seek down (default); 1 = Seek up. |
References getAllRegisters(), and waitAndFinishTune().
void SI470X::setBand | ( | uint8_t | band = 1 | ) |
Sets the FM Band
BAND value | Description |
---|---|
0 | 00 = 87.5–108 MHz (USA, Europe) (Default) |
1 (default) | 01 = 76–108 MHz (Japan wide band) |
2 | 10 = 76–90 MHz (Japan) |
3 | 11 = Reserved |
band | See the table above. If you do not set a parameter, will be considered 1 (76-108MHz) |
void SI470X::setSpace | ( | uint8_t | space = 0 | ) |
Sets the FM Space
The SI470x device supports 3 different settings as shown below
BAND value | Description |
---|---|
0 | 00 - 200 kHz (US / Australia, Default) |
1 (default) | 01 - 100 kHz (Europe / Japan) |
2 | 02 - 50 kHz |
3 | 03 - Reserved (Do not use) |
int SI470X::getRssi | ( | ) |
void SI470X::setSoftmute | ( | bool | value | ) |
Sets the Softmute true or false.
value | TRUE or FALSE |
void SI470X::setMute | ( | bool | value | ) |
Sets the Mute true or false.
value | TRUE or FALSE |
void SI470X::setMono | ( | bool | value | ) |
Sets the Mono true or false (stereo)
value | TRUE or FALSE |
void SI470X::setRdsMode | ( | uint8_t | rds_mode = 0 | ) |
Sets the Rds Mode Standard or Verbose.
rds_mode | 0 = Standard (default); 1 = Verbose |
uint8_t SI470X::getPartNumber | ( | ) |
Gets the Part Number.
If it returns 0x01, so the device is: Si4702/03
uint16_t SI470X::getManufacturerId | ( | ) |
Gets the Manufacturer ID.
uint8_t SI470X::getFirmwareVersion | ( | ) |
Gets the Firmware Version.
The return velue before powerup will be 0. After powerup should be 010011 (19)
uint8_t SI470X::getDeviceId | ( | ) |
Gets the Device identification.
uint8_t SI470X::getChipVersion | ( | ) |
Gets the Chip Version.
void SI470X::setVolume | ( | uint8_t | value | ) |
Sets the audio volume level.
value | 0 to 15 (if 0, mutes the audio) |
uint8_t SI470X::getVolume | ( | ) |
Gets the current audio volume level.
void SI470X::setVolumeUp | ( | ) |
Increments the audio volume.
void SI470X::setVolumeDown | ( | ) |
Decrements the audio volume.
|
protected |
|
protected |
Referenced by setup().
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
Referenced by setup().
|
protected |
Referenced by setup().
|
protected |
|
protected |
typedef uint16_t si470x_reg0c |
RDS Block A.
RDS Block A Data.
typedef uint16_t si470x_reg0d |
RDS Block B.
RDS Block B Data.
typedef uint16_t si470x_reg0e |
RDS Block C.
RDS Block C Data.
typedef uint16_t si470x_reg0f |
RDS Block D.
RDS Block D Data.