void NRF_EnableRX(void) { NRF_WriteRegister(NRF_STATUS, 0x7E); NRF_WriteRegister(NRF_CONFIG, 0x0F); NRF_SendCommand(NRF_FLUSH_RX, 0xFF); for (int i =0; i < 2; i++) { NRF_Delay(); } NRF_CE_hi; for (int i =0; i < 2; i++) { NRF_Delay(); } NRF_SendCommand(NRF_FLUSH_RX, 0xFF); }
uint8_t NRF2_SendPayload(NRF_PayloadDataType* NRF_Payload) { uint8_t bytecnt, status; /* Reset CE pin to enable register write */ NRF2_CE_LOW; /* Reset CS pin to initiate an SPI transmission */ NRF2_CS_LOW; /* Send NRF_WR_TX_PLOAD command */ assert_param(NRF_Payload->NRF_PayloadWidth <= NRF_MAX_PAYLOAD_WIDTH); status = NRF2_SPI_SendByte(NRF_WR_TX_PLOAD); /* Send payload contents */ for(bytecnt = 0; bytecnt < NRF_Payload->NRF_PayloadWidth; bytecnt++) { NRF2_SPI_SendByte(NRF_Payload->NRF_Payload[bytecnt]); } /* Set CS pin to complete transmission */ NRF2_CS_HIGH; /* Hold CE high for at least 10us to send payload */ NRF2_CE_HIGH; NRF_Delay(200); NRF2_CE_LOW; return status; }
void recv_setup() { status = RECEIVER; //printf("enabling receiver"); NRF_WriteRegister(NRF_STATUS, 0x7E); // reset status register NRF_SendCommand(NRF_FLUSH_RX, 0xFF); NRF_WriteRegister(NRF_CONFIG, 0x0F); NRF_CE_hi; NRF_Delay(); }
void net_send_packet(uint8_t *packet) { if (status != SENDER) { // while (action == READING) {} sender_enable(); } action = WRITING; printf("Sending packet %p %d %d %d %d\n", packet, packet[0],packet[1],packet[2], packet[3]); int aux = ID; while (aux > 0) { aux--;} // send payload NRF_SendPayload(NRF_W_TX_PAYLOAD,NET_PACKET_SIZE,packet); // enable the chip to send the packet NRF_CE_hi; NRF_Delay(); NRF_CE_lo; action = WAITING; }