# rda5807m

Library for the RDA5807M FM RadioTuner.

Author | Rob Jansen, Copyright © 2023..2023, all rights reserved.
Adapted-by |
Compiler | 2.5r7

Description

    Library for controlling the RDA5807M Radio Tuner.
                 The chip uses an IIC interface which must be defined by
                 the main program.

Sources

    Single-Chip Broadcast FM Radio Tuner Rev.1.8–Aug.2014

Notes

    The main program has to define and include the used IIC library and
           if needed define aliases to rule out differences between IIC
           libraries. The chip operates at 3.3 Volt so make sure to use a level
           shifter on the IIC lines if your PIC is running at 5 Volt.

Dependencies

No dependency found

## Summary

### Global variables/contants

- `var word _rda5807m_mirror_r2`
- `var word _rda5807m_mirror_r3`
- `const word _RDA5807M_MASK_R2_SEEKUP = 0x0200`
- `const word _RDA5807M_MASK_R2_RDS = 0x0008`
- `var word _rda5807m_mirror_r4`
- `var word _rda5807m_mirror_r5`
- `const word _RDA5807M_MASK_R3_TEST = 0x0020`
- `const byte _RDA5807M_REG_R0 = 0x00`
- `const byte RDA5807M_DEEMPHASIS_50_US = 0`
- `const word _RDA5807M_MASK_R2_BASS = 0x1000`
- `const word _RDA5807M_MASK_R2_OUTPUT = 0x8000`
- `const word _RDA5807M_REG_RA_CHANNEL = 0x03FF`
- `const word _RDA5807M_MASK_R5_VOL = 0x000F`
- `var dword rda5807m_band_frequency_high`
- `const word _RDA5807M_MASK_R3_BAND_WORLD = 0x0008`
- `const word _RDA5807M_REG_RA_RDS = 0x8000`
- `const word _RDA5807M_MASK_R3_BAND = 0x000C`
- `const byte RDA5807M_SPACING_50_KHZ = 1`
- `const byte _RDA5807M_REG_RA = 0x0A`
- `const byte RDA5807M_VOLUME_MAX = 15`
- `const byte _RDA5807M_IIC_RD_ADDRESS = 0b0010_0011`
- `const byte RDA5807M_SPACING_200_KHZ = 3`
- `const word _RDA5807M_MASK_R3_SPACE_200 = 0x0001`
- `const word _RDA5807M_MASK_R4_DE50 = 0x0800`
- `const word _RDA5807M_MASK_R3_SPACE_100 = 0x0000`
- `const word _RDA5807M_MASK_R3_SPACE_25 = 0x0003`
- `const byte _RDA5807M_REG_R3 = 0x03`
- `const word _RDA5807M_MASK_R4_SOFTMUTE = 0x0200`
- `const byte RDA5807M_BAND_EAST_EUROPE = 3`
- `const word _RDA5807M_MASK_R2_NEW = 0x0004`
- `const word _RDA5807M_MASK_R3_TUNE = 0x0010`
- `const word _RDA5807M_MASK_R3_CHANNEL = 0xFFC0`
- `const word _RDA5807M_MASK_R4_AFC = 0x0100`
- `const word _RDA5807M_MASK_R3_BAND_JAPAN = 0x0004`
- `const word _RDA5807M_MASK_R2_SEEK = 0x0100`
- `const byte _RDA5807M_REG_RDSA = 0x0C`
- `const word _RDA5807M_MASK_R3_SPACE = 0x0003`
- `const byte RDA5807M_SPACING_25_KHZ = 0`
- `const word _RDA5807M_MASK_R2_RESET = 0x0002`
- `var byte _rda5807m_spacing`
- `const word _RDA5807M_MASK_R3_SPACE_50 = 0x0002`
- `const byte _RDA5807M_REG_RDSD = 0x0F`
- `const word _RDA5807M_REG_RA_STEREO = 0x0400`
- `const word _RDA5807M_REG_RA_RDSBLOCK = 0x0800`
- `const byte RDA5807M_BAND_JAPAN = 1`
- `const byte RDA5807M_RSSI_MIN = 0`
- `const word _RDA5807M_MASK_R2_DMUTE = 0x4000`
- `const word _RDA5807M_REG_RB_FMTRUE = 0x0100`
- `const byte _RDA5807M_REG_RDSC = 0x0E`
- `const word _RDA5807M_MASK_R2_MONO = 0x2000`
- `const byte RDA5807M_BAND_WORLD_WIDE = 2`
- `var dword rda5807m_band_frequency_low`
- `const word _RDA5807M_MASK_R4_FIFO_CLR = 0x0400`
- `const byte RDA5807M_BAND_US_EUROPE = 0`
- `const word _RDA5807M_MASK_R2_ENABLE = 0x0001`
- `const byte _RDA5807M_REG_RB = 0x0B`
- `const byte _RDA5807M_IIC_WR_ADDRESS = 0b0010_0010`
- `const byte RDA5807M_RSSI_MAX = 127`
- `const byte _RDA5807M_REG_R5 = 0x05`
- `const byte _RDA5807M_REG_R2 = 0x02`
- `const byte RDA5807M_SPACING_100_KHZ = 2`
- `const byte _RDA5807M_REG_RDSB = 0x0D`
- `const word _RDA5807M_MASK_R3_BAND_US_EUR = 0x0000`
- `const byte RDA5807M_VOLUME_MIN = 0`
- `const byte RDA5807M_DEEMPHASIS_75_US = 1`
- `const word _RDA5807M_REG_RA_SEEK = 0x4000`
- `const word _RDA5807M_REG_RB_RSSI = 0xFE00`
- `const byte _RDA5807M_REG_R4 = 0x04`
- `const word _RDA5807M_REG_RB_FMREADY = 0x0080`
- `const word _RDA5807M_MASK_R3_BAND_EAST_EUR = 0x000C`

