rf_fun.c

来自「LCD FUNCTION OF msp430」· C语言 代码 · 共 80 行

C
80
字号
#include "io430.h"
#include "in430.h"
#include "CC1100.h"
#include "hal_msp430.h"
#include "spi.c"
void halMcuWaitUs(uint16 usec) // 5 cycles for calling
{
    // The least we can wait is 3 usec:
    // ~1 usec for call, 1 for first compare and 1 for return

    while(usec > 3)       // 2 cycles for compare
    {                     // 2 cycles for jump
        asm("NOP");       // 1 cycles for nop
        asm("NOP");       // 1 cycles for nop
        asm("NOP");       // 1 cycles for nop
        asm("NOP");       // 1 cycles for nop
        asm("NOP");       // 1 cycles for nop
        usec -= 2;        // 1 cycles for optimized decrement
    }
} 

//----------------------------------------------------------------------------------
//  void halRfResetChip(void)
//
//  DESCRIPTION:
//    Resets the chip using the procedure described in the datasheet.
//----------------------------------------------------------------------------------
void halRfResetChip(void)
{
    // Toggle chip select signal
    HAL_SPI_CS_DEASSERT;
    halMcuWaitUs(30);
    HAL_SPI_CS_ASSERT;
    halMcuWaitUs(30);
    HAL_SPI_CS_DEASSERT;
    halMcuWaitUs(45);

    // Send SRES command
    HAL_SPI_CS_ASSERT;
    while(HAL_SPI_SOMI_VAL);
    HAL_SPI_TXBUF_SET(CC1100_SRES);
    HAL_SPI_WAIT_TXFIN;

    // Wait for chip to finish internal reset
    while (HAL_SPI_SOMI_VAL);
    HAL_SPI_CS_DEASSERT;
}

//----------------------------------------------------------------------------------
//  uint8 halRfReadStatusReg(uint8 addr)
//
//  NOTE:
//      When reading a status register over the SPI interface while the register
//      is updated by the radio hardware, there is a small, but finite, probability
//      that the result is corrupt. The CC1100 and CC1100 errata notes explain the
//      problem and propose several workarounds.
//
//----------------------------------------------------------------------------------
uint8 halRfReadStatusReg(uint8 addr)
{
    uint8 reg;
    halSpiRead(addr | CC1100_READ_SINGLE, &reg, 1);
    return(reg);
}
//----------------------------------------------------------------------------------
//  uint8 halRfGetChipId(void)
//----------------------------------------------------------------------------------
uint8 halRfGetChipId(void)
{
    return(halRfReadStatusReg(CC1100_PARTNUM));
}

//----------------------------------------------------------------------------------
//  uint8 halRfGetChipVer(void)
//----------------------------------------------------------------------------------
uint8 halRfGetChipVer(void)
{
    return(halRfReadStatusReg(CC1100_VERSION));
}

⌨️ 快捷键说明

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