PU2CLR BK108X Arduino Library 1.0.2
This is an Arduino Library to control the BK108X device
Loading...
Searching...
No Matches
Basic Functions

Functions

void BK108X::setI2CAddress (int bus_addr)
 Sets the I2C bus address.
 
void BK108X::setDelayAfterCrystalOn (uint8_t ms_value)
 Set the Delay After Crystal On (default 500ms)
 
uint16_t BK108X::getShadownRegister (uint8_t register_number)
 Get the Shadown Register object.
 
void BK108X::setShadownRegister (uint8_t register_number, uint16_t value)
 Sets a given value to the Shadown Register.
 
uint8_t BK108X::getCurrentMode ()
 Get the Current Mode (AM or FM)
 
void BK108X::setStereoThresholdPilotStrength (uint8_t value)
 Sets the Stereo Threshold of Pilotto Strength.
 
void BK108X::setFmDeemphasis (uint8_t de)
 Sets De-emphasis.
 
void BK108X::setTimeCallStrengthPilot (uint8_t value)
 Sets the time used to call the strength of pilot.
 
uint16_t BK108X::getRegister (uint8_t reg)
 Gets a givens current register content of the device.
 
void BK108X::setRegister (uint8_t reg, uint16_t value)
 Sets a given value to the device registers.
 
bk_reg0a BK108X::getStatus ()
 Gets the current status (register 0x0A) content.
 
void BK108X::waitAndFinishTune ()
 Wait STC (Seek/Tune Complete) status becomes 0.
 
void BK108X::reset ()
 Resets the device.
 
void BK108X::powerUp ()
 Powers the receiver on.
 
void BK108X::powerDown ()
 Powers the receiver off.
 
void BK108X::setup (int sda_pin, int sclk_pin, int rdsInterruptPin=-1, int seekInterruptPin=-1, uint8_t oscillator_type=OSCILLATOR_TYPE_CRYSTAL)
 Starts the device.
 
void BK108X::setFM (uint16_t minimum_frequency, uint16_t maximum_frequency, uint16_t default_frequency, uint16_t step)
 Sets the receiver to FM mode.
 
void BK108X::setAM (uint16_t minimum_frequency, uint16_t maximum_frequency, uint16_t default_frequency, uint16_t step, uint16_t am_space=0)
 Sets the receiver to AM mode.
 
void BK108X::setChannel (uint16_t channel)
 Sets the channel.
 
void BK108X::setFrequency (uint16_t frequency)
 Sets the FM frequency.
 
void BK108X::setFrequencyUp ()
 Increments the current frequency.
 
void BK108X::setFrequencyDown ()
 Decrements the current frequency.
 
uint16_t BK108X::getFrequency ()
 Gets the current frequency.
 
uint16_t BK108X::getChannel ()
 Gets the current channel.
 
uint16_t BK108X::getRealChannel ()
 Gets the current channel stored in register 0x0B.
 
uint16_t BK108X::getRealFrequency ()
 Gets the frequency based on READCHAN register (0x0B)
 
void BK108X::seekSoftware (uint8_t seek_mode, uint8_t direction, void(*showFunc)()=NULL)
 Seeks a station via Software.
 
void BK108X::seekHardware (uint8_t seek_mode, uint8_t direction)
 Seeks a station via hardware functionality.
 
void BK108X::setSeekThreshold (uint8_t rssiValue, uint8_t snrValue)
 Sets RSSI and SNR Seek Threshold.
 
void BK108X::setBand (uint8_t band=1)
 Sets the current band for AM or FM

 
void BK108X::setSpace (uint8_t space=0)
 Sets the Space channel for AM or FM.
 
int BK108X::getRssi ()
 Gets the current Rssi.
 
int BK108X::getSnr ()
 Gets the current SNR.
 
void BK108X::setSoftMute (bool value)
 Sets the Softmute true or false.
 
void BK108X::setSoftMuteAttack (uint8_t value)
 Sets Softmute Attack/Recover Rate.
 
void BK108X::setSoftMuteAttenuation (uint8_t value)
 Sets Softmute Attenuation.
 
void BK108X::setMuteThreshold (uint8_t rssi, uint8_t snr)
 Set the Mute Threshold based on RSSI and SNR.
 
