📄 rf_fun.c
字号:
#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, ®, 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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -