//Fetch the next act payload //Return the payload length char NRF24L01_RxPacket(char *payload) { int len; int i; //Get the packet length RADIO_EN_CS(); SPI_SendByte(CMD_RX_PL_WID); len = SPI_ReceiveByte(); RADIO_DIS_CS(); if (len>0 && len<33) { //Read the packet from the RX buffer RADIO_EN_CS(); SPI_SendByte(CMD_R_RX_PAYLOAD); for(i=0;i<len;i++) payload[i] = SPI_ReceiveByte(); RADIO_DIS_CS(); } else { len=0; } //Pulse CE //CE_PULSE(); return len; }
//Fetch the next act payload //Return the payload length char radioRxPacket(__xdata char *payload) { int len; int i; //Get the packet length RADIO_EN_CS(); spiRadioSend(CMD_RX_PL_WID); len = spiRadioReceive(); RADIO_DIS_CS(); if (len>0 && len<33) { //Read the packet from the RX buffer RADIO_EN_CS(); spiRadioSend(CMD_R_RX_PAYLOAD); for(i=0;i<len;i++) payload[i] = spiRadioReceive(); RADIO_DIS_CS(); } else { len=0; } //Pulse CE //CE_PULSE(); return len; }
//Set the TX and RX address void radioSetAddress(__xdata char* address) { int i; RADIO_EN_CS(); spiRadioSend(CMD_W_REG | REG_TX_ADDR); for(i=0; i<5; i++) spiRadioSend(address[i]); RADIO_DIS_CS(); RADIO_EN_CS(); spiRadioSend(CMD_W_REG | REG_RX_ADDR_P0); for(i=0; i<5; i++) spiRadioSend(address[i]); RADIO_DIS_CS(); }
//Set the TX and RX address void NRF24L01_SetAddress(char* address) { int i; RADIO_EN_CS(); SPI_SendByte(CMD_W_REG | REG_TX_ADDR); for(i=0; i<5; i++) SPI_SendByte(address[i]); RADIO_DIS_CS(); RADIO_EN_CS(); SPI_SendByte(CMD_W_REG | REG_RX_ADDR_P0); for(i=0; i<5; i++) SPI_SendByte(address[i]); RADIO_DIS_CS(); }
//Nop command, permit to get the status byte char NRF24L01_Nop() { char status; RADIO_EN_CS(); status = SPI_SendByte(CMD_NOP); RADIO_DIS_CS(); return status; }
//Nop command, permit to get the status byte char radioNop() { char status; RADIO_EN_CS(); status = spiRadioSend(CMD_NOP); RADIO_DIS_CS(); return status; }
char NRF24L01_FlushRx() { char status; RADIO_EN_CS(); status = SPI_SendByte(CMD_FLUSH_RX); RADIO_DIS_CS(); return status; }
char radioFlushRx() { char status; RADIO_EN_CS(); status = spiRadioSend(CMD_FLUSH_RX); RADIO_DIS_CS(); return status; }
unsigned char nrfFlushTx() { unsigned char status; RADIO_EN_CS(); status = spiSendByte(CMD_FLUSH_TX); RADIO_DIS_CS(); return status; }
/* Sent the NOP command. Used to get the status byte */ unsigned char nrfNop() { unsigned char status; RADIO_EN_CS(); status = spiSendByte(CMD_NOP); RADIO_DIS_CS(); return status; }
// Return the payload length unsigned char nrfRxLength(unsigned int pipe) { unsigned char length; RADIO_EN_CS(); spiSendByte(CMD_RX_PL_WID); length = spiReceiveByte(); RADIO_DIS_CS(); return length; }
char radioReadReg(char addr) { char value; RADIO_EN_CS(); spiRadioSend(CMD_R_REG | (addr&0x1F)); value = spiRadioSend(0xA5); RADIO_DIS_CS(); return value; }
char radioWriteReg(char addr, char value) { char status; RADIO_EN_CS(); status = spiRadioSend(CMD_W_REG | (addr&0x1F)); spiRadioSend(value); RADIO_DIS_CS(); return value; }
char NRF24L01_WriteReg(char addr, char value) { char status; RADIO_EN_CS(); status = SPI_SendByte(CMD_W_REG | (addr&0x1F)); SPI_SendByte(value); RADIO_DIS_CS(); return value; }
char NRF24L01_ReadReg(char addr) { char value; RADIO_EN_CS(); SPI_SendByte(CMD_R_REG | (addr&0x1F)); value = SPI_ReceiveByte(); RADIO_DIS_CS(); return value; }
unsigned char nrfActivate() { unsigned char status; RADIO_EN_CS(); status = spiSendByte(CMD_ACTIVATE); spiSendByte(ACTIVATE_DATA); RADIO_DIS_CS(); return status; }
//Send a packet as acknowledgment payload void radioAckPacket(char pipe, __xdata char* payload, char len) { int i; RADIO_EN_CS(); /* Send the read command with the address */ spiRadioSend(CMD_W_ACK_PAYLOAD(pipe)); /* Read LEN bytes */ for(i=0; i<len; i++) spiRadioSend(payload[i]); RADIO_DIS_CS(); }
//Send a packed in no-ack mode void NRF24L01_TxPacketNoAck(char *payload, char len) { int i; //Send the packet in the TX buffer RADIO_EN_CS(); SPI_SendByte(CMD_W_PAYLOAD_NO_ACK); for(i=0;i<len;i++) SPI_SendByte(payload[i]); RADIO_DIS_CS(); //Pulse CE CE_PULSE(); return; }
//Send a packed in no-ack mode void radioTxPacketNoAck(__xdata char *payload, char len) { int i; //Send the packet in the TX buffer RADIO_EN_CS(); spiRadioSend(CMD_W_TX_PAYLOAD_NO_ACK); for(i=0;i<len;i++) spiRadioSend(payload[i]); RADIO_DIS_CS(); //Pulse CE CE_PULSE(); return; }
// Read the RX payload unsigned char nrfReadRX(char *buffer, int len) { unsigned char status; int i; RADIO_EN_CS(); /* Send the read command with the address */ status = spiSendByte(CMD_R_RX_PAYLOAD); /* Read LEN bytes */ for(i=0; i<len; i++) buffer[i]=spiReceiveByte(); RADIO_DIS_CS(); return status; }
/* Write len bytes a nRF24L register. 5 Bytes max */ unsigned char nrfWriteReg(unsigned char address, char *buffer, int len) { unsigned char status; int i; RADIO_EN_CS(); /* Send the write command with the address */ status = spiSendByte( CMD_W_REG | (address&0x1F) ); /* Write LEN bytes */ for(i=0; i<len; i++) spiSendByte(buffer[i]); RADIO_DIS_CS(); return status; }
// Write the ack payload of the pipe 0 unsigned char nrfWriteAck(unsigned int pipe, char *buffer, int len) { unsigned char status; int i; ASSERT(pipe<6); RADIO_EN_CS(); /* Send the read command with the address */ status = spiSendByte(CMD_W_ACK_PAYLOAD(pipe)); /* Read LEN bytes */ for(i=0; i<len; i++) spiSendByte(buffer[i]); RADIO_DIS_CS(); return status; }