/* Send data using the nRF radio */ void radioTask(void *pvParameters) { (void) pvParameters; uint8_t rfData[NRF24_PAYLOAD_LEN]; uint8_t rcvData[NRF24_PAYLOAD_LEN]; uint8_t pktCounter = 0; uint8_t blinkCounter = 0; const portTickType blinkDelay = 250 / portTICK_RATE_MS; const portTickType sendDelay = 5000 / portTICK_RATE_MS; rfData[0] = 0xB1; rfData[1] = 0x3A; rfData[2] = 0x23; while(1) { if(nrf24_dataReady()) { nrf24_getData(rcvData); // Format message for debugging char debugRcvString[3*6] = {0}; for (uint8_t i=0; i < NRF24_PAYLOAD_LEN; i++) { sprintf(debugRcvString+(3*i), "%02X ", rcvData[i]); } printf("Received: %s\n", debugRcvString); } rfData[3] = pktCounter++; nrf24_send(rfData); while(nrf24_isSending()); char debugSendString[3*6] = {0}; for (uint8_t i = 0; i < NRF24_PAYLOAD_LEN; i++) { sprintf(debugSendString+(3*i), "%02X ", rfData[i]); } printf("Sent: %s\n", debugSendString); if(nrf24_lastMessageStatus()) { //there was a send problem }else{ //transmission was ok } for(blinkCounter = 1 + nrf24_retransmissionCount(); blinkCounter > 0; --blinkCounter) { PORTC |= _BV(PORTC3); vTaskDelay(blinkDelay); PORTC &= ~_BV(PORTC3); vTaskDelay(blinkDelay); } nrf24_powerUpRx(); vTaskDelay(sendDelay); } }
void copy_paste() { int temp; nrf24_config(2, 4); nrf24_tx_address(tx_address11); nrf24_rx_address(rx_address11); while (1) { //LED0 = LED_ON; //LED1 = LED_ON; //LED2 = LED_ON; //LED3 = LED_ON; //delay_loop1(); //LED0 = LED_OFF; //LED1 = LED_OFF; //LED2 = LED_OFF; //LED3 = LED_OFF; //delay_loop1(); //nrf24_tx_address((uint8_t*) (uartBuffer + 1)); data_array[0] = 0x00; data_array[1] = 0xAA; data_array[2] = 0x55; data_array[3] = 0x22; /* Automatically goes to TX mode */ nrf24_send(data_array,4); /* Wait for transmission to end */ while (nrf24_isSending()); /* Make analysis on last tranmission attempt */ temp = nrf24_lastMessageStatus(); if (temp == NRF24_TRANSMISSON_OK) { //Do something } else if (temp == NRF24_MESSAGE_LOST) { //Do something else } /* Retranmission count indicates the tranmission quality */ /* Optionally, go back to RX mode ... */ //nrf24_powerUpRx(); /* Or you might want to power down after TX */ // nrf24_powerDown(); /* Wait a little ... */ //_delay_ms(10); } }
int main() { DDRB |= 1<<PORTB3; PORTB |= 1<<PORTB3; ledPort |= _BV(ledPin); /* init hardware pins */ nrf24_init(); /* Channel #2 , payload length: 4 */ nrf24_config(2,4); /* Set the device addresses */ nrf24_tx_address(tx_address); nrf24_rx_address(rx_address); pwm_init(); // initialize timer in PWM mode interupt_init(); //initalize Interrupt 0 /* Fill the data buffer */ data_array[0] = deviceID; data_array[1] = 0xAA; while(1) { data_array[3] = events; data_array[2] = events >> 8; nrf24_send(data_array); /* Wait for transmission to end */ while(nrf24_isSending()) { } ledPort ^= _BV(ledPin); _delay_ms(80000); } }
/* ------------------------------------------------------------------------- */ int main() { /* init the software uart */ uart_init(); /* init the xprintf library */ xdev_out(uart_put_char); /* simple greeting message */ xprintf("\r\n> TX device ready\r\n"); /* init hardware pins */ nrf24_init(); /* Channel #2 , payload length: 4 */ nrf24_config(2,4); /* Set the device addresses */ nrf24_tx_address(tx_address); nrf24_rx_address(rx_address); while(1) { /* Fill the data buffer */ data_array[0] = 0x00; data_array[1] = 0xAA; data_array[2] = 0x55; data_array[3] = q++; /* Automatically goes to TX mode */ nrf24_send(data_array); /* Wait for transmission to end */ while(nrf24_isSending()); /* Make analysis on last tranmission attempt */ temp = nrf24_lastMessageStatus(); if(temp == NRF24_TRANSMISSON_OK) { xprintf("> Tranmission went OK\r\n"); } else if(temp == NRF24_MESSAGE_LOST) { xprintf("> Message is lost ...\r\n"); } /* Retranmission count indicates the tranmission quality */ temp = nrf24_retransmissionCount(); xprintf("> Retranmission count: %d\r\n",temp); /* Optionally, go back to RX mode ... */ nrf24_powerUpRx(); /* Or you might want to power down after TX */ // nrf24_powerDown(); /* Wait a little ... */ _delay_ms(10); } }
int main() { uint8_t i, change; uint8_t hand; uint32_t timeout = 0; uart_init(); xdev_out(uart_putchar); // Determine which hand this is from PE2 // Left is hand 0, right is hand 1 PORTE = (1 << 2); DDRE = 0; hand = (PINE & 0x04) ? 0 : 1; xprintf("\r\nHand %d\r\n", hand); // Initialise NRF24 // Set the last byte of the address to the hand ID rx_address[4] = hand; nrf24_init(); nrf24_config(CHANNEL, sizeof msg); nrf24_tx_address(tx_address); nrf24_rx_address(rx_address); matrix_init(); msg[0] = hand & 0x01; msg[1] = 0; msg[2] = 0; // Set up LED and flash it briefly DDRE |= 1<<6; PORTE = 1<<6; _delay_ms(500); PORTE = 0; get_voltage(); check_voltage(); // Scan the matrix and detect any changes. // Modified rows are sent to the receiver. while (1) { timeout++; matrix_scan(); for (i=0; i<ROWS; i++) { change = matrix_prev[i] ^ matrix[i]; // If this row has changed, send the row number and its current state if (change) { if (DEBUG) xprintf("%d %08b -> %08b %ld\r\n", i, matrix_prev[i], matrix[i], timeout); msg[1] = i; msg[2] = matrix[i]; nrf24_send(msg); while (nrf24_isSending()); timeout = 0; } matrix_prev[i] = matrix[i]; } // Sleep if there has been no activity for a while if (timeout > SLEEP_TIMEOUT) { timeout = 0; enter_sleep_mode(); } } }
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(); }
int main(void) { /* Initialise the GPIO block */ gpioInit(); /* Initialise the UART0 block for printf output */ //uart0Init(115200); uart0Init(9600); /* Configure the multi-rate timer for 1ms ticks */ mrtInit(__SYSTEM_CLOCK/1000); /* Configure the switch matrix (setup pins for UART0 and GPIO) */ //configurePins(); spiInit(LPC_SPI0, 6, 0); SwitchMatrix_Init(); //uart & spi LPC_GPIO_PORT->DIR0 |= (1 << CSN); LPC_GPIO_PORT->DIR0 |= (1 << CE); uint8_t temp = 0; nrf24_init(); /* Set the LED pin to output (1 = output, 0 = input) */ #if !defined(USE_SWD) LPC_GPIO_PORT->DIR0 |= (1 << LED_LOCATION); #endif //printf("write"); mrtDelay(500); nrf24_config(2,16); #if TX_NODE nrf24_tx_address(tx_address); nrf24_rx_address(rx_address); #else nrf24_tx_address(rx_address); //backwards looking but is fine nrf24_rx_address(tx_address); #endif uint8_t i = 0; while(1) { /* Turn LED On by setting the GPIO pin high */ LPC_GPIO_PORT->SET0 = 1 << LED_LOCATION; mrtDelay(500); /* Turn LED Off by setting the GPIO pin low */ LPC_GPIO_PORT->CLR0 = 1 << LED_LOCATION; mrtDelay(500); /* printf("Send\r\n"); for(i=0; i<16; i++){ printf("%d: %d\n\r", i, tx_data_array[i]); } */ nrf24_send(tx_data_array); while(nrf24_isSending()); nrf24_powerUpRx(); //done transmitting, set back to rx mode for(i=0; i<16; i++){ tx_data_array[i]++; } /* if(nrf24_dataReady()){ printf("\n\rGot data\n\r"); nrf24_getData(rx_data_array); for(i=0; i<16; i++){ printf("%d: %d\n\r", i, rx_data_array[i]); } } */ } }