/******************************************************************************* * Function Name : EP1_OUT_Callback. * Description : EP1 OUT Callback Routine. * Input : None. * Output : None. * Return : None. *******************************************************************************/ void EP1_OUT_Callback(void) { USB_SIL_Read(EP1_OUT, Receive_Buffer); blink = 1; NRF24L01_Transmit(&Receive_Buffer[1]); while (NRF24L01_GetTransmissionStatus() == NRF24L01_Transmit_Status_Sending) ; SetEPRxStatus(ENDP1, EP_RX_VALID); }
void transmitter(void) { /* My address */ uint8_t MyAddress[] = { 0xE7, 0xE7, 0xE7, 0xE7, 0xE7 }; /* Receiver address */ uint8_t TxAddress[] = { 0x7E, 0x7E, 0x7E, 0x7E, 0x7E }; uint8_t dataOut[32], dataIn[32], i; uint32_t tr_count; NRF24L01_Transmit_Status_t transmissionStatus; /* Initialize NRF24L01+ on channel 15 and 32bytes of payload */ /* By default 2Mbps data rate and 0dBm output power */ /* NRF24L01 goes to RX mode by default */ NRF24L01_Init(15, 32); /* Set RF settings, Data rate to 2Mbps, Output power to -18dBm */ NRF24L01_SetRF(NRF24L01_DataRate_2M, NRF24L01_OutputPower_M18dBm); /* Set my address, 5 bytes */ //NRF24L01_SetMyAddress(MyAddress); /* Set TX address, 5 bytes */ //NRF24L01_SetTxAddress(TxAddress); uint8_t reg; delay_(720000); reg = NRF24L01_ReadRegister(NRF24L01_REG_CONFIG); printf("NRF24L01_REG_CONFIG: 0x%X\r\n", reg); reg = NRF24L01_ReadRegister(NRF24L01_REG_EN_RXADDR); printf("NRF24L01_REG_EN_RXADDR: 0x%X\r\n", reg); reg = NRF24L01_ReadRegister(NRF24L01_REG_RF_CH); printf("NRF24L01_REG_RF_CH: 0x%X\r\n", reg); reg = NRF24L01_ReadRegister(NRF24L01_REG_CONFIG); printf("NRF24L01_REG_CONFIG: 0x%X\r\n", reg); reg = NRF24L01_ReadRegister(NRF24L01_REG_RF_CH); printf("NRF24L01_REG_RF_CH: 0x%X\r\n", reg); reg = NRF24L01_ReadRegister(NRF24L01_REG_CONFIG); printf("NRF24L01_REG_CONFIG: 0x%X\r\n", reg); delay_(720000); for (i = 0; i < 32; i++) { dataOut[i] = i + 30; dataIn[i] = 0; } while (1) { /* Transmit data, goes automatically to TX mode */ NRF24L01_Transmit(dataOut); /* Turn on led to indicate sending */ LED2_ON; /* Wait for data to be sent */ do { transmissionStatus = NRF24L01_GetTransmissionStatus(); printf("transmissionStatus: %d\r\n", transmissionStatus); delay_(72000); } while (transmissionStatus == NRF24L01_Transmit_Status_Sending); /* Turn off led */ LED2_OFF; /* Go back to RX mode */ NRF24L01_PowerUpRx(); i = 0; uint8_t status = NRF24L01_GetStatus(); printf("status: %d\r\n", status); /* Wait received data, wait max 100ms, if time is larger, then data were probably lost */ while (!NRF24L01_DataReady()) { delay_(720000); i++; printf("TM_NRF24L01_DataReady\r\n"); if( i > 100) break; } /* Get data from NRF2L01+ */ NRF24L01_GetData(dataIn); printf("dataIn: %s\r\n", dataIn); /* Check transmit status */ if (transmissionStatus == NRF24L01_Transmit_Status_Ok) { tr_count++; printf("tr_count: %s\r\n", tr_count); } delay_(7200000); } }
void retranslate(void) { /* Receiver address */ uint8_t TxAddress[] = { 0xE7, 0xE7, 0xE7, 0xE7, 0xE7 }; /* My address */ uint8_t MyAddress[] = { 0x7E, 0x7E, 0x7E, 0x7E, 0x7E }; uint8_t dataIn[32]; NRF24L01_Transmit_Status_t transmissionStatus; /* Initialize NRF24L01+ on channel 15 and 32bytes of payload */ /* By default 2Mbps data rate and 0dBm output power */ /* NRF24L01 goes to RX mode by default */ NRF24L01_Init(15, 32); /* Set RF settings, Data rate to 2Mbps, Output power to -18dBm */ NRF24L01_SetRF(NRF24L01_DataRate_2M, NRF24L01_OutputPower_M18dBm); /* Set my address, 5 bytes */ NRF24L01_SetMyAddress(MyAddress); /* Set TX address, 5 bytes */ NRF24L01_SetTxAddress(TxAddress); LED1_ON; delay_(3600000); LED1_OFF; while (1) { /* If data is ready on NRF24L01+ */ if (NRF24L01_DataReady()) { /* Get data from NRF24L01+ */ NRF24L01_GetData(dataIn); delay_(36000); /* Send it back, automatically goes to TX mode */ NRF24L01_Transmit(dataIn); /* Start send */ LED1_ON;; delay_(360000); /* Wait for data to be sent */ do { transmissionStatus = NRF24L01_GetTransmissionStatus(); } while (transmissionStatus == NRF24L01_Transmit_Status_Sending); /* Send done */ LED1_OFF; /* Go back to RX Mode */ NRF24L01_PowerUpRx(); } } }