### Procedures

- `rda5807m_disable_rds()`
- `rda5807m_unmute()`
- `rda5807m_enable_bass_boost()`
- `rda5807m_enable_power()`
- `rda5807m_enable_rds()`
- `rda5807m_seek_stop()`
- `rda5807m_set_deemphasis(byte in deemphasis_value)`
- `rda5807m_set_output_stereo()`
- `rda5807m_disable_bass_boost()`
- `rda5807m_mute()`
- `rda5807m_write_register(byte in register, word in data)`
- `rda5807m_set_frequency(dword in frequency)`
- `rda5807m_set_channel_spacing(byte in channel_spacing)`
- `rda5807m_disable_soft_mute()`
- `rda5807m_seek_down()`
- `rda5807m_disable_power()`
- `rda5807m_set_band(byte in band_selection)`
- `rda5807m_set_volume(byte in volume)`
- `rda5807m_enable_output()`
- `rda5807m_set_output_mono()`
- `rda5807m_seek_up()`
- `rda5807m_print_status()`
- `rda5807m_enable_soft_mute()`
- `rda5807m_disable_output()`
- `rda5807m_init()`

### Functions

- `rda5807m_read_register(byte in register) return word`
- `rda5807m_channel_is_stereo() return bit`
- `rda5807m_channel_is_fm() return bit`
- `rda5807m_get_signal_strength() return byte`
- `rda5807m_get_frequency() return dword`
- `rda5807m_seek_completed() return bit`
- `rda5807m_channel_is_ready() return bit`
- `rda5807m_channel_has_rds() return bit`

## API details

### Global variables/contants

- `var word _rda5807m_mirror_r2`

      We need to keep a mirror of all write only registers.

- `var word _rda5807m_mirror_r3`

  No documentation found

- `const word _RDA5807M_MASK_R2_SEEKUP = 0x0200`

  No documentation found

- `const word _RDA5807M_MASK_R2_RDS = 0x0008`

  No documentation found

- `var word _rda5807m_mirror_r4`

  No documentation found

- `var word _rda5807m_mirror_r5`

  No documentation found

- `const word _RDA5807M_MASK_R3_TEST = 0x0020`

  No documentation found

- `const byte _RDA5807M_REG_R0 = 0x00`

      Register R0. Holds the chip ID but we do not use it.

- `const byte RDA5807M_DEEMPHASIS_50_US = 0`

      Deemphasis options.

- `const word _RDA5807M_MASK_R2_BASS = 0x1000`

  No documentation found

- `const word _RDA5807M_MASK_R2_OUTPUT = 0x8000`

  No documentation found

- `const word _RDA5807M_REG_RA_CHANNEL = 0x03FF`

  No documentation found

- `const word _RDA5807M_MASK_R5_VOL = 0x000F`

  No documentation found

- `var dword rda5807m_band_frequency_high`

      Highest frequency of the selected band in kHz.

- `const word _RDA5807M_MASK_R3_BAND_WORLD = 0x0008`

  No documentation found

- `const word _RDA5807M_REG_RA_RDS = 0x8000`

  No documentation found

- `const word _RDA5807M_MASK_R3_BAND = 0x000C`

  No documentation found

- `const byte RDA5807M_SPACING_50_KHZ = 1`

  No documentation found

- `const byte _RDA5807M_REG_RA = 0x0A`

      Register RA. Read only status register.