void BK108X::setSeekMute (bool value)
 Disable or Enable soft mute when seeking.
 
void BK108X::setAfcMute (bool value)
 Disable or Enable soft mute when AFCRL is high.
 
void BK108X::setAudioMute (bool left, bool right)
 Sets the Mute true or false.
 
void BK108X::setAudioMute (bool value)
 Sets the Mute true or false.
 
void BK108X::setMono (bool value)
 Sets the Mono true or false (stereo)
 
bool BK108X::isStereo ()
 Checks stereo / mono status.
 
void BK108X::setVolume (uint8_t value)
 Sets the audio volume level.
 
uint8_t BK108X::getVolume ()
 Gets the current audio volume level.
 
void BK108X::setVolumeUp ()
 Increments the audio volume.
 
void BK108X::setVolumeDown ()
 Decrements the audio volume.
 

Detailed Description

Basic

Function Documentation

◆ setI2CAddress()

void BK108X::setI2CAddress ( int  bus_addr)
inline

Sets the I2C bus address.

This function must to be called before setup function if your device are not using 0x10 (default)

Parameters
bus_addrI2C buss address

Definition at line 834 of file BK108X.h.

References BK108X::deviceAddress.

◆ setDelayAfterCrystalOn()

void BK108X::setDelayAfterCrystalOn ( uint8_t  ms_value)
inline

Set the Delay After Crystal On (default 500ms)

Parameters
ms_valueValue in milliseconds

Definition at line 842 of file BK108X.h.

◆ getShadownRegister()

uint16_t BK108X::getShadownRegister ( uint8_t  register_number)
inline

Get the Shadown Register object.

if you want to get the current value of the device register, call getAllRegisters() before calling this function.

if you are dealing with the status register (0x0A), you can call getStatus() instead getAllRegisters().

See also
setAllRegisters, getAllRegisters, getShadownRegister, getStatus
Parameters
register_number
Returns
16 bits word with the Shadown registert

Definition at line 857 of file BK108X.h.

◆ setShadownRegister()

void BK108X::setShadownRegister ( uint8_t  register_number,
uint16_t  value 
)
inline

Sets a given value to the Shadown Register.

You have to call setAllRegisters() after setting the Shadow Registers to store the value into the device.

See also
setAllRegisters, getAllRegisters, getShadownRegister, getStatus
Parameters
register_numberregister index (from 0x00 to 0x0F)
value16 bits word with the content of the register

Definition at line 867 of file BK108X.h.

◆ getCurrentMode()

uint8_t BK108X::getCurrentMode ( )
inline

Get the Current Mode (AM or FM)

Returns
uint8_t 0 = FM; 1 = AM

Definition at line 888 of file BK108X.h.

◆ setStereoThresholdPilotStrength()

void BK108X::setStereoThresholdPilotStrength ( uint8_t  value)
inline

Sets the Stereo Threshold of Pilotto Strength.

Parameters
value0 ~ 7

Definition at line 896 of file BK108X.h.

◆ setFmDeemphasis()

void BK108X::setFmDeemphasis ( uint8_t  de)
inline

Sets De-emphasis.

75 μs. Used in USA (default); 50 μs. Used in Europe, Australia, Japan.

Parameters
de0 = 75 μs; 1 = 50 μs

Definition at line 908 of file BK108X.h.

◆ setTimeCallStrengthPilot()

void BK108X::setTimeCallStrengthPilot ( uint8_t  value)
inline

Sets the time used to call the strength of pilot.

Parameters
value0 ~ 3

Definition at line 920 of file BK108X.h.

◆ getRegister()

uint16_t BK108X::getRegister ( uint8_t  reg)

Gets a givens current register content of the device.

See also
shadowRegisters;
Parameters
deviceregister address
Returns
the register content (the shadowRegisters array has this content. So, you do not need to use it most of the cases)

Definition at line 273 of file BK108X.cpp.

◆ setRegister()

void BK108X::setRegister ( uint8_t  reg,
uint16_t  value 
)

Sets a given value to the device registers.

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 BK108X.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.

See also
shadowRegisters;
Parameters
deviceregister address

Definition at line 293 of file BK108X.cpp.

◆ getStatus()

