
VMA322
V. 02 – 08/05/2019
7
©Velleman nv
return(status); // return nRF24L01 status unsigned char
}
/**************************************************/
/**************************************************
* Function: TX_Mode();
*
* Description:
* This function initializes one nRF24L01 device to
* TX mode, set TX address, set RX address for auto.ack,
* fill TX payload, select RF channel, datarate & TX pwr.
* PWR_UP is set, CRC(2 unsigned chars) is enabled, & PRIM:TX.
*
* ToDo: One high pulse(>10us) on CE will now send this
* packet and expext an acknowledgment from the RX device.
**************************************************/
void TX_Mode(void)
{
SPI_PORT&=~CE;
SPI_Write_Buf(WRI TX_ADDR, TX_ADDRESS, TX_ADR_WIDTH); // Writes TX_Address to
nRF24L01
SPI_Write_Buf(WRI RX_ADDR_P0, TX_ADDRESS, TX_ADR_WIDTH); // RX_Addr0 same as
TX_Adr for Auto.Ack
SPI_RW_Reg(WRI EN_AA, 0x01); // Enable Auto.Ack:Pipe0
SPI_RW_Reg(WRI EN_RXADDR, 0x01); // Enable Pipe0
SPI_RW_Reg(WRI SETUP_RETR, 0x1a); // 500us + 86us, 10 retrans...
SPI_RW_Reg(WRI RF_CH, 40); // Select RF channel 40
SPI_RW_Reg(WRI RF_SETUP, 0x07); // TX_PWR:0dBm, Datarate:2Mbps, LNA:HCURR
SPI_RW_Reg(WRI CONFIG, 0x0e); // Set PWR_UP bit, enable CRC(2 unsigned chars) &
Prim:TX. MAX_RT & TX_DS enabled..
SPI_Write_Buf(WR_TX_PLOAD,tx_buf,TX_PLOAD_WIDTH);
SPI_PORT|=CE;
}
// Code End
Download the code below into the RX Arduino
®
(receive). This code will drive the nFR24L01 module to receive
the data that transmit form the TX module and print it to the serial port.
// Code Begin
#include "NRF24L01.h"
//***************************************************
#define TX_ADR_WIDTH 5 // 5 unsigned chars TX(RX) address width
#define TX_PLOAD_WIDTH 32 // 32 unsigned chars TX payload
unsigned char TX_ADDRESS[TX_ADR_WIDTH] =
{
0x34,0x43,0x10,0x10,0x01
}; // Define a static TX address