- `const byte RDA5807M_VOLUME_MAX = 15`

  No documentation found

- `const byte _RDA5807M_IIC_RD_ADDRESS = 0b0010_0011`

  No documentation found

- `const byte RDA5807M_SPACING_200_KHZ = 3`

  No documentation found

- `const word _RDA5807M_MASK_R3_SPACE_200 = 0x0001`

  No documentation found

- `const word _RDA5807M_MASK_R4_DE50 = 0x0800`

  No documentation found

- `const word _RDA5807M_MASK_R3_SPACE_100 = 0x0000`

  No documentation found

- `const word _RDA5807M_MASK_R3_SPACE_25 = 0x0003`

  No documentation found

- `const byte _RDA5807M_REG_R3 = 0x03`

      Register R3. Write only control register.

- `const word _RDA5807M_MASK_R4_SOFTMUTE = 0x0200`

  No documentation found

- `const byte RDA5807M_BAND_EAST_EUROPE = 3`

      56 .. 67 or 50 .. 65 MHz.

- `const word _RDA5807M_MASK_R2_NEW = 0x0004`

  No documentation found

- `const word _RDA5807M_MASK_R3_TUNE = 0x0010`

  No documentation found

- `const word _RDA5807M_MASK_R3_CHANNEL = 0xFFC0`

  No documentation found

- `const word _RDA5807M_MASK_R4_AFC = 0x0100`

  No documentation found

- `const word _RDA5807M_MASK_R3_BAND_JAPAN = 0x0004`

  No documentation found

- `const word _RDA5807M_MASK_R2_SEEK = 0x0100`

  No documentation found

- `const byte _RDA5807M_REG_RDSA = 0x0C`

      RDS registers. Read only data register.

- `const word _RDA5807M_MASK_R3_SPACE = 0x0003`

  No documentation found

- `const byte RDA5807M_SPACING_25_KHZ = 0`

      Channel spacing selection options.

- `const word _RDA5807M_MASK_R2_RESET = 0x0002`

  No documentation found

- `var byte _rda5807m_spacing`

      Local variables.

- `const word _RDA5807M_MASK_R3_SPACE_50 = 0x0002`

  No documentation found

- `const byte _RDA5807M_REG_RDSD = 0x0F`

  No documentation found

- `const word _RDA5807M_REG_RA_STEREO = 0x0400`

  No documentation found

- `const word _RDA5807M_REG_RA_RDSBLOCK = 0x0800`

  No documentation found

- `const byte RDA5807M_BAND_JAPAN = 1`

      76 .. 91 MHz.

- `const byte RDA5807M_RSSI_MIN = 0`

      Signal strength (RSSI) levels.

- `const word _RDA5807M_MASK_R2_DMUTE = 0x4000`

  No documentation found

- `const word _RDA5807M_REG_RB_FMTRUE = 0x0100`

  No documentation found

- `const byte _RDA5807M_REG_RDSC = 0x0E`

  No documentation found

- `const word _RDA5807M_MASK_R2_MONO = 0x2000`

  No documentation found

- `const byte RDA5807M_BAND_WORLD_WIDE = 2`

      76 .. 108 MHz.

- `var dword rda5807m_band_frequency_low`

       Variables.
      Lowest frequency of the selected band in kHz.

- `const word _RDA5807M_MASK_R4_FIFO_CLR = 0x0400`

  No documentation found

- `const byte RDA5807M_BAND_US_EUROPE = 0`

      Band selection options.

- `const word _RDA5807M_MASK_R2_ENABLE = 0x0001`

  No documentation found

- `const byte _RDA5807M_REG_RB = 0x0B`

      Register RB. Read only status register.

- `const byte _RDA5807M_IIC_WR_ADDRESS = 0b0010_0010`

      IIC read and IIC write address of the RDA5807M. The data sheet is not clear
      (not complete!) on this. Apparently the device has two modes of operation,
      sequential access and random access. This access type depends on the chosen
      IIC address. Only the random access mode is used by this library.
      const byte _RDA5807M_IIC_WR_ADDRESS = 0b0010_0000 -- Sequential access mode.
      const byte _RDA5807M_IIC_RD_ADDRESS = 0b0010_0001

- `const byte RDA5807M_RSSI_MAX = 127`

  No documentation found

- `const byte _RDA5807M_REG_R5 = 0x05`

      Register R5. Write only control register.

- `const byte _RDA5807M_REG_R2 = 0x02`

      Register R2. Write only control register.

- `const byte RDA5807M_SPACING_100_KHZ = 2`

      Used for Europe.

- `const byte _RDA5807M_REG_RDSB = 0x0D`

  No documentation found