bk_reg0a BK108X::getStatus ( )

Gets the current status (register 0x0A) content.

You can use this function when you need to get more than one status attribute at once.

See example code below.

bk_reg0a status = getStatus();
Serial.println(status.refined.ST); // Stereo Signal Received Indicator
Serial.println(status.refined.RSSI); // Current RSSI value
Serial.println(status.refined.RDSR); // RDS Ready Indicator
struct bk_reg0a::@10 refined
Register 0Ah. Status2 (0x0000)
Definition: BK108X.h:332
bk_reg0a getStatus()
Gets the current status (register 0x0A) content.
Definition: BK108X.cpp:338
See also
getRSSI
BK1086/88E - BROADCAST AM/FM/SW/LW RADIO RECEIVER Rev 1.3; page 17.
Returns
bk_reg0a data type status register (Register 0Ah. Status2)

Definition at line 338 of file BK108X.cpp.

◆ waitAndFinishTune()

void BK108X::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 BK108X clears the STC bit.

Definition at line 352 of file BK108X.cpp.

Referenced by BK108X::setChannel().

◆ reset()

void BK108X::reset ( )

Resets the device.

Definition at line 368 of file BK108X.cpp.

◆ powerUp()

void BK108X::powerUp ( )

Powers the receiver on.

Starts the receiver and set default configurations suggested by the BELEN

See also
BEKEN - BK1086/88 - BROADCAST AM/FM/SW/LW RADIO RECEIVER Rev 1.3; pages 12-21
setup

Definition at line 385 of file BK108X.cpp.

Referenced by BK108X::setup().

◆ powerDown()

void BK108X::powerDown ( )

Powers the receiver off.

Definition at line 433 of file BK108X.cpp.

◆ setup()

