//BIT0 should be SS, but in point of fact it is IRQ.
//BIT4 is actually SS, BIT5 is CE.
#define SS BIT4
+#define CE BIT5;
-//This could be more accurate.
-//Does it ever need to be?
-#define NRFSPEED 0
-#define NRFDELAY(x)
-//delay(x)
+#define RADIOACTIVE P5OUT|=CE
+#define RADIOPASSIVE P5OUT&=~CE
//! Set up the pins for NRF mode.
void nrfsetup(){
P5OUT|=SS;
P5DIR&=~MISO;
- P5DIR|=MOSI+SCK+SS;
+ P5DIR|=MOSI+SCK+SS+CE;
//Begin a new transaction.
nrftrans8(*buf++);
P5OUT|=SS;
+ return reg;//status
}
//! Reads a register
u8 nrf_regread(u8 reg, u8 *buf, int len){
*buf++=nrftrans8(0);
P5OUT|=SS;
+ return reg;//status
}
//! Handles a Nordic RF command.
unsigned long len){
unsigned long i;
+ RADIOPASSIVE;
+
//Raise !SS to end transaction, just in case we forgot.
P5OUT|=SS;
nrfsetup();
P5OUT|=SS; //Raise !SS to end transaction.
txdata(app,verb,len);
break;
-
case SETUP:
nrfsetup();
txdata(app,verb,0);
break;
+ case NRF_RX:
+ RADIOPASSIVE;
+
+ //Get the packet.
+ P5OUT&=~SS;
+ nrftrans8(NRF_R_RX_PAYLOAD);
+ for(i=0;i<32;i++)
+ cmddata[i]=nrftrans8(0xde);
+ P5OUT|=SS;
+ //no break
+ txdata(app,verb,32);
+ break;
+ case NRF_RX_FLUSH:
+ //Flush the buffer.
+ P5OUT&=~SS;
+ nrftrans8(NRF_FLUSH_RX);
+ P5OUT|=SS;
+
+ //Return the packet.
+ txdata(app,verb,32);
+ break;
+ case NRF_TX:
+ default:
+ debugstr("Not yet supported.");
+ txdata(app,verb,0);
+ break;
}
+ P5OUT|=SS;//End session
+ RADIOACTIVE;
}
\brief Constants for NRF Driver
*/
-//Nordic RF Instructions
+//Nording RF Commands
+
+//Grab a packet, if one is available.
+#define NRF_RX 0x80
+//Send a packet.
+#define NRF_TX 0x81
+//Flsuh RX
+#define NRF_RX_FLUSH 0x82
+
+//Nordic RF SPI Instructions
#define NRF_R_REGISTER 0x00
#define NRF_W_REGISTER 0x20
-#define NRF_R_RX_PAYLOAD 0x60
+#define NRF_R_RX_PAYLOAD 0x61
#define NRF_W_TX_PAYLOAD 0xA0
-#define NRF_FLUSH_TX 0xE0
-#define NRF_FLUSH_RX 0xE1
-#define NRF_REUSE_TX_PL 0xE2
+#define NRF_FLUSH_TX 0xE1
+#define NRF_FLUSH_RX 0xE2
+#define NRF_REUSE_TX_PL 0xE3
#define NRF_NOP 0xFF
-
//NRF24L01+ Registers
//These aren't yet used, but are included for later
//translation to XML.