2 \author Jean-Michel Picod
3 \brief Chipcon SPI CC2500
5 Unfortunately, there is very little similarity between the CC2420
6 and the CC2500, to name just two of the myriad of Chipcon SPI
7 radios. Auto-detection will be a bit difficult, but more to the
8 point, all high level functionality must be moved into the client.
11 //Higher level left to client application.
15 #include <stdlib.h> //added for itoa
20 #define CC2500_MEM_READ 0x80
21 #define CC2500_MEM_BURST 0x40
22 #define CC2500_MEM_WRITE 0x00
24 #define RADIO_TX SETCE
25 #define RADIO_RX CLRCE
27 //! Handles a Chipcon SPI command.
28 void cc2500_handle_fn( uint8_t const app,
32 // define the ccspi app's app_t
33 app_t const cc2500_app = {
45 "\tThe CC2500 app adds support for the Chipcon SPI register\n"
46 "\tinterface for the CC2500 (and similar) chip.\n"
49 //! Set up the pins for CCSPI mode.
61 //Begin a new transaction.
66 //! Read and write an CCSPI byte.
67 u8 cc2500trans8(u8 byte){
68 register unsigned int bit;
69 //This function came from the CCSPI Wikipedia article.
72 for (bit = 0; bit < 8; bit++) {
73 /* write MOSI on trailing edge of previous clock */
82 /* read MISO on trailing edge */
92 u8 cc2500_regwrite(u8 reg, const u8 *buf, int len){
96 reg |= CC2500_MEM_BURST;
97 reg=cc2500trans8(reg|CC2500_MEM_READ);
105 u8 cc2500_regread(u8 reg, u8 *buf, int len){
109 reg|=CC2500_MEM_BURST;
110 reg=cc2500trans8(reg|CC2500_MEM_WRITE);
112 *buf++=cc2500trans8(0);
118 //! Handles a Chipcon SPI command.
119 void cc2500_handle_fn( uint8_t const app,
122 unsigned long i, nbyte;
130 cmddata[0]|=CC2500_MEM_READ; //Set the read bit.
135 cmddata[0] |= CC2500_MEM_BURST;
136 CLRSS; //Drop !SS to begin transaction.
138 cmddata[i]=cc2500trans8(cmddata[i]);
139 SETSS; //Raise !SS to end transaction.
140 txdata(app,verb,len);
147 case CC2500_REPEAT_RX:
149 cc2500_handle_fn(app, CC2500_RX, 0);
154 debugstr("RX is not functionning right now");
155 txdata(app, verb, 0);
159 RADIO_TX; // Set option power amplificator to TX
160 // FIXME: Flush FIFO first ?
163 cc2500trans8(CC2500_TXFIFO | CC2500_MEM_BURST); // TX FIFO Burst
164 for (i = 0; i < len; i++)
165 cc2500trans8(cmddata[i]);
166 SETSS; // Exit burst mode
168 cc2500trans8(CC2500_STX); // Go to TX mode
170 txdata(app, verb, 0);
173 case CC2500_RX_FLUSH:
176 cc2500trans8(CC2500_SIDLE);
177 cc2500trans8(CC2500_SFLUSHRX);
182 case CC2500_TX_FLUSH:
185 cc2500trans8(CC2500_SIDLE);
186 cc2500trans8(CC2500_SFLUSHTX);
192 debugstr("Not yet supported in CC2500");