?? cc1020.c
字號:
#include "modemhw.h"
/****************************************************************************/
/* This routine sends new configuration data to the CC1020 */
/****************************************************************************/
void ConfigureCC1020(char Count, short Configuration[])
{
short val;
char i;
for (i=0;i<Count;i++) {
val=Configuration[i];
WriteToCC1020RegisterWord(val);
}
}
/****************************************************************************/
/* SPI versions of configuration routines. The SPI interface must be */
/* initialised correctly before use */
/****************************************************************************/
#ifdef SPI
/****************************************************************************/
/* This routine sets up the CC1020 for SPI transfer */
/****************************************************************************/
void SetupCC1020ForSPI(void)
{
TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN;
TI_CC_CSn_PxDIR |= TI_CC_CSn_PIN; // /CS disable
ME2 |= USPIE1; // Enable USART1 SPI mode
UCTL1 |= CHAR + SYNC + MM; // 8-bit SPI Master **SWRST**
/* Data is output with the falling edge ok!!*/
UTCTL1 |= CKPH + SSEL1 + SSEL0 + STC; // SMCLK, 3-pin mode
UBR01 = 0x02; // UCLK/2
UBR11 = 0x00; // 0
UMCTL1 = 0x00; // No modulation
TI_CC_SPI_USART1_PxSEL |= TI_CC_SPI_USART1_SIMO | TI_CC_SPI_USART1_SOMI | TI_CC_SPI_USART1_UCLK;
// SPI option select
TI_CC_SPI_USART1_PxDIR |= TI_CC_SPI_USART1_SIMO + TI_CC_SPI_USART1_UCLK;
// SPI TXD out direction
UCTL1 &= ~SWRST; // Initialize USART state machine
}
/****************************************************************************/
/* This routine writes to a single CC1020 register */
/****************************************************************************/
void WriteToCC1020Register(char addr, char data)
{
char first_byte, second_byte;
second_byte=data;
TI_CC_CSn_PxOUT &= ~TI_CC_CSn_PIN; // /CS enable
IFG2 &= ~URXIFG1; // Clear flag
first_byte=(addr<<1)|0x01;
U1TXBUF = first_byte; // Send address
while (!(IFG2&URXIFG1)); // Wait for TX to finish
IFG2 &= ~URXIFG1; // Clear flag
U1TXBUF = data; // Load data for TX after addr
while (!(IFG2&URXIFG1)); // Wait for end of addr TX
TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN; // /CS disable
}
/****************************************************************************/
/* This routine writes to a single CC1020 register, with data and address */
/* given in the same variable */
/****************************************************************************/
void WriteToCC1020RegisterWord(short addranddata)
{
union {
unsigned short data;
struct {
char LowByte;
char HighByte;
};
};
data=addranddata;
TI_CC_CSn_PxOUT &= ~TI_CC_CSn_PIN; // /CS enable
IFG2 &= ~URXIFG1; // Clear flag
U1TXBUF = LowByte|0x01; // Send address
while (!(IFG2&URXIFG1)); // Wait for TX to finish
IFG2 &= ~URXIFG1; // Clear flag
U1TXBUF = HighByte; // Load data for TX after addr
while (!(IFG2&URXIFG1)); // Wait for end of addr TX
TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN; // /CS disable
}
/****************************************************************************/
/* This routine reads from a single CC1020 register */
/****************************************************************************/
char ReadFromCC1020Register(char addr)
{
char Value;
TI_CC_CSn_PxOUT &= ~TI_CC_CSn_PIN; // /CS enable
IFG2 &= ~URXIFG1; // Clear flag set during addr TX
U1TXBUF = (addr<<1)&0xFE; // Send address
while (!(IFG2&URXIFG1)); // Wait for TXBUF ready
IFG2 &= ~URXIFG1; // Clear flag set during addr TX
U1TXBUF = 0; // Load dummy byte for TX after addr
while (!(IFG2&URXIFG1)); // Wait for end of dummy byte TX
Value = U1RXBUF; // Read data
TI_CC_CSn_PxOUT |= TI_CC_CSn_PIN; // /CS disable
return Value;
}
#else
/* Bit banging PIC interface...have fun to port them on the MSP430 ;-)
maybe in the future....*/
/****************************************************************************/
/* General I/O pin "bit-bashing" versions of configuration routines. */
/****************************************************************************/
/****************************************************************************/
/* This routine writes to a single CC1020 register */
/****************************************************************************/
/*
void WriteToCC1020Register(char addr, char data)
{
short val;
val=(short) (addr&0x7F)<<9 | (short) data &0x00FF;
WriteToCC1020RegisterWord(val);
}
*/
/****************************************************************************/
/* This routine writes to a single CC1020 register, with address and data */
/* given in the same variable */
/****************************************************************************/
/*
void WriteToCC1020RegisterWord(short addranddata)
{
char BitCounter;
char Low;
char High;
union {
unsigned short data;
struct
{
char LowByte;
char HighByte;
};
};
PSEL=1;
data=addranddata;
PSEL=0;
Low=LowByte;
// Send address bits
for (BitCounter=0;BitCounter<7;BitCounter++)
{
PCLK=0;
PDI=((Low&0x80)>>7);
Low=Low<<1;
PCLK=1;
}
// Send read/write bit
// Ignore bit in data, always use 1
PCLK=0;
PDI=1;
PCLK=1;
PCLK=0;
High=HighByte;
// Send data bits
for (BitCounter=0;BitCounter<8;BitCounter++)
{
PCLK=0;
PDI=((High&0x80)>>7);
High=High<<1;
PCLK=1;
}
PCLK=0;
PSEL=1;
}
*/
/****************************************************************************/
/* This routine reads from a single CC1020 register */
/****************************************************************************/
/*
char ReadFromCC1020Register(char addr)
{
char BitCounter;
char Byte;
PSEL=1;
Byte=addr<<1;
PSEL=0;
// Send address bits
for (BitCounter=0;BitCounter<7;BitCounter++)
{
PCLK=0;
PDI=((Byte&0x80)>>7);
Byte=Byte<<1;
PCLK=1;
}
// Send read/write bit
// Ignore bit in data, always use 0
PCLK=0;
PDI=0;
PCLK=1;
PCLK=0;
// Receive data bits
PDI=1;
TRISC|=0x20; // Set up PDATA as an input
for (BitCounter=0;BitCounter<8;BitCounter++)
{
PCLK=1;
Byte=Byte<<1;
Byte=Byte|PDO;
PCLK=0;
}
TRISC&=~0x20; // Set up PDATA as an output again
PSEL=1;
return Byte;
}
*/
#endif
/****************************************************************************/
/* This routine resets the CC1020, clearing all registers. */
/****************************************************************************/
void ResetCC1020(void)
{
// Reset CC1020
WriteToCC1020Register(CC1020_MAIN, 0x0F&~0x01);
// Bring CC1020 out of reset
WriteToCC1020Register(CC1020_MAIN, 0x1F);
}
/****************************************************************************/
/* This routine calibrates the CC1020 */
/* Returns 0 if calibration fails, non-zero otherwise. Checks the LOCK */
/* to check for success. */
/****************************************************************************/
char CalibrateCC1020(char PA_POWER)
{
volatile int TimeOutCounter;
volatile int nCalAttempt;
// Turn off PA to avoid spurs during calibration in TX mode
WriteToCC1020Register(CC1020_PA_POWER,0x00);
// Calibrate, and re-calibrate if necessary:
for (nCalAttempt = CAL_ATTEMPT_MAX; (nCalAttempt>0); nCalAttempt--) {
// Start calibration
WriteToCC1020Register(CC1020_CALIBRATE,0xB4);
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -