BSP430  20141115
Board Support Package for MSP430 microcontrollers
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Modules Pages
rf/cc110x/main.c
#include <bsp430/clock.h>
#include <bsp430/serial.h>
static uint8_t
sendStrobe (uint8_t reg)
{
uint8_t rc = 0;
(void)iBSP430spiTxRx_rh(spi, &reg, 1, 0, &rc);
return rc;
}
static uint8_t
readRegister (uint8_t reg)
{
uint8_t rxbuf[2];
/* If this is a status register add the BURST bit */
if (0x30 <= reg) {
reg |= 0x40;
}
/* Add the READ bit */
reg |= 0x80;
(void)iBSP430spiTxRx_rh(spi, &reg, 1, 1, rxbuf);
return rxbuf[1];
}
static int
writeRegister (uint8_t reg,
uint8_t val)
{
uint8_t txbuf[2];
uint8_t rxbuf[2];
txbuf[0] = reg;
txbuf[1] = val;
(void)iBSP430spiTxRx_rh(spi, txbuf, 2, 0, rxbuf);
return rxbuf[1];
}
void main ()
{
int rc = 0;
/* GDO0 and GDO2 are always interrupt-capable. */
cprintf("\nccid " __DATE__ " " __TIME__ "\n");
#if BSP430_PLATFORM_PERIPHERAL_HELP
#endif /* BSP430_PLATFORM_PERIPHERAL_HELP */
cprintf(__DATE__ " " __TIME__ "\n");
/* Configure the SPI interface, but immediately put it into hold
* mode so we can check CHIP_RDYn on the MISO/GDO1 input. */
if (spi) {
/* GDO1 to input, pull-up */
}
cprintf("SPI device %p hold returned %d\n", spi, rc);
if (! spi) {
return;
}
/* Configure CSn initial high to ensure we have a falling edge when
* we first enable the radio. */
/* Now enable the radio */
/* Spin until GDO1 (CHP_RDYn) is clear indicating radio is responsive */
cprintf("Waiting for radio ready\n");
}
/* Enable SPI */
cprintf("Radio is up, hold release %d; sending SRES strobe\n", rc);
/* Send a reset */
do {
rc = sendStrobe(0x30);
cprintf("Strobe response %#02x\n", rc);
if (0x0F != rc) {
}
} while (0x0F != rc);
cprintf("PARTNUM response %#02x\n", readRegister(0x30));
cprintf("VERSION response %#02x\n", readRegister(0x31));
cprintf("IOCFG2 read %#02x\n", readRegister(0x00));
cprintf("IOCFG1 read %#02x\n", readRegister(0x01));
cprintf("IOCFG0 read %#02x\n", readRegister(0x02));
/* ChipCon radios consume 1.4mA when idle. That goes down to
* nominally 400 nA if the GDOs are configured to "HW to 0" and the
* chip is told to power-down on loss of CSn. On the EXP430F5438
* the RF PWR header indicates that a CC1101 is using 40 nA in this
* mode.*/
rc = writeRegister(0x00, 0x2f);
rc = writeRegister(0x01, 0x2f);
rc = writeRegister(0x02, 0x2f);
cprintf("Cleared IOCFG\n");
cprintf("IOCFG2 read %#02x\n", readRegister(0x00));
cprintf("IOCFG1 read %#02x\n", readRegister(0x01));
cprintf("IOCFG0 read %#02x\n", readRegister(0x02));
/* SPWD */
rc = sendStrobe(0x39);
cprintf("SPWD got %d\n", rc);
/* Disable SPI before removing CSn otherwise the sequence isn't
* right. */
/* This gets the RF2500T power down to about 120 nA. Note:
* Purposefully enter LPM with #GIE off since we do not intend to
* wake up.*/
}