- `const word _RDA5807M_MASK_R3_BAND_US_EUR = 0x0000`

  No documentation found

- `const byte RDA5807M_VOLUME_MIN = 0`

      Volume levels.

- `const byte RDA5807M_DEEMPHASIS_75_US = 1`

  No documentation found

- `const word _RDA5807M_REG_RA_SEEK = 0x4000`

  No documentation found

- `const word _RDA5807M_REG_RB_RSSI = 0xFE00`

  No documentation found

- `const byte _RDA5807M_REG_R4 = 0x04`

      Regiser R4. Write only control register.

- `const word _RDA5807M_REG_RB_FMREADY = 0x0080`

  No documentation found

- `const word _RDA5807M_MASK_R3_BAND_EAST_EUR = 0x000C`

  No documentation found

### Procedures

- `rda5807m_disable_rds()`

      Disable the RDS off the RDA5807M.

- `rda5807m_unmute()`

      Unmute the output off the RDA5807M.

- `rda5807m_enable_bass_boost()`

      Enable the bass boost off the RDA5807M.

- `rda5807m_enable_power()`

      Enable the RDA5807M.

- `rda5807m_enable_rds()`

      Enable the RDS of the RDA5807M.

- `rda5807m_seek_stop()`

      Stop seeking to the next channel.

- `rda5807m_set_deemphasis(byte in deemphasis_value)`

      Set De-emphasis of the RDA5807M to the given value. Value must be
      RDA5807M_DEEMPHASIS_50_US or RDA5807M_DEEMPHASIS_75_US.

- `rda5807m_set_output_stereo()`

      Set the output of the RDA5807M to stereo.

- `rda5807m_disable_bass_boost()`

      Disable the bass boost off the RDA5807M.

- `rda5807m_mute()`

      Mute the output off the RDA5807M.

- `rda5807m_write_register(byte in register, word in data)`

      Write a byte to the given register of the DS3231.

- `rda5807m_set_frequency(dword in frequency)`

      Set the frequency of the RDA5807M. The given frequency is given in kHz and
      must be in the range of the selectded band.

- `rda5807m_set_channel_spacing(byte in channel_spacing)`

      Set the channel spacing of the RDA5807M.

- `rda5807m_disable_soft_mute()`

      Disable soft mute off the RDA5807M.

- `rda5807m_seek_down()`

      Seek down to the next channel.

- `rda5807m_disable_power()`

      Disable the RDA5807M.

- `rda5807m_set_band(byte in band_selection)`

      Set the band of the RDA5807M. This will also set the global variables that
      hold the high and low frequeny of the selected band.

- `rda5807m_set_volume(byte in volume)`

      Set the volme of the RDA5870M. Volume must be in range RDA5807M_VOLUME_MIN
      to RDA5807M_VOLUME_MAX.

- `rda5807m_enable_output()`

      Enable the output of the RDA5807M.

- `rda5807m_set_output_mono()`

      Set the output of the RDA5807M to mono.

- `rda5807m_seek_up()`

      Seek up to the next channel.

- `rda5807m_print_status()`

  No documentation found

- `rda5807m_enable_soft_mute()`

      Enable soft mute off the RDA5807M.

- `rda5807m_disable_output()`

      Disable the output of the RDA5807M.

- `rda5807m_init()`

      Intialize the RDA5807M. The device is initialized for Europe as follows:
      ) Set the band to RDA5807M_BAND_US_EUROPE
      ) Set the spacing to RDA5807M_SPACING_100_KHZ
      ) Set the de-emphasis to RDA5807M_DEEMPHASIS_50_US
      The device is reset and powered up.

### Functions

- `rda5807m_read_register(byte in register) return word`

      Read a byte from the given register of the DS3231.

- `rda5807m_channel_is_stereo() return bit`

      Returns TRUE when the selected channel is stereo.

- `rda5807m_channel_is_fm() return bit`

      Returns TRUE when the selected channel is an FM station.

- `rda5807m_get_signal_strength() return byte`

      Get the RSSI signal strength of the current selected channel.
      Return value is between RDA5807M_RSSI_MIN and RDA5807M_RSSI_MAX

- `rda5807m_get_frequency() return dword`

      Get the frequency of the RDA5807M. The frequency is returned in kHz.

- `rda5807m_seek_completed() return bit`

      Returns TRUE when a seek was completed.

- `rda5807m_channel_is_ready() return bit`

      Returns TRUE when the selected channel is ready.

- `rda5807m_channel_has_rds() return bit`

      Returns TRUE when the selected channel has RDS. RDS must be enabled.

## Related samples

Here are the list of samples which use this library:

16f1825 | 16f1825_rda5807m.jal