void BK108X::setup ( int  sda_pin,
int  sclk_pin,
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.

You have to inform at least two parameters: RESET pin and I2C SDA pin of your MCU

Parameters
rdsInterruptPin// optional. Sets the Interrupt 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 Crystal (default) or Ref. Clock.

Definition at line 450 of file BK108X.cpp.

References BK108X::i2cInit(), BK108X::powerUp(), BK108X::rdsInterruptPin, and BK108X::seekInterruptPin.

◆ setFM()

void BK108X::setFM ( uint16_t  minimum_frequency,
uint16_t  maximum_frequency,
uint16_t  default_frequency,
uint16_t  step 
)

Sets the receiver to FM mode.

Configures the receiver on FM mode; Also sets the band limits, defaul frequency and step.

Parameters
minimum_frequencyminimum frequency for the band
maximum_frequencymaximum frequency for the band
default_frequencydefault freuency
stepincrement and decrement frequency step in KHz (default 10 * 10KHz)

Definition at line 476 of file BK108X.cpp.

◆ setAM()

void BK108X::setAM ( uint16_t  minimum_frequency,
uint16_t  maximum_frequency,
uint16_t  default_frequency,
uint16_t  step,
uint16_t  am_space = 0 
)

Sets the receiver to AM mode.

Configures the receiver on AM mode; Also sets the band limits, defaul frequency and step.

Parameters
minimum_frequencyminimum frequency for the band
maximum_frequencymaximum frequency for the band
default_frequencydefault freuency
stepincrement and decrement frequency step

Definition at line 504 of file BK108X.cpp.

◆ setChannel()

void BK108X::setChannel ( uint16_t  channel)

Sets the channel.

Parameters
channel

Definition at line 535 of file BK108X.cpp.

References BK108X::waitAndFinishTune().

◆ setFrequency()

void BK108X::setFrequency ( uint16_t  frequency)

Sets the FM frequency.

....

Parameters
frequency

Definition at line 556 of file BK108X.cpp.

◆ setFrequencyUp()

void BK108X::setFrequencyUp ( )

Increments the current frequency.

The increment uses the band space as step.

Definition at line 575 of file BK108X.cpp.

◆ setFrequencyDown()

void BK108X::setFrequencyDown ( )

Decrements the current frequency.

The drecrement uses the band space as step.

Definition at line 590 of file BK108X.cpp.

◆ getFrequency()

uint16_t BK108X::getFrequency ( )

Gets the current frequency.

Returns
uint16_t

Definition at line 605 of file BK108X.cpp.

◆ getChannel()

uint16_t BK108X::getChannel ( )

Gets the current channel.

Returns
uint16_t

Definition at line 615 of file BK108X.cpp.

◆ getRealChannel()

uint16_t BK108X::getRealChannel ( )

Gets the current channel stored in register 0x0B.

This method is useful to query the current channel during the seek operations.

Returns
uint16_t

Definition at line 626 of file BK108X.cpp.

◆ getRealFrequency()

uint16_t BK108X::getRealFrequency ( )

Gets the frequency based on READCHAN register (0x0B)

Unlike getFrequency method, this method queries the device.

Returns
uint16_t

Definition at line 639 of file BK108X.cpp.

◆ seekSoftware()

void BK108X::seekSoftware ( uint8_t  seek_mode,
uint8_t  direction,
void(*)()  showFunc = NULL 
)

Seeks a station via Software.

Todo:
it is not working properly

Seeks a station up or down.

Seek up or down a station and call a function defined by the user to show the frequency during the seek process.

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.

It is important to say you have to implement a show frequency function. This function have to get the frequency via getFrequency function.

Example:

BK108X rx;
void showFrequency() {
uint16_t freq = rx.getFrequency();
Serial.print(freq);
Serial.println("MHz ");
}
void loop() {
.
.
rx.seek(BK_SEEK_WRAP, BK_SEEK_UP, showFrequency); // Seek Up
.
.
}
#define BK_SEEK_WRAP
Definition: BK108X.h:34
#define BK_SEEK_UP
Seek Up Direction.
Definition: BK108X.h:33
void seek(uint8_t seek_mode, uint8_t direction, void(*showFunc)()=NULL)
Definition: BK108X.h:1053
KT0915 Class.
Definition: BK108X.h:725
uint16_t getFrequency()
Gets the current frequency.
Definition: BK108X.cpp:605
Parameters
seek_modeSeek Mode; 0 = Wrap at the upper or lower band limit and continue seeking (default); 1 = Stop seeking at the upper or lower band limit.
directionSeek Direction; 0 = Seek down (default); 1 = Seek up.
showFuncfunction that you have to implement to show the frequency during the seeking process. Set NULL if you do not want to show the progress.

Definition at line 684 of file BK108X.cpp.

◆ seekHardware()

void BK108X::seekHardware ( uint8_t  seek_mode,
uint8_t  direction 
)

Seeks a station via hardware functionality.

Todo:
make it work.
Parameters
seek_modeSeek Mode; 0 = Wrap at the upper or lower band limit and continue seeking (default); 1 = Stop seeking at the upper or lower band limit.
directionSeek Direction; 0 = Seek down (default); 1 = Seek up.

Definition at line 726 of file BK108X.cpp.

◆ setSeekThreshold()

void BK108X::setSeekThreshold ( uint8_t  rssiValue,
uint8_t  snrValue 
)

Sets RSSI and SNR Seek Threshold.

Todo:
make it work.
Parameters
rssiValuebetween 0 and 127
snrValuebetween 0 and 127

Definition at line 762 of file BK108X.cpp.

◆ setBand()

void BK108X::setBand ( uint8_t  band = 1)

Sets the current band for AM or FM

Configures the band by setting the Register 05h. System Configuration2

Band value AM / KHz FM / MHz
0 LW - 153~279 FULL - 64~108
1 MW - 520~1710 East Europe 64~76
2 SW - 2.3~21.85 Japan 76~91
3 MW - 522~1710 Europe 87~108
See also
BK1086/88E - BROADCAST AM/FM/SW/LW RADIO RECEIVER Rev 1.3; page 15
Parameters
bandthe valid values are 0, 1, 2 and 3. See table above.

Definition at line 787 of file BK108X.cpp.

◆ setSpace()

void BK108X::setSpace ( uint8_t  space = 0)

Sets the Space channel for AM or FM.

Band value AM FM
0 1 KHz 10 KHz
1 5 KKz 50 KHz
2 9 KHz 100 KHz
3 10 KHz 200 KHz
See also
BK1086/88E - BROADCAST AM/FM/SW/LW RADIO RECEIVER Rev 1.3; page 15
Parameters
spacevalid values 0,1,2 and 3. See table above.

Definition at line 812 of file BK108X.cpp.

◆ getRssi()

int BK108X::getRssi ( )

Gets the current Rssi.

Returns
int

Definition at line 829 of file BK108X.cpp.

◆ getSnr()

int BK108X::getSnr ( )

Gets the current SNR.

Returns
int The SNR Value.( in dB)

Definition at line 841 of file BK108X.cpp.

◆ setSoftMute()

void BK108X::setSoftMute ( bool  value)

Sets the Softmute true or false.

Enable or Disable Soft Mute resource.

Parameters
valueTRUE or FALSE

Definition at line 853 of file BK108X.cpp.

◆ setSoftMuteAttack()

void BK108X::setSoftMuteAttack ( uint8_t  value)

Sets Softmute Attack/Recover Rate.

Soft mute Attack/Recover

Value Description
0 fastest
1 fast
2 slow
3 slowest
Parameters
valueSee table above.

Definition at line 874 of file BK108X.cpp.

◆ setSoftMuteAttenuation()

void BK108X::setSoftMuteAttenuation ( uint8_t  value)

Sets Softmute Attenuation.

Soft mute Attenuation.

Value Description
0 fastest
1 fast
2 slow
3 slowest
Parameters
valueSee table above

Definition at line 893 of file BK108X.cpp.

◆ setMuteThreshold()

void BK108X::setMuteThreshold ( uint8_t  rssi,
uint8_t  snr 
)

Set the Mute Threshold based on RSSI and SNR.

See also
BK1086/88 - BROADCAST AM/FM/SW/LW RADIO RECEIVER Rev 1.3; page 19; Register 0x14 (Boot Configuration5)
Parameters
rssiThe Mute Threshold Based on RSSI (default 26)
snrThe Mute Threshold Based on SNR (default 5)

Definition at line 907 of file BK108X.cpp.

◆ setSeekMute()

void BK108X::setSeekMute ( bool  value)

Disable or Enable soft mute when seeking.

Parameters
valueIf true, enable mute during the seek;

Definition at line 920 of file BK108X.cpp.

◆ setAfcMute()

void BK108X::setAfcMute ( bool  value)

Disable or Enable soft mute when AFCRL is high.

Parameters
valueIf true, enable soft mute when AFCRL is high

Definition at line 931 of file BK108X.cpp.

◆ setAudioMute() [1/2]

void BK108X::setAudioMute ( bool  left,
bool  right 
)

Sets the Mute true or false.

Parameters
leftleft channel (TRUE = MUTE/ FALSE = UNMUTE)
leftright channel (TRUE = MUTE / FALSE = UMUTE)

Definition at line 945 of file BK108X.cpp.

Referenced by BK108X::setAudioMute().

◆ setAudioMute() [2/2]

void BK108X::setAudioMute ( bool  value)

Sets the Mute true or false.

Parameters
valueleft and right channels (TRUE = MUTE/ FALSE = UNMUTE)

Definition at line 958 of file BK108X.cpp.

References BK108X::setAudioMute().

◆ setMono()

void BK108X::setMono ( bool  value)

Sets the Mono true or false (stereo)

if TRUE, force mono; else force stereo

Parameters
valueTRUE or FALSE

Definition at line 969 of file BK108X.cpp.

◆ isStereo()

bool BK108X::isStereo ( )

Checks stereo / mono status.

See also
getStatus
Parameters
valueTRUE if stereo

Definition at line 983 of file BK108X.cpp.

◆ setVolume()

void BK108X::setVolume ( uint8_t  value)

Sets the audio volume level.

Parameters
value0 to 31 (if 0, mutes the audio)

Definition at line 995 of file BK108X.cpp.

◆ getVolume()

uint8_t BK108X::getVolume ( )

Gets the current audio volume level.

Returns
uint8_t 0 to 15

Definition at line 1011 of file BK108X.cpp.

◆ setVolumeUp()

void BK108X::setVolumeUp ( )

Increments the audio volume.

Definition at line 1021 of file BK108X.cpp.

◆ setVolumeDown()

void BK108X::setVolumeDown ( )

Decrements the audio volume.

Definition at line 1035 of file BK108X.cpp.