2 \author Travis Goodspeed
3 \brief NordicRF Register Interface
6 //Higher level left to client application.
18 //Weird HOPE badge wiring. This was a fuckup.
19 //BIT0 should be SS, but in point of fact it is IRQ.
20 //BIT4 is actually SS, BIT5 is CE.
24 #define RADIOACTIVE P5OUT|=CE
25 #define RADIOPASSIVE P5OUT&=~CE
28 //! Set up the pins for NRF mode.
32 P5DIR|=MOSI+SCK+SS+CE;
35 //Begin a new transaction.
40 //! Read and write an NRF byte.
41 u8 nrftrans8(u8 byte){
42 register unsigned int bit;
43 //This function came from the NRF Wikipedia article.
46 for (bit = 0; bit < 8; bit++) {
47 /* write MOSI on trailing edge of previous clock */
56 /* read MISO on trailing edge */
66 u8 nrf_regwrite(u8 reg, const u8 *buf, int len){
77 u8 nrf_regread(u8 reg, u8 *buf, int len){
88 //! Handles a Nordic RF command.
89 void nrfhandle(unsigned char app,
96 //Raise !SS to end transaction, just in case we forgot.
101 //PEEK and POKE might come later.
104 P5OUT&=~SS; //Drop !SS to begin transaction.
106 cmddata[i]=nrftrans8(cmddata[i]);
107 P5OUT|=SS; //Raise !SS to end transaction.
108 txdata(app,verb,len);
111 case PEEK://Grab NRF Register
112 P5OUT&=~SS; //Drop !SS to begin transaction.
113 nrftrans8(NRF_R_REGISTER | cmddata[0]); //000A AAAA
115 cmddata[i]=nrftrans8(cmddata[i]);
116 P5OUT|=SS; //Raise !SS to end transaction.
117 txdata(app,verb,len);
120 case POKE://Poke NRF Register
121 P5OUT&=~SS; //Drop !SS to begin transaction.
122 nrftrans8(NRF_W_REGISTER | cmddata[0]); //001A AAAA
124 cmddata[i]=nrftrans8(cmddata[i]);
125 P5OUT|=SS; //Raise !SS to end transaction.
126 txdata(app,verb,len);
137 nrftrans8(NRF_R_RX_PAYLOAD);
139 cmddata[i]=nrftrans8(0xde);
147 nrftrans8(NRF_FLUSH_RX);
156 debugstr("Not yet supported.");
161 P5OUT|=SS;//End session