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

📄 rfreadrssi.c

📁 ti-Chipcon CC1010 1G以下Soc源码库。包括rf,powermodes,clockmodes,flashRW,interrupts,timer,pwm,uart...所有底层驱动源码
💻 C
字号:
/*****************************************************************************
 *                                                                           *
 *        **********                                                         *
 *       ************                                                        *
 *      ***        ***                                                       *
 *      ***   +++   ***                                                      *
 *      ***   + +   ***                                                      *
 *      ***   +                            CHIPCON CC1010                    *
 *      ***   + +   ***                   HAL - RFReadRSSI                   *
 *      ***   +++   ***                                                      *
 *      ***       ***                                                        *
 *       ***********                                                         *
 *        *********                                                          *
 *                                                                           *
 *****************************************************************************
 *                                                                           *
 *****************************************************************************
 * Author:              ROH                                                  *
 *****************************************************************************
 * Revision history:                                                         *
 *                                                                           *
 * $Log: RFReadRSSI.c,v $
 * Revision 1.2  2003/02/25 10:04:00  tos
 * Bugfix: allow ADC to settle (after power-up) before taking RSSI sample.
 *
 * Revision 1.1  2002/10/14 13:04:34  tos
 * Initial version in CVS.
 *
 *                                                                           *
 ****************************************************************************/

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


//----------------------------------------------------------------------------
//  halRFReadRSSI(...)
//
//  Description:
//      This function activates RSSI output on the AD2 pinn, 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.
//      The function can be used as a carrier sense if the returned value is
//      compared to some relatively low threshold.
//
//  Arguments:
//
//  Return value:
//      char
//          The approximate signal strength of the incoming signal in dBm.
//----------------------------------------------------------------------------
char halRFReadRSSI() {
    byte val;

    FREND|=0x02;                // Activate RSSI output

    #if (CC1010EB_CLKFREQ == 14746)
    ADCON2=0x03;                // ADC divider i 1/64 (optimal for 14.7456 MHz
                                // CLK), Interrupt not enabled.
    #else
    ADCON2=0x02;                // ADC divider i 1/48 (optimal for 11.0592 MHz
                                // CLK), Interrupt not enabled.
    #endif

    ADCON=0x0A;                 // ADC power on, single-conversion mode, 
                                // input from AD2 pin


    halWait(200, CC1010EB_CLKFREQ);

    ADC_RUN(TRUE);

    while (ADCON&0x04);         // Wait until sample is available
    
    val=ADC_GET_SAMPLE_8BIT();  // Get 8 MSB of sample
    
    ADC_POWER(FALSE);           // Power down ADC
    
    val = -50-((val*55)>>8);
    return val;
}    

⌨️ 快捷键说明

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