void initRadio(void){ nrf24_init(); nrf24_config(NRF24_CHANNEL_MHZ, NRF24_PAYLOAD_LEN);//channel 15, 16 byte payload nrf24_tx_address(ptxAddr); nrf24_rx_address(prxAddr); }
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); } }
/*---------------------------------------------------------------------------*/ static PT_THREAD(nrf24_thread(struct pt *pt)) { PT_BEGIN(pt); /* init hardware pins */ nrf24_init(); /* Channel #2 , payload length: 8 */ nrf24_config(2,8); /* Set the device addresses */ nrf24_tx_address(tx_address); nrf24_rx_address(rx_address); uint32_t counter; uint16_t temp; int16_t realval; while(1) { PT_WAIT_UNTIL(pt,nrf24_dataReady()); dbg(PSTR("> -------------------------------------\r\n")); nrf24_getData(data_array); temp = (data_array[0]<<8)+data_array[1]; realval = temp * 10; realval /= 11; realval -= 500; dbg(PSTR("> RAW Temp: %u\r\n"),temp); dbg(PSTR("> Temp: %u\r\n"),realval); temp = (data_array[2]<<8)+data_array[3]; dbg(PSTR("> Batt: %u\r\n"),temp); counter = (data_array[4]<<24)+(data_array[5]<<16)+(data_array[6]<<8)+data_array[7]; dbg(PSTR("> Counter: %u\r\n"),counter); } PT_END(pt); }
int main(int argc, char **argv){ uint8_t data_array[4]; uint8_t tx_address[5] = { 0xE7, 0xE7, 0xE7, 0xE7, 0xE7 }; uint8_t rx_address[5] = { 0xD7, 0xD7, 0xD7, 0xD7, 0xD7 }; if (!bcm2835_init()) return 1; mysql_connect(); /* 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); printf("Configured\n"); while (1){ if (nrf24_dataReady()) { nrf24_getData(data_array); printf("> %d %d %d %d \n", data_array[0], data_array[1], data_array[2], data_array[3]); if (argc>1) { if (argv[1][0]=='1') { writeCpm( data_array[0], data_array[1], data_array[2], data_array[3]); } } } } mysql_disconnect(); bcm2835_close(); return 0; }
/*---------------------------------------------------------------------------*/ void init_hardware() { /* init interrupt pin */ pinMode(B,2,INPUT); /* init led ... */ led0_init(); led0_low(); /* init hardware pins */ nrf24_init(); /* disable the analog comparator */ ACSR = (1<<ACD); /* channel #2 , payload length: 4 */ nrf24_config(2,32); /* get the rx address from EEPROM */ rx_address[0] = eeprom_read_byte((uint8_t*)10); rx_address[1] = eeprom_read_byte((uint8_t*)11); rx_address[2] = eeprom_read_byte((uint8_t*)12); rx_address[3] = eeprom_read_byte((uint8_t*)13); rx_address[4] = eeprom_read_byte((uint8_t*)14); /* set the device addresses */ nrf24_tx_address(tx_address); nrf24_rx_address(rx_address); /* initial power-down */ nrf24_powerDown(); /* disable digital buffer at the adc pin */ cbi(DIDR0,ADC1D); PRR = (1<<PRTIM1)|(1<<PRTIM0)|(0<<PRADC)|(0<<PRUSI); }
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); } }
/** * @brief Main program. * @param None * @retval None */ void main(void) { static u8 status; bool flag_display_retrans_cnt; disableInterrupts(); Config(); Errors_Init(); enableInterrupts(); Goto_HALT(); while (1) { if((btn_pressed != BUTTON1) && (btn_pressed != BUTTON2)) { DELAY_STOP; goto sleep; } PWR_PVDCmd(ENABLE); /* Power voltage detector and brownout Reset unit supply current 2,6uA */ PWR_PVDLevelConfig(PWR_PVDLevel_2V26); /* Set Programmable voltage detector threshold to 2,26V */ if(DELAY_EXPIRED) flag_display_retrans_cnt = TRUE; else flag_display_retrans_cnt = FALSE; while(!DELAY_EXPIRED); /* wait for power-up delay to expire (199.68ms) - needed for nRF24L01+ power up */ DELAY_STOP; CLK_PeripheralClockConfig(CLK_Peripheral_SPI1, ENABLE); nrf24_init(); /* init hardware pins */ nrf24_config(0, 6); /* Channel #0 , payload length: 6 */ nrf24_tx_address(tx_address); /* Set the device addresses */ nrf24_rx_address(rx_address); /* Check NRF24 Init error */ if(Errors_CheckError(ERROR_NRF24_INIT)) { LED_Red_Blink(2); goto sleep; } TXmsg.M.status = 0; /* Reset status byte */ /* Check Programmable voltage detector (PVD) output flag, if battery low send this information */ /* Internal reference voltage should be stable at this point */ if(PWR->CSR1 & PWR_FLAG_PVDOF) { /* VDD/VDDA is below the VPVD threshold (2,26V) */ TXmsg.M.status |= STATUS_LOWBATT; } PWR_PVDCmd(DISABLE); if(btn_pressed == BUTTON1) { TXmsg.M.ownID = (u32)ownID_btn1; TXmsg.M.txcnt = tx_cnt++; nrf24_send((u8*)&TXmsg.B.b[0]); } else if(btn_pressed = BUTTON2) { TXmsg.M.ownID = (u32)ownID_btn2; TXmsg.M.txcnt = tx_cnt++; nrf24_send((u8*)&TXmsg.B.b[0]); } btn_pressed = 0; do { status = nrf24_getStatus(); } while(!(status & ((1 << TX_DS) | (1 << MAX_RT)))); if(status & (1 << TX_DS)) /* send successful */ { if(flag_display_retrans_cnt) { u8 i; u8 retrans_cnt = nrf24_retransmissionCount(); LED_Green_Blink(retrans_cnt); } else { LED_Green_Blink(1); } } else if(status & (1 << MAX_RT)) /* send failed, max retries exceeded */ { LED_Red_Blink(1); } sleep: Goto_HALT(); } }
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(); } } }
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]); } } */ } }