/* * 函数名:NRF_Rx_Dat * 描述 :用于从NRF的接收缓冲区中读出数据 * 输入 :rxBuf:用于接收该数据的数组,外部定义 * 输出 :接收结果, * 调用 :外部调用 */ u8 NRF_Rx_Dat(u8 *rxbuf) { u8 state; if( nrf_mode != RX_MODE) { NRF_RX_Mode(); } NRF_CE_HIGH(); //进入接收状态 /*等待接收中断*/ while(NRF_Read_IRQ()!=0); NRF_CE_LOW(); //进入待机状态 /*读取status寄存器的值 */ state=NRF_ReadReg(STATUS); /* 清除中断标志*/ NRF_WriteReg(NRF_WRITE_REG+STATUS,state); /*判断是否接收到数据*/ if(state & RX_DR) //接收到数据 { NRF_ReadBuf(RD_RX_PLOAD,rxbuf,RX_PLOAD_WIDTH);//读取数据 NRF_WriteReg(FLUSH_RX,NOP); //清除RX FIFO寄存器 return RX_DR; } else { return ERROR; //没收到任何数据 } }
/* * 函数名:NRF_RX_Mode * 描述 :配置并进入接收模式 * 输入 :无 * 输出 :无 * 调用 :外部调用 */ void NRF_RX_Mode(void) { NRF_CE_LOW(); NRF_WriteReg(NRF_WRITE_REG+EN_AA,0x01); //使能通道0的自动应答 NRF_WriteReg(NRF_WRITE_REG+EN_RXADDR,0x01); //使能通道0的接收地址 NRF_WriteBuf(NRF_WRITE_REG+RX_ADDR_P0,RX_ADDRESS,RX_ADR_WIDTH);//写RX节点地址 NRF_WriteReg(NRF_WRITE_REG+CONFIG, 0x0B | (IS_CRC16<<2)); //配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式 #if 1 /* 清除中断标志*/ NRF_WriteReg(NRF_WRITE_REG+STATUS,0xff); NRF_WriteReg(FLUSH_RX,NOP); //清除RX FIFO寄存器 #endif /*CE拉高,进入接收模式*/ NRF_CE_HIGH(); nrf_mode = RX_MODE; }
/** * @brief Handle interrupt event * @note Call this function, judge whether a payload is received and processes received payload in EXTIx_IRQHandler() * @param Pointer to nRF24L01P_Object * @retval STATUS register in nRF24L01P. */ uint8_t NRF_IRQ_Handler(nRF24L01P_Object* nrf) { uint8_t status; NRF_CS_LOW(nrf); status = NRF_SPI_SendByte(nrf, NRF_NOP); NRF_CS_HIGH(nrf); if(EXTI_GetITStatus(nrf->EXTI_LINE) != RESET) { nrf->ReceivedPayload.Datapipe = NRF_STATUS_RX_P_NO(status); if(status & NRF_STATUS_RX_DR) { NRF_GetPayload(nrf); NRF_WriteReg(nrf, NRF_STATUS, NRF_STATUS_RX_DR); } if(status & NRF_STATUS_TX_DS) { NRF_WriteReg(nrf, NRF_STATUS, NRF_STATUS_TX_DS); } if(status & NRF_STATUS_MAX_RT) { NRF_Flush_TX(nrf); NRF_WriteReg(nrf, NRF_STATUS, NRF_STATUS_MAX_RT); } EXTI_ClearITPendingBit(nrf->EXTI_LINE); } return status; }
//由中断服务函数调用 void NRF_ISR_Tx_Handler(void) { if(isr_addr == NULL) { return; //无效 } //检测发送结果 isr_state = NRF_ReadReg(STATUS); /*读取状态寄存器的值 */ NRF_WriteReg(NRF_WRITE_REG+STATUS,isr_state); /*清除TX_DS或MAX_RT中断标志*/ NRF_WriteReg(FLUSH_TX,NOP); //清除TX FIFO寄存器 if( (!(isr_state & TX_DS) ) || (isr_L==0) ) //如果发送不成功,或者已经发送完成,则结束 { isr_addr = NULL; //通过判断 isr_addr 就知道是否发送完毕。 isr_L = 0; //isr_L就不一定了 return; //通过 isr_state 判断状态 } //还没发送完成,就继续发送 isr_addr += MAX_ONCE_TX_NUM; //指向下一个地址 NRF_ISR_Tx_Dat_Once(); }
/** * @brief Set RX address * @note Automatically decide number of bytes to send. * @param Pointer to nRF24L01P_Object * @param Datapipe, 0 ~ 5 integer * @param Address buffer pointer. * @retval STATUS register in nRF24L01P. */ uint8_t NRF_SetRXAddr(nRF24L01P_Object* nrf, uint8_t Datapipe, uint8_t* Addr) { assert_param((Datapipe >= 0) && (Datapipe <= 5)); switch(Datapipe){ case 0: memcpy(nrf->RX_Address_P0, Addr, nrf->AddressFieldWidth); return NRF_WriteMultiByteReg(nrf, NRF_RX_ADDR_P0, Addr, nrf->AddressFieldWidth); case 1: memcpy(nrf->RX_Address_P1, Addr, nrf->AddressFieldWidth); return NRF_WriteMultiByteReg(nrf, NRF_RX_ADDR_P1, Addr, nrf->AddressFieldWidth); case 2: nrf->RX_Address_P2 = *Addr; return NRF_WriteReg(nrf, NRF_RX_ADDR_P2, *Addr); case 3: nrf->RX_Address_P3 = *Addr; return NRF_WriteReg(nrf, NRF_RX_ADDR_P3, *Addr); case 4: nrf->RX_Address_P4 = *Addr; return NRF_WriteReg(nrf, NRF_RX_ADDR_P4, *Addr); case 5: nrf->RX_Address_P5 = *Addr; return NRF_WriteReg(nrf, NRF_RX_ADDR_P5, *Addr); default: return 0; } }
//传输一次,数据最长为 32字节 static u8 NRF_TX_Dat_Once(u8 *txbuf) { u8 state; /*ce为低,进入待机模式1*/ NRF_CE_LOW(); /*写数据到TX BUF 最大 32个字节*/ NRF_WriteBuf(WR_TX_PLOAD,txbuf,MAX_ONCE_TX_NUM); /*CE为高,txbuf非空,发送数据包 */ NRF_CE_HIGH(); /*等待发送完成中断 */ while(NRF_Read_IRQ()!=0); /*读取状态寄存器的值 */ state = NRF_ReadReg(STATUS); /*清除TX_DS或MAX_RT中断标志*/ NRF_WriteReg(NRF_WRITE_REG+STATUS,state); NRF_WriteReg(FLUSH_TX,NOP); //清除TX FIFO寄存器 /*判断中断类型*/ return state; }
/*=====================================================================================================*/ void NRF24L01_Init( u8 NRF_INIT_MODE ) { NRF_CE = 0; NRF_SetAddr(NRF_TX_ADDR, TX_ADDRESS); // 設定 TX 地址 NRF_SetAddr(NRF_RX_ADDR_P0, RX_ADDRESS); // 設定 RX 地址 NRF_WriteReg(CMD_W_REG | NRF_EN_AA, 0x01); // 致能通道0的自動應答 NRF_WriteReg(CMD_W_REG | NRF_EN_RXADDR, 0x01); // 致能 data Pipe 0 的接收地址 NRF_WriteReg(CMD_W_REG | NRF_SETUP_RETR, 0x1A); // 設定自動重發間隔時間:500us + 86us;最大自動重發次數:10次 NRF_SetChannel(NRF_CHANAL); // 設定傳輸通道(頻率) NRF_SetDataRate(NRF_RATE_2Mbps); // 設定傳輸速率 2Mbps NRF_WriteReg(CMD_W_REG | NRF_RX_PW_P0, NRF_TX_PL_WIDTH); // 設定通道0的有效數據寬度 switch(NRF_INIT_MODE) { case NRF_MODE_TXOL: NRF_WriteReg(CMD_W_REG | NRF_RX_PW_P0, NRF_TX_PL_WIDTH); // 設定通道0的有效數據寬度 NRF_WriteReg(CMD_W_REG | NRF_CONFIG, 0x0E); // Power UP,Enable 16bit CRC,TX Mode,no mask break; case NRF_MODE_RXOL: NRF_WriteReg(CMD_W_REG | NRF_RX_PW_P0, NRF_TX_PL_WIDTH); // 設定通道0的有效數據寬度 NRF_WriteReg(CMD_W_REG | NRF_CONFIG, 0x0F); // Power UP,Enable 16bit CRC,RX Mode,no mask break; case NRF_MODE_FTLR: NRF_WriteReg(CMD_W_REG | NRF_CONFIG, 0x0E); // Power UP,Enable 16bit CRC,TX Mode,no mask NRF_FlushRxFIFO(); NRF_FlushTxFIFO(); // SPI_RW(NRF_SPIx, 0x50); // SPI_RW(NRF_SPIx, 0x73); // NRF_WriteReg(CMD_W_REG | NRF_DYNPD, 0x01); // NRF_WriteReg(CMD_W_REG | NRF_FEATURE, 0x07); break; case NRF_MODE_FRLT: NRF_FlushRxFIFO(); NRF_FlushTxFIFO(); NRF_WriteReg(CMD_W_REG | NRF_CONFIG, 0x0F); // Power UP,Enable 16bit CRC,RX Mode,no mask // SPI_RW(NRF_SPIx, 0x50); // SPI_RW(NRF_SPIx, 0x73); // NRF_WriteReg(CMD_W_REG | NRF_DYNPD, 0x01); // NRF_WriteReg(CMD_W_REG | NRF_FEATURE, 0x07); break; } // NRF_WriteReg(CMD_RX_PL_WID, 0x73); // NRF_WriteReg(CMD_W_REG | NRF_DYNPD, 0x01); // NRF_WriteReg(CMD_W_REG | NRF_FEATURE, 0x07); NRF_CE = 1; while(NRF_Check()!=SUCCESS); }
uint8_t NRF24L01_RxPacket(uint8_t *rxbuf) { uint8_t sta;//spi速度为9Mhz(24L01的最大SPI时钟为10Mhz) sta= NRF_ReadReg(NRFRegSTATUS);//读取状态寄存器的值 NRF_WriteReg(NRF_WRITE_REG+NRFRegSTATUS, sta);//清除TX_DS或MAX_RT中断标志 if (sta & RX_OK) { NRF_ReadBuf(RD_RX_PLOAD, rxbuf, RX_PLOAD_WIDTH);//读取数据 NRF_WriteReg(FLUSH_RX, 0xff);//清除RX FIFO寄存器 return 1; } return 0;//没收到任何数据 }
//由中断服务函数调用 void NRF_ISR_Rx_Handler(void) { u8 state; NRF_CE_LOW(); //进入待机状态 /*读取status寄存器的值 */ state=NRF_ReadReg(STATUS); /* 清除中断标志*/ NRF_WriteReg(NRF_WRITE_REG+STATUS,state); if(re_flag == QUEUE_FULL) //满了就直接清FIFO,退出 { NRF_WriteReg(FLUSH_RX,NOP); //清除RX FIFO寄存器 NRF_CE_HIGH(); //进入接收模式 return; //接收队列满了,不进行处理 } //还没满,则继续接收 /*判断是否接收到数据*/ if(state & RX_DR) //接收到数据 { NRF_ReadBuf(RD_RX_PLOAD,(u8 *)&(RX_ISR_FIFO[rear]),RX_PLOAD_WIDTH); //读取数据 NRF_WriteReg(FLUSH_RX,NOP); //清除RX FIFO寄存器 rear++; if(rear >= RX_ISR_FIFO_PACKET) { rear=0; //重头开始 } if(rear == front) //追到屁股了,满了 { re_flag = QUEUE_FULL; } else { re_flag = QUEUE_NORMAL; } } else { //没收到任何数据 } NRF_CE_HIGH(); //进入接收模式 }
/** * @brief Get payload. * @note * @param Pointer to nRF24L01P_Object. * @retval none. */ void NRF_GetPayload(nRF24L01P_Object* nrf) { uint8_t bytecnt; /* Get payload width for following operations */ NRF_SPI_GetReceivedPayloadInfo(nrf); /* Return if there is nothing in RX FIFO */ if(nrf->ReceivedPayload.PayloadWidth == 0) { return; } /* Flush RX FIFO, clear RX_DR flag and return if there is an error occured */ else if(nrf->ReceivedPayload.PayloadWidth > NRF_MAX_PAYLOAD_WIDTH) { NRF_Flush_RX(nrf); NRF_WriteReg(nrf, NRF_STATUS, NRF_STATUS_RX_DR); return; } /* Read RX FIFO Data */ NRF_ReadPayloadData(nrf, nrf->ReceivedPayload.Payload, nrf->ReceivedPayload.PayloadWidth); /* Fill remaining space with zero */ for(bytecnt = nrf->ReceivedPayload.PayloadWidth; bytecnt < NRF_MAX_PAYLOAD_WIDTH; bytecnt++) { nrf->ReceivedPayload.Payload[bytecnt] = 0x00; } }
/*=====================================================================================================*/ void NRF_RX_Mode( void ) { NRF_CE = 0; NRF_WriteReg(CMD_W_REG | NRF_CONFIG, 0x0F); // Power UP,Enable 16bit CRC,RX Mode,no mask NRF_CE = 1; Delay_10us(13); // After 130μs nRF24L01+ monitors the air for incoming communication. }
/*=====================================================================================================*/ static void NRF_SetDataRate( u8 DataRate ) { switch(DataRate) { case NRF_RATE_250Kbps: NRF_WriteReg(CMD_W_REG | NRF_RF_SETUP, NRF_RATE_250Kbps); break; case NRF_RATE_1Mbps: NRF_WriteReg(CMD_W_REG | NRF_RF_SETUP, NRF_RATE_1Mbps); break; case NRF_RATE_2Mbps: NRF_WriteReg(CMD_W_REG | NRF_RF_SETUP, NRF_RATE_2Mbps); break; } }
/*=====================================================================================================*/ static void NRF_TxData( u8 *TxBuf ) { NRF_CE = 0; NRF_SetAddr(NRF_TX_ADDR, TX_ADDRESS); // 設定 TX 地址 NRF_WriteReg(CMD_W_REG | NRF_CONFIG, 0x0E); // Power UP,Enable 16bit CRC,TX Mode,no mask NRF_WriteBuf(CMD_W_TX_PLOAD, TxBuf, NRF_TX_PL_WIDTH); // 寫入資料 NRF_CE = 1; Delay_10us(1); // A high pulse on CE starts the transmission. The minimum pulse width on CE is 10μs. }
/*=====================================================================================================*/ u8 NRF_RxPacket( u8 *RxBuf ) { u8 Status = ERROR; NRF_CE = 1; while(NRF_IRQ!=0); Status = NRF_ReadReg(CMD_R_REG | NRF_STATUS); if(Status&NRF_STA_RX_DR) { NRF_CE = 0; NRF_RxData(RxBuf); NRF_WriteReg(CMD_W_REG | NRF_STATUS, Status); return NRF_STA_RX_DR; } else { NRF_WriteReg(CMD_W_REG | NRF_STATUS, Status); return ERROR; } }
void NRF_PowerUpRX(void) { uint8_t RegValue; //CE_L(); //can be done by checking every time the real value of register as shown below //RegValue = NRF_ReadReg(NRF_GetRegCommand(CONFIG, READ)); RegValue = CONFIG_DEFAULT | ((1 << PWR_UP) | (1 << PRIM_RX)); NRF_WriteReg(NRF_GetRegCommand(CONFIG, WRITE), RegValue); //CE_H(); }
void NRF_configure_RX() { delay_ms(1); // enter standby mode //CE_L(); // set receiver address, for only two modules present the same address is acceptable NRF_WriteRegData(NRF_GetRegCommand(RX_ADDR_P0, WRITE), TX_ADDRESS, TX_ADR_WIDTH); NRF_WriteRegData(NRF_GetRegCommand(RX_ADDR_P0, WRITE), TX_ADDRESS, TX_ADR_WIDTH); // enable auto ack NRF_WriteReg(NRF_GetRegCommand(EN_AA, WRITE), 0x01); // enable pipe 0 NRF_WriteReg(NRF_GetRegCommand(EN_RXADDR, WRITE), 0x01); // set payload width to 1 byte NRF_WriteReg(NRF_GetRegCommand(RX_PW_P0, WRITE), TX_PLOAD_WIDTH); // select RF channel 2 NRF_WriteReg(NRF_GetRegCommand(RF_CH, WRITE), 2); // set 2Mbps bit rate and 0dBm output power level NRF_WriteReg(NRF_GetRegCommand(RF_SETUP, WRITE), 0x07); NRF_PowerUpRX(); delay_ms(1); }
void SetRxMode(void) { SPI_CE_L; NRF_WriteReg(FLUSH_RX, 0xff);//清除TX FIFO寄存器 NRF_WriteBuf(NRF_WRITE_REG+RX_ADDR_P0, RX_ADDRESS, RX_ADR_WIDTH);//写RX节点地址 NRF_WriteReg(NRF_WRITE_REG+EN_AA, 0x01);//使能通道0的自动应答 NRF_WriteReg(NRF_WRITE_REG+EN_RXADDR, 0x01);//使能通道0的接收地址 NRF_WriteReg(NRF_WRITE_REG+RF_CH, 40);//设置RF通信频率 NRF_WriteReg(NRF_WRITE_REG+RX_PW_P0, RX_PLOAD_WIDTH);//选择通道0的有效数据宽度 NRF_WriteReg(NRF_WRITE_REG+RF_SETUP, 0x0f);//设置TX发射参数,0db增益,2Mbps,低噪声增益开启 NRF_WriteReg(NRF_WRITE_REG+CONFIG, 0x0f);//配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,接收模式 SPI_CE_H; printf("nrf24l01 work on rx..\r\n"); }
/*=====================================================================================================*/ u8 NRF_TxPacket( u8 *TxBuf ) { u8 Status; NRF_TxData(TxBuf); while(NRF_IRQ!=0); Status = NRF_ReadReg(CMD_R_REG | NRF_STATUS); NRF_WriteReg(CMD_W_REG | NRF_STATUS, Status); NRF_FlushTxFIFO(); if(Status&NRF_STA_MAX_RT) return NRF_STA_MAX_RT; else if(Status&NRF_STA_TX_DS) return NRF_STA_TX_DS; else return ERROR; }
/* * 函数名:NRF_Init * 描述 :SPI的 I/O配置 * 输入 :无 * 输出 :无 * 调用 :外部调用 */ void NRF_Init(void) { //配置NRF管脚复用 spi_init(NRF_SPI,MASTER); //初始化SPI,主机模式 gpio_init(PORTE,28, GPO,LOW); //初始化CE,默认进入待机模式 //gpio_init(PORTE,27, GPI,LOW); //初始化IRQ管脚为输入 gpio_init(PORTA,14, GPO,HIGH); //初始化PCSN管脚为输出,低电平选中 #if IS_USE_ISR exti_init(PORTE,27, falling_up); //初始化IRQ管脚为 :下降沿触发,内部上拉 #else gpio_init(PORTE,27, GPI,LOW); //初始化IRQ管脚为输入 #endif //配置NRF寄存器 NRF_CE_LOW(); NRF_WriteReg(NRF_WRITE_REG+SETUP_AW,ADR_WIDTH - 2); //设置地址长度为 TX_ADR_WIDTH NRF_WriteReg(NRF_WRITE_REG+RF_CH,CHANAL); //设置RF通道为CHANAL NRF_WriteReg(NRF_WRITE_REG+RF_SETUP,0x0f); //设置TX发射参数,0db增益,2Mbps,低噪声增益开启 NRF_WriteReg(NRF_WRITE_REG+EN_AA,0x01); //使能通道0的自动应答 NRF_WriteReg(NRF_WRITE_REG+EN_RXADDR,0x01); //使能通道0的接收地址 //RX模式配置 //NRF_WriteBuf(NRF_WRITE_REG+RX_ADDR_P0,RX_ADDRESS,RX_ADR_WIDTH);//写RX节点地址 NRF_WriteReg(NRF_WRITE_REG+RX_PW_P0,RX_PLOAD_WIDTH); //选择通道0的有效数据宽度 //TX模式配置 //NRF_WriteBuf(NRF_WRITE_REG+TX_ADDR,TX_ADDRESS,TX_ADR_WIDTH); //写TX节点地址 ,主要为了使能ACK NRF_WriteReg(NRF_WRITE_REG+SETUP_RETR,0x0F); //设置自动重发间隔时间:250us + 86us;最大自动重发次数:15次 #if IS_AUTO_RX_MODE NRF_RX_Mode(); //默认进入接收模式 #endif NRF_CE_HIGH(); while(NRF_Check() == 0); //检测无线模块是否插入:如果卡在这里,说明没检测到无线模块 }
/** * @brief Enable of disable interrupt masks. * @note * @param Pointer to nRF24L01P_Object * @param Interrupt mask, can be combination of @ref NRF_InterruptMask. * @param NewState. ENABLE of DISABLE * @retval STATUS register in nRF24L01P. */ uint8_t NRF_INT_MASK_Cmd(nRF24L01P_Object* nrf, uint8_t NRF_InterruptMask, FunctionalState NewState) { uint8_t config; //Content of NRF_CONFIG register /* Parameter check */ assert_param(IS_NRF_INT_MASK(NRF_InterruptMask)); /* Read original NRF_CONFIG register */ config = NRF_ReadReg(nrf, NRF_CONFIG); /* Compute the new value */ if(NewState == ENABLE) config = config | NRF_InterruptMask; else config = config & ~NRF_InterruptMask; /* Write new value into NRF_CONFIG register */ return NRF_WriteReg(nrf, NRF_CONFIG, config); }
/* * 函数名:NRF_TX_Mode * 描述 :配置发送模式 * 输入 :无 * 输出 :无 * 调用 :外部调用 */ void NRF_TX_Mode(void) { u32 i; NRF_CE_LOW(); NRF_WriteBuf(NRF_WRITE_REG+TX_ADDR,TX_ADDRESS,TX_ADR_WIDTH); //写TX节点地址 NRF_WriteBuf(NRF_WRITE_REG+RX_ADDR_P0,RX_ADDRESS,RX_ADR_WIDTH); //设置RX节点地址 ,主要为了使能ACK NRF_WriteReg(NRF_WRITE_REG+CONFIG,0x0A | (IS_CRC16<<2)); //配置基本工作模式的参数;PWR_UP,EN_CRC,16BIT_CRC,发射模式,开启所有中断 /*CE拉高,进入发送模式*/ NRF_CE_HIGH(); i=0xffff; while(i--); //CE要拉高一段时间才进入发送模式 //DELAY_MS(1); nrf_mode = TX_MODE; }
/*=====================================================================================================*/ static void NRF_SetChannel( u8 Channel ) { if(Channel<126) NRF_WriteReg(CMD_W_REG | NRF_RF_CH, Channel); }
uint8_t NRF_PowerDown(nRF24L01P_Object* nrf) { uint8_t config; config = NRF_ReadReg(nrf, NRF_CONFIG) & (~NRF_PWR_UP); return NRF_WriteReg(nrf, NRF_CONFIG, config); }
/** * @brief Initialize nRF24L01P registers * @note Pointer to nRF24L01P_Object * @param None * @retval None */ uint8_t NRF_Device_Config(nRF24L01P_Object* nrf) { uint8_t bytecnt; uint8_t bufferA[7]; //for register NRF_CONFIG to NRF_RF_SETUP uint8_t bufferB[2]; //for NRF_DYNPD and NRF_FEATURE /* Parameter check */ assert_param(IS_NRF_INT_MASK(nrf->InterruptMask) && \ IS_NRF_CRC(nrf->IntegratedCRC) && \ IS_NRF_CRC_ENCODING(nrf->CRCEncodingScheme) && \ IS_NRF_MASTER_MODE(nrf->MasterMode) && \ IS_NRF_DATAPIPE(nrf->AutoACKEnabledPipe) && \ IS_NRF_DATAPIPE(nrf->RXAddressEnabledPipe) && \ IS_NRF_AFW(nrf->AddressFieldWidth) && \ IS_NRF_ARD(nrf->AutoRetransmitDelay) && \ IS_NRF_ARC(nrf->AutoRetransmitCount) && \ IS_NRF_RF_CHN(nrf->RFChannel) && \ IS_NRF_CCT(nrf->ContinuousCarrierTransmit) && \ IS_NRF_PLL_LOCK(nrf->PLL_Lock) && \ IS_NRF_RF_DR(nrf->AirDataRate) && \ IS_NRF_RF_PWR(nrf->RF_Power) && \ IS_NRF_DATAPIPE(nrf->DynamicPayloadEnabledPipe) && \ IS_NRF_DPL(nrf->DynamicPayloadLength) && \ IS_NRF_ACK_PAY(nrf->PayloadWithACK) && \ IS_NRF_DYN_ACK(nrf->DynamicACK)); // Ensure desired data range // assert_param(((NRF_InitStructure->NRF_DynamicPayloadEnabledPipe) & \ ~(NRF_InitStructure->NRF_AutoACKEnabledPipe)) || \ (!(NRF_InitStructure->NRF_DynamicPayloadLength) && \ (NRF_InitStructure->NRF_DynamicPayloadEnabledPipe))); // Prevent conflict between configurations: // Can not enable dynamic payload when AutoACK or NRF_DPL is disabled /* Assemble contents to send */ bufferA[0] = nrf->InterruptMask | \ nrf->IntegratedCRC | \ nrf->CRCEncodingScheme | \ NRF_PWR_UP | \ nrf->MasterMode; bufferA[1] = nrf->AutoACKEnabledPipe; bufferA[2] = nrf->RXAddressEnabledPipe; bufferA[3] = nrf->AddressFieldWidth - 2; bufferA[4] = nrf->AutoRetransmitDelay | \ nrf->AutoRetransmitCount; bufferA[5] = nrf->RFChannel; bufferA[6] = nrf->ContinuousCarrierTransmit | \ nrf->PLL_Lock | \ nrf->AirDataRate | \ nrf->RF_Power; bufferB[0] = nrf->DynamicPayloadEnabledPipe; bufferB[1] = nrf->DynamicPayloadLength | \ nrf->PayloadWithACK | \ nrf->DynamicACK; NRF_CE_LOW(nrf); /* Send register contents through SPI */ for(bytecnt = 0; bytecnt < 7; bytecnt++) { NRF_WriteReg(nrf, NRF_CONFIG + bytecnt, *(bufferA + bytecnt)); } NRF_WriteMultiByteReg(nrf, NRF_RX_ADDR_P0, nrf->RX_Address_P0, nrf->AddressFieldWidth); NRF_WriteMultiByteReg(nrf, NRF_RX_ADDR_P1, nrf->RX_Address_P1, nrf->AddressFieldWidth); NRF_WriteMultiByteReg(nrf, NRF_TX_ADDR, nrf->TX_Address, nrf->AddressFieldWidth); NRF_WriteReg(nrf, NRF_RX_ADDR_P2, nrf->RX_Address_P2); NRF_WriteReg(nrf, NRF_RX_ADDR_P3, nrf->RX_Address_P3); NRF_WriteReg(nrf, NRF_RX_ADDR_P4, nrf->RX_Address_P4); NRF_WriteReg(nrf, NRF_RX_ADDR_P5, nrf->RX_Address_P5); NRF_WriteReg(nrf, NRF_DYNPD, *bufferB); return NRF_WriteReg(nrf, NRF_FEATURE, *(bufferB + 1)); }