// Sends a data package to the default address. Be sure to send the correct // amount of bytes as configured as payload on the receiver. void nrf24_send(uint8_t* value) { /* Go to Standby-I first */ nrf24_ce_digitalWrite(LOW); /* Set to transmitter mode , Power up if needed */ nrf24_powerUpTx(); /* Do we really need to flush TX fifo each time ? */ #if 1 /* Pull down chip select */ nrf24_csn_digitalWrite(LOW); /* Write cmd to flush transmit FIFO */ spi_transfer(FLUSH_TX, 1); /* Pull up chip select */ nrf24_csn_digitalWrite(HIGH); #endif /* Pull down chip select */ nrf24_csn_digitalWrite(LOW); /* Write cmd to write payload */ spi_transfer(W_TX_PAYLOAD, 0); /* Write payload */ nrf24_transmitSync(value,payload_len); /* Pull up chip select */ nrf24_csn_digitalWrite(HIGH); /* Start the transmission */ nrf24_ce_digitalWrite(HIGH); }
/* Write to a single register of nrf24 */ void nrf24_writeRegister(uint8_t reg, uint8_t* value, uint8_t len) { nrf24_csn_digitalWrite(LOW); spi_transfer(W_REGISTER | (REGISTER_MASK & reg)); nrf24_transmitSync(value,len); nrf24_csn_digitalWrite(HIGH); }
void nrf24_test_sender() { int temp; data_array[0] = 0x00; data_array[1] = 0xAA; data_array[2] = 0x55; data_array[3] = 0x00; nrf24_ce_digitalWrite(LOW); /* Set to transmitter mode , Power up if needed */ nrf24_powerUpTx(); /* Do we really need to flush TX fifo each time ? */ #if 1 /* Pull down chip select */ nrf24_csn_digitalWrite(LOW); /* Write cmd to flush transmit FIFO */ spi_transfer(FLUSH_TX); /* Pull up chip select */ nrf24_csn_digitalWrite(HIGH); #endif /* Pull down chip select */ nrf24_csn_digitalWrite(LOW); /* Write cmd to write payload */ spi_transfer(W_TX_PAYLOAD); /* Write payload */ nrf24_transmitSync(data_array, 30); /* Pull up chip select */ nrf24_csn_digitalWrite(HIGH); /* Start the transmission */ nrf24_ce_digitalWrite(HIGH); /* Wait for transmission to end */ }
void nrf24_send(const void *value, unsigned short payload_len) { //This is supposed to be modularisd and call prepare and transmit but for now we just do //everythung here /* Go to Standby-I first */ int i=0; length_arr=payload_len; //payload_len=23; //nrf24_test_sender(); //return; for(i=0;i<127;i++) { data[i]=0; } for(i=0;i<payload_len;i++) { data[i]=((uint8_t *)value)[i]; } nrf24_ce_digitalWrite(LOW); /* Set to transmitter mode , Power up if needed */ nrf24_powerUpTx(); /* Do we really need to flush TX fifo each time ? */ #if 1 /* Pull down chip select */ nrf24_csn_digitalWrite(LOW); /* Write cmd to flush transmit FIFO */ spi_transfer(FLUSH_TX); /* Pull up chip select */ nrf24_csn_digitalWrite(HIGH); #endif /* Pull down chip select */ nrf24_csn_digitalWrite(LOW); /* Write cmd to write payload */ spi_transfer(W_TX_PAYLOAD); /* Write payload */ nrf24_transmitSync(value,payload_len); /* Pull up chip select */ nrf24_csn_digitalWrite(HIGH); /* Start the transmission */ nrf24_ce_digitalWrite(HIGH); //while(true); //while(1); //while(1); while(nrf24_isSending()); //nrf24_powerUpRx(); }