⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rfreadrssilevel.c

📁 ti-Chipcon CC1010 1G以下Soc源码库。包括rf,powermodes,clockmodes,flashRW,interrupts,timer,pwm,uart...所有底层驱动源码
💻 C
字号:
/*****************************************************************************
 *                                                                           *
 *        **********                                                         *
 *       ************                                                        *
 *      ***        ***                                                       *
 *      ***   +++   ***                                                      *
 *      ***   + +   ***                                                      *
 *      ***   +                            CHIPCON CC1010                    *
 *      ***   + +   ***                 HAL - RFReadRSSIlevel                *
 *      ***   +++   ***                                                      *
 *      ***       ***                                                        *
 *       ***********                                                         *
 *        *********                                                          *
 *                                                                           *
 *****************************************************************************
 * Configures/sets up and reads the current CC1010 RSSI level.               *
 *****************************************************************************
 * Author:              TOS                                                  *
 *****************************************************************************
 * Revision history:                                                         *
 *                                                                           *
 * $Log: RFReadRSSIlevel.c,v $
 * Revision 1.1  2004/01/08 19:15:32  tos
 * Initial version in CVS.
 *
 *
 *                                                                           *
 ****************************************************************************/

#include <chipcon/hal.h>
#include <chipcon/cc1010eb.h>


//----------------------------------------------------------------------------
//  char halRFReadRSSIlevel(...)
//
//  Description:
//      This function activates RSSI output on the AD2 pin, activates the ADC 
//      for channel 2 reads, the RSSI output voltage and converts it to an
//      approximation of the incoming signal's strength in dBm (range is appr.
//      -110 to -50 dBm.) The value obtained is approximate and most valid for
//      a signal @ 600 MHz. The accuracy should be no worse than +/- 10 dBm at
//      any frequency.
//      An RSSI filter circuit of one capacitor and one resistor is required to
//      be connected to the AD2 pin externally (see datasheet for details).
//      This function disrupts user ADC operation and does not restore the ADC
//      to its former state. This function differs from the "old" function in
//      the sense that it can operate in two modes, RSSI_INIT and RSSI_RUN.
//      The ADC is not powered down after each read in order to save execution
//      time. The function can be used as a carrier sense if the returned value
//      is compared to some relatively low threshold.
//  Arguments:
//      byte mode
//          Selects function mode, RSSI_INIT or RSSI_RUN.
//  Return value:
//      char
//          The converted AD2 value = RSSI value
//        
//----------------------------------------------------------------------------
char halRFReadRSSIlevel(byte rssi_mode) {
    byte val = 0;

    // If RSSI mode = run/continuous
    if(rssi_mode == RSSI_MODE_RUN){
        // Configure ADC for RSSI reading
        halConfigADC(ADC_MODE_SINGLE | ADC_REFERENCE_INTERNAL_1_25, CC1010EB_CLKFREQ, 0);
    
        // Turn on ADC
        ADC_POWER(TRUE);

        // Wait until ADC stabilized
        halWait(1, CC1010EB_CLKFREQ);

        // Select RSSI input and read sample
        ADC_SELECT_INPUT(ADC_INPUT_AD2);
        ADC_SAMPLE_SINGLE();
        val=ADC_GET_SAMPLE_8BIT();  // Get 8 MSB of sample

        // Convert value into dBm
        val = -50-((val*55)>>8);
    // Else (RSSI mode = initialisation)
    } else {
        // Activate RSSI output
        FREND|=0x02;

        // Configure ADC for RSSI reading
        halConfigADC(ADC_MODE_SINGLE | ADC_REFERENCE_INTERNAL_1_25, CC1010EB_CLKFREQ, 0);
    
        // Turn on ADC
        ADC_POWER(TRUE);

        // Wait until ADC stabilized
        halWait(200, CC1010EB_CLKFREQ);
    }

    return val;
}    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -