Announcement

Collapse
No announcement yet.

Si470x FM Radio Module

Collapse
This topic is closed.
X
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Si470x FM Radio Module

    If you just need to download the latest version of Si470x.pbpmod ... Get it here ... http://support.melabs.com/DT/Si470x.pbpmod
    Current version is 1.1
    Save it to your PBP3 folder.
    If you want to know how it works ... keep reading.

    This module is for PBP3 ver. 3.0.6.x and higher only.
    Download the latest version of PicBasic Pro from http://pbp3.com/download.html
    It creates an easy interface to the Si4703 from Silicon laboratories, using just about any PIC chip.
    Along with being a complete digital FM stereo tuner, the Si4703 also receives the RDS/RBDS information which gives song titles, station ID's and other information.

    Sparkfun has a few breakout boards that make things easier, since the chip is so small it would be nearly impossible to hand solder onto a board. The two on the left also have an amplifier for headphones. The one on the right gives Line level audio outputs that would require an external amplifier.

    This module uses the new USERCOMMAND and Conditional Compiling abilities of PBP3 to create easy commands for use in your program.

    Available Commands: () indicates the command requires a parameter
    Si470x_INITIALIZE . . . . . . Resets and Initializes the radio module.
    Si470x_TUNE() . . . . . . . . Tune to a specific frequency
    Si470x_VOLUME() . . . . . . . Volume Up, Down or to a specific level
    Si470x_SEEK() . . . . . . . . Seek Up or Down
    SI470X_SEEKSNR(). . . . . . . Seek Signal to Noise Ratio
    SI470X_SEEKIMP(). . . . . . . Seek Impulse threshold
    SI470X_REGION() . . . . . . . Select Region .. USA, Europe, Australia, Japan, JapanWide
    SI470X_BAND() . . . . . . . . Select frequency range, 0=87.5-108, 1=76-108, 2=76-90
    SI470X_SPACE(). . . . . . . . Select channel spacing, 0=200khz, 1=100khz, 2=50khz
    SI470X_SOFTMUTEATTACK() . . . 0=fastest, 3=slowest
    SI470X_SOFTMUTEATTEN(). . . . 0=16dB, 1=14dB, 2=12dB, 3=10dB
    Si470X_GET. . . . . . . . . . Reads all registers
    Si470X_GETSTATUS. . . . . . . Reads only statusrssi and readchan
    Si470X_UPDATE . . . . . . . . Write all writable registers
    SI470X_PRESET() . . . . . . . Restore a saved station preset {requires USE_PRESETS}
    SI470X_SAVE_PRESET(). . . . . Save current station to a Preset {requires USE_PRESETS}
    Si470X_RDS_PROCESS. . . . . . Process any new RDS Packets

    Variables:
    Si470x_CURRENTFREQUENCY . . . Current Station Frequency
    Si470X_CURRENTVOLUME. . . . . Current Volume
    Si470X_CURRENTBAND. . . . . . Currently selected Band
    Si470X_CURRENTSPACE . . . . . Current channel spacing
    Si470X_CURRENTRSSI. . . . . . Received Signal Strength
    Si470X_MINFREQUENCY . . . . . Lowest frequency available in currently selected Band
    Si470X_MAXFREQUENCY . . . . . Highest frequency available in currently selected Band
    Options
    #DEFINE USE_PRESETS . . . . . Number of station presets ... 0, 10 or 20

    RDS Options
    #DEFINE USE_RDS . . . . . . . Enable/Disable all RDS functions
    #DEFINE USE_TIME. . . . . . . Capture Time Packets
    #DEFINE USE_GENRE . . . . . . Decode PTY (genre)
    #DEFINE USE_RADIOTEXT . . . . Capture RadioText information
    #DEFINE USE_PACKETTRACK . . . use Packet Tracking, required for COMPLETE flag
    #DEFINE RDS_MAXERRORS ? . . . 0=best text(slower), 3=bad text(faster)
    #DEFINE CLEARTEXT_ONCHANGE. . Clear RadioText buffer whenever it changes

    RDS Variables
    RADIOTEXT . . . . . . . . . . 64 BYTE array, song title etc.
    RADIOTEXT_LENGTH. . . . . . . Length of string in RadioText
    RADIOTEXT_CHANGED . . . . . . BIT, indicates text has changed
    RADIOTEXT_COMPLETE. . . . . . BIT, indicates the radiotext string is Complete

    GENRE . . . . . . . . . . . . 8 BYTE array, Talk, Rock, Country etc.
    GENRE_CHANGED . . . . . . . . BIT, indicates Genre has changed
    PTY . . . . . . . . . . . . . BYTE, Program Type code



    Download the module from here ... http://support.melabs.com/DT/Si470x.pbpmod
    Save it to your PBP3 folder.
    PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
    Never download a PIC datasheet from anywhere but microchip.com

  • #2
    Configure and Initialize your harware first!
    This is an example configuration for a 16F887, you will need to make changes if you are using a different chip.
    Since PBP supports over 500 chips ... How to configure a different chip is beyond the scope of this article, see section 4.9 in the PBP3 manual.
    Code:
    #CONFIG
        __config _CONFIG1, _INTRC_OSC_NOCLKOUT & _WDT_OFF & _MCLRE_OFF & _LVP_OFF & _CP_OFF & _BOREN_OFF
    #ENDCONFIG
    
    DEFINE OSC 8
    OSCCON = %01110101         ; internal oscillator @ 8 Mhz
    ANSEL  = %00000000         ; All Digital
    ANSELH = %00000000

    Once you have the chip running, here's a simple program that will get the radio working too.
    Change the TUNE frequency to a station in your area.
    Code:
    ;----[Change these to match your hardware]----------------------------------
        Si470x_SDA      VAR PORTB.1   ; radio module's I2C data pin
        Si470x_SCL      VAR PORTB.2   ; radio module's I2C clock pin
        Si470x_RST      VAR PORTB.5   ; radio module's reset pin
        RDS_LED         VAR PORTD.1   ; Optional LED, comment if not used
        STEREO_LED      VAR PORTD.0   ; Optional LED, comment if not used
        LED_POLARITY    CON 1         ; 0=Active LOW, 1=Active HIGH
        INCLUDE "Si470x.pbpmod" : CHECK_VERSION $11 ; requires Si470x  ver. 1.1      
    
    ;---------------------------------------------------------------------------
        Si470X_Initialize   ; Initialize the radio chip
        Si470X_TUNE(943)    ; Tune to 94.3 Mhz
        Si470X_VOLUME(7)    ; set Volume to half way (0-15)
    
    END
    On power-up it will play the specified station at half volume.
    Nothing can be changed, but it should tell you if your hardware is hooked up correctly.

    This program uses about 1.2K words of program space.
    With it being the absolute minimum, it means that many chips like the 12F675 won't have enough memory.
    For the full radio system, plan on using a chip with at least 8K WORDS of Flash program memory.


    Of course, you'll probably want to be able to change stations and adjust the volume.
    So Example 2 adds a 5-way joystick (also from sparkfun). You can use individual switches with pull-up resistors if you prefer, but the joystick was more convenient for my breadboard.
    BUTTON commands make it really easy.

    Code:
    ;----[Change these to match your hardware]--------------------------------------
        Si470X_SDA      VAR PORTB.1
        Si470X_SCL      VAR PORTB.2
        Si470X_RST      VAR PORTB.5
        RDS_LED         VAR PORTD.1   ; Optional LED, comment if not used
        STEREO_LED      VAR PORTD.0   ; Optional LED, comment if not used
        LED_POLARITY    CON 1         ; 0=Active LOW, 1=Active HIGH
        #DEFINE USE_PRESETS 10       ; use EEPROM station presets 0, 10 or 20
        INCLUDE "Si470x.pbpmod"  : CHECK_VERSION $11 ; requires Si470x  ver. 1.1      
    
    ;-----[Joystick Connections]----------------------------------------------------
    UP_BUTT      VAR PORTC.0
    CENTER_BUTT  VAR PORTC.1
    LEFT_BUTT    VAR PORTC.2
    DN_BUTT      VAR PORTC.3
    RIGHT_BUTT   VAR PORTC.4
    
    UP_VAR       VAR BYTE             ; Button command Variables
    DN_VAR       VAR BYTE
    LEFT_VAR     VAR BYTE
    RIGHT_VAR    VAR BYTE
    CENTER_VAR   VAR BYTE
    
    ;----[Initialization]-----------------------------------------------------------
        Si470X_Initialize   ; Initialize the radio chip
        Si470X_PRESET(1)    ; Tune to saved preset
        Si470X_VOLUME(7)    ; set Volume to half way
        Si470X_SEEKSNR(1)   ; Seek signal to noise threshold
        Si470X_SEEKIMP(1)   ; Seek impulse threshold
    
    ;----[Main program loop]--------------------------------------------------------
    Main:
        BUTTON UP_BUTT, 0, 20, 20, UP_VAR, 1, DO_UP                ; Volume Up
        BUTTON DN_BUTT, 0, 20, 20, DN_VAR, 1, DO_DN                ; Volume Down
        BUTTON LEFT_BUTT, 0, 20, 20, LEFT_VAR, 1, DO_LEFT          ; Seek Down
        BUTTON RIGHT_BUTT, 0, 255, 255, RIGHT_VAR, 1, DO_RIGHT     ; Seek Up
        BUTTON CENTER_BUTT, 0, 255, 255, CENTER_VAR, 1, DO_CENTER  ; Save Preset
        PAUSE 10                                                   ; Loop Timing
    GOTO Main
    
    ;----[Joystick Actions]---------------------------------------------------------
    DO_UP:
        Si470X_VOLUME(UP)
    GOTO Main
    
    DO_DN:
        Si470X_VOLUME(DN)
    GOTO Main
    
    DO_LEFT:
        Si470X_SEEK(DN)
    GOTO Main
    
    DO_RIGHT:
        Si470X_SEEK(UP)
    GOTO Main
    
    DO_CENTER:
        SI470X_SAVE_PRESET(1)
    GOTO Main

    Click image for larger version.

    The UP and DOWN buttons (Volume) will auto repeat. Hold the button to continue changing.
    The LEFT and RIGHT buttons (Seek) are one shot's. Release and press again to continue.
    The CENTER button saves the currently tuned station to a "PRESET" which will be restored on power-up.

    Note: The radio is 3.3V only. DO NOT power the device with +5V.
    The PIC16F887 will run at a maximum of 10Mhz at 3.3V.
    PBP3 Manual : Microchip Datasheets - 10F, 12F, 16F, 18F
    Never download a PIC datasheet from anywhere but microchip.com

    Comment

    Working...
    X