/**@brief Function for putting the chip into sleep mode. * * @note This function will not return. */ static void sleep_mode_enter(void) { uint32_t err_code; #ifdef DEBUG nrf_delay_ms(100); #endif // Stop all sensor timers sensors_timers_stop(); // TODO: Put all sensors in deep sleep // TODO: Stop all relevant timers? // Prepare wakeup buttons. err_code = app_button_disable(); APP_ERROR_CHECK(err_code); // Configure buttons with sense level low as wakeup source. // Should already have been done, but just to make sure nrf_gpio_cfg_sense_input(BUTTON1, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW); // Wait 1s for things to finish nrf_delay_ms(1000); // Go to system-off mode (this function will not return; wakeup will cause a reset). err_code = sd_power_system_off(); APP_ERROR_CHECK(err_code); }
int main() { uint8_t output_state = 0; nrf_gpio_pin_dir_set(LED_PIN, NRF_GPIO_PIN_DIR_OUTPUT); int n = 0; initialise_monitor_handles(); printf("hello world!\n"); while(++n) { printf("round %d\n", n); nrf_delay_ms(1000); if (output_state == 1) nrf_gpio_pin_set(LED_PIN); else nrf_gpio_pin_clear(LED_PIN); output_state = (output_state + 1) & 1; nrf_delay_ms(100); } return 0; }
void printStorerChunk(int chunk) { if (chunk > LAST_FLASH_CHUNK || chunk < 0) { // invalid chunk debug_log("ERR: Invalid storer chunk to print\r\n"); return; } mic_chunk_t* chunkPtr = (mic_chunk_t*)ADDRESS_OF_CHUNK(chunk); debug_log("-FLASH chunk %d:\r\n",chunk); debug_log("ts: 0x%lX - ms: %hd - ba: %d -- ch: 0x%lX",(*chunkPtr).timestamp, (*chunkPtr).msTimestamp, (int)((*chunkPtr).battery*1000), (*chunkPtr).check ); nrf_delay_ms(3); for (int i = 0; i < SAMPLES_PER_CHUNK; i++) { if (i%10 == 0) debug_log("\r\n "); unsigned char sample = (*chunkPtr).samples[i]; if (sample != INVALID_SAMPLE) { debug_log("%3u, ",(int)sample); } else { debug_log("- , "); } nrf_delay_ms(2); } debug_log("\r\n---\r\n"); nrf_delay_ms(10); }
int main(void) { uint32_t err_code; // Initialize. timers_init(); err_code = bsp_init(BSP_INIT_LED, APP_TIMER_TICKS(100, APP_TIMER_PRESCALER), NULL); APP_ERROR_CHECK(err_code); uart_init(); ble_stack_init(); twi_master_init(); err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING); nrf_delay_ms(200); bsp_indication_set(BSP_INDICATE_IDLE); nrf_delay_ms(200); err_code = bsp_indication_set(BSP_INDICATE_ADVERTISING); update_sensor(0); start_advertising(); timers_start(); // Enter main loop. for (;; ) { power_manage(); } }
void Spi_Flash_test(void) { uint8_t count = 5; //unsigned int x=10,y=10; SpiFlash_Write_Data("NRF", FLASH_BLOCK_NUMBLE, FLASH_PAGE_NUMBLE, FLASH_WRITE_NUMBLE); nrf_delay_ms(100); SpiFlash_Read_Data(FLASH_Buf, FLASH_BLOCK_NUMBLE , FLASH_PAGE_NUMBLE , FLASH_WRITE_NUMBLE); if((FLASH_Buf[0] == 'N') && (FLASH_Buf[1] == 'R') && (FLASH_Buf[2] == 'F')) { DispColor(0xF800);//blue nrf_delay_ms(100); DispColor(0x0000);//black nrf_delay_ms(100); //DispStr(FLASH_Buf,x,y,BLACK,RED); //nrf_delay_ms(1000); //nrf_gpio_pin_set(IND_LED); //nrf_delay_ms(2000); } else { for(;;) DispColor(0x07E0);//green //nrf_delay_ms(100); } }
int main(void){ softdevice_init(); gap_params_init(); _led.set_led_value = led_set_cb; ble_led_init(&_led); led_init(); advertising_init(); // start fast advertisement ble_advertising_start(BLE_ADV_MODE_FAST); do{ // set to 1 led gpio (bit 12 corresponding to pin 12) // NRF_GPIO->OUTSET = (1UL << GREEN_LED_PIN); // wait 300ms nrf_delay_ms(300); // set to 0 led gpio (bit 12 corresponding to pin 12) // NRF_GPIO->OUTCLR = (1UL << GREEN_LED_PIN); // wait 300ms nrf_delay_ms(300); }while(1); //infinite loop return 0; }
void rgb_lcd_begin() { _displayfunction = LCD_2LINE; nrf_delay_ms(50); rgb_lcd_command(LCD_FUNCTIONSET | _displayfunction); nrf_delay_ms(5); rgb_lcd_command(LCD_FUNCTIONSET | _displayfunction); nrf_delay_ms(2); rgb_lcd_command(LCD_FUNCTIONSET | _displayfunction); rgb_lcd_command(LCD_FUNCTIONSET | _displayfunction); _displaycontrol = LCD_DISPLAYON | LCD_CURSOROFF | LCD_BLINKOFF; rgb_lcd_display(); rgb_lcd_clear(); nrf_delay_ms(2); _displaymode = LCD_ENTRYLEFT | LCD_ENTRYSHIFTDECREMENT; rgb_lcd_command(LCD_ENTRYMODESET | _displaymode); rgb_lcd_setReg(0, 0); rgb_lcd_setReg(1, 0); rgb_lcd_setReg(0x08, 0xAA); nrf_delay_ms(1); rgb_lcd_default(); }
uint16_t battery_adc_read_once(void) { uint32_t adc_result = 0; uint16_t batt_lvl_in_milli_volts=0; battery_start(); nrf_delay_ms(10); while( !(NRF_ADC->EVENTS_END) ) { nrf_delay_ms(10); } NRF_ADC->EVENTS_END = 0; adc_result = NRF_ADC->RESULT; NRF_ADC->TASKS_STOP = 1; #if DEBUG_UART_EN // DbgPrintf("adc_result:%d\r\n",adc_result); #endif //*batt_lvl_in_milli_volts = ((uint32_t)(ADC_RESULT_IN_MILLI_VOLTS(adc_result)) & 0xffff); batt_lvl_in_milli_volts = ((uint32_t)(ADC_RESULT_IN_MILLI_VOLTS(adc_result)) & 0xffff); #if DEBUG_UART_EN // DbgPrintf("milli_volts:%d\r\n",batt_lvl_in_milli_volts); #endif //when charging, battery voltage need adjust // if(charger_status()!= NoCharge) { //batt_lvl_in_milli_volts += BATTERY_VOLTAGE_ADJUSTMENT; // } return batt_lvl_in_milli_volts; }
int main(void) { LEDS_CONFIGURE(LEDS_MASK); LEDS_OFF(LEDS_MASK); nrf_gpio_cfg_output(WAVE_ON_PIN_NUMBER); // on this pin 2Hz wave will be generated #ifdef BSP_BUTTON_0 // configure pull-up on first button nrf_gpio_cfg_input(BSP_BUTTON_0, NRF_GPIO_PIN_PULLUP); #endif APP_GPIOTE_INIT(1); uart_config(); lpcomp_init(); printf("\n\rLPCOMP driver usage example\r\n"); while (true) { print_statistics(); LEDS_ON(BSP_LED_1_MASK); NRF_GPIO->OUTCLR = (1 << WAVE_ON_PIN_NUMBER); nrf_delay_ms(100); // generate 100 ms pulse on selected pin print_statistics(); LEDS_OFF(BSP_LED_1_MASK); NRF_GPIO->OUTSET = (1 << WAVE_ON_PIN_NUMBER); nrf_delay_ms(400); } }
int main(void){ softdevice_init(); gap_params_init(); advertising_init(); // start fast advertisement ble_advertising_start(BLE_ADV_MODE_FAST); // setup led gpio in output mode NRF_GPIO->PIN_CNF[GREEN_LED_PIN] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos) | (GPIO_PIN_CNF_PULL_Disabled << GPIO_PIN_CNF_PULL_Pos) | (GPIO_PIN_CNF_INPUT_Disconnect << GPIO_PIN_CNF_INPUT_Pos) | (GPIO_PIN_CNF_DIR_Output << GPIO_PIN_CNF_DIR_Pos); do{ // set to 1 led gpio (bit 12 corresponding to pin 12) NRF_GPIO->OUTSET = (1UL << GREEN_LED_PIN); // wait 300ms nrf_delay_ms(300); // set to 0 led gpio (bit 12 corresponding to pin 12) NRF_GPIO->OUTCLR = (1UL << GREEN_LED_PIN); // wait 300ms nrf_delay_ms(300); }while(1); //infinite loop return 0; }
/**@brief Function for checking if the erase bond button press sequence is detected. * * @param[out] p_erase_bonds Will be true if the clear bonding button was pressed to wake the application up. */ static void detect_erase_bond_pressed(bool * p_erase_bonds) { uint32_t err_code; bool button; *p_erase_bonds = false; err_code = app_button_is_pushed(0, &button); APP_ERROR_CHECK(err_code); uint8_t count = 0; while (button) { nrf_delay_ms(100); count++; if (count > 20) { *p_erase_bonds = true; NRF_LOG_DEBUG("Erasing bonds button press detected!\r\n"); break; } err_code = app_button_is_pushed(0, &button); APP_ERROR_CHECK(err_code); } while (button) { nrf_gpio_pin_clear(LED_1); nrf_delay_ms(200); nrf_gpio_pin_set(LED_1); nrf_delay_ms(200); err_code = app_button_is_pushed(0, &button); APP_ERROR_CHECK(err_code); } }
/** * @brief Function for application main entry. */ int main(void) { uint8_t new_duty_cycle; uint32_t err_code; lfclk_init(); // Start APP_TIMER to generate timeouts. APP_TIMER_INIT(APP_TIMER_PRESCALER, OP_QUEUES_SIZE, NULL); /*Initialize low power PWM for all 3 channels of RGB or 3 channels of leds on pca10028*/ pwm_init(); while (true) { /* Duty cycle can also be changed from main context. */ new_duty_cycle = low_power_pwm_2.period - low_power_pwm_2.duty_cycle; err_code = low_power_pwm_duty_set(&low_power_pwm_2, new_duty_cycle); APP_ERROR_CHECK(err_code); nrf_delay_ms(500); new_duty_cycle = low_power_pwm_2.period - low_power_pwm_2.duty_cycle; err_code = low_power_pwm_duty_set(&low_power_pwm_2, new_duty_cycle); APP_ERROR_CHECK(err_code); nrf_delay_ms(500); } }
/** * @brief Function for application main entry. */ int main(void) { uint32_t err_code; // Configure LED-pins as outputs nrf_gpio_cfg_output(LED_0); nrf_gpio_cfg_output(LED_1); nrf_gpio_cfg_sense_input(BUTTON_0, NRF_GPIO_PIN_PULLUP, NRF_GPIO_PIN_SENSE_LOW); APP_GPIOTE_INIT(APP_GPIOTE_MAX_USERS); err_code = app_gpiote_user_register(&m_app_gpiote_my_id, (1 << BUTTON_0), (1 << BUTTON_0), gpiote_event_handler); APP_ERROR_CHECK(err_code); err_code = app_gpiote_user_enable(m_app_gpiote_my_id); APP_ERROR_CHECK(err_code); while(true) { nrf_gpio_pin_set(LED_1); nrf_delay_ms(500); nrf_gpio_pin_clear(LED_1); nrf_delay_ms(500); } }
/** * @param none */ void nRF905_txData(void) { /* Set nRF905 in Tx mode */ set_tx(); nrf_delay_ms(10); TxPacket(); nrf_delay_ms(10); }
/** * @param none */ void nRF905_rxData(void) { /* Set nRF905 in Rx mode */ set_rx(); while (check_ready()==0); nrf_delay_ms(10); RxPacket(); nrf_delay_ms(10); }
void assert_nrf_callback(uint16_t line_num, const uint8_t * p_file_name) { for (;;) { bsp_indication_set(BSP_INDICATE_FATAL_ERROR); nrf_delay_ms(500); bsp_indication_set(BSP_INDICATE_IDLE); nrf_delay_ms(500); } app_error_handler(0xDEADBEEF, line_num, p_file_name); }
int main(void){ nrf_gpio_range_cfg_output(18, 19); while(1){ nrf_gpio_port_write(2, 8); nrf_delay_ms(500); nrf_gpio_port_write(2, 4); nrf_delay_ms(500); } }
int main(void) { nrf_gpio_cfg_output($$com.sysprogs.examples.ledblink.LEDBIT$$); for (;;) { nrf_gpio_pin_set($$com.sysprogs.examples.ledblink.LEDBIT$$); nrf_delay_ms($$com.sysprogs.examples.ledblink.DELAYMSEC$$); nrf_gpio_pin_clear($$com.sysprogs.examples.ledblink.LEDBIT$$); nrf_delay_ms($$com.sysprogs.examples.ledblink.DELAYMSEC$$); } }
void test_led(void) { NRF_LOG_INFO("Turning LEDs on for a second\r\n"); NRF_LOG_FLUSH(); nrf_delay_ms(10); nrf_gpio_pin_clear(LED_RED); nrf_gpio_pin_clear(LED_GREEN); nrf_delay_ms(1000); nrf_gpio_pin_set(LED_RED); nrf_gpio_pin_set(LED_GREEN); nrf_delay_ms(10); }
int main(void) { uint32_t err_code; //Initialize GPIO nrf_gpiote_init(); pin_output_init(); err_code = nrf_drv_ppi_init(); APP_ERROR_CHECK(err_code); // Initialize PWM pwm_init(); // Initialize timers_init(); ble_stack_init(); gap_params_init(); services_init(); advertising_init(); conn_params_init(); //Starts advertising advertising_timer_init(); advertising_start(); //Initialize shields twi_motordriver_init(); twi_rfid_init(); // Initialize the IR lib. Must be done after initializing the SoftDevice ir_lib_init(IR_OUTPUT_PIN); err_code = ir_ppi_init(); APP_ERROR_CHECK(err_code); //Feedback, notifying the user that the DK is ready set_rgb_color(0); playNote(1607); nrf_delay_ms(30); playNote(1516); nrf_delay_ms(30); playNote(1431); // Enter main loop. for (;;) { power_manage(); } }
/** * @brief Function for application main entry. */ int main(void) { // Configure LED-pins as outputs. LEDS_CONFIGURE(LEDS_MASK); lys_init(); if (LYS_ERROR_SUCCESS != lys_params_receive(&m_params[0], (sizeof(m_params)/sizeof(lys_param_t)))) { while (true) { lys_error_send(); } } for (uint32_t j=0; j < m_param_num_loops; j++) { for (int i=0; i < LEDS_NUMBER; i++) { LEDS_INVERT(1 << m_leds_list[i]); switch (m_param_blink_delay_type) { case 0: nrf_delay_ms(100); break; case 1: nrf_delay_ms(500); break; case 2: nrf_delay_ms(1000); break; default: break; } } } m_result = (m_param_num_loops * m_param_blink_delay_type); if (LYS_ERROR_SUCCESS != lys_results_send(&m_results[0], (sizeof(m_results)/sizeof(lys_param_t)))) { while (true) { lys_error_send(); } } while (true) { // Finished. } }
/**************************************************************************/ float MPL3115A2_getPressure() { uint32_t pressure; MPL3115A2_write8(MPL3115A2_CTRL_REG1, MPL3115A2_CTRL_REG1_SBYB | MPL3115A2_CTRL_REG1_OS128 | MPL3115A2_CTRL_REG1_BAR); uint8_t sta = 0; while (! (sta & MPL3115A2_REGISTER_STATUS_PDR)) { sta = MPL3115A2_read8(MPL3115A2_REGISTER_STATUS); nrf_delay_ms(15); } uint8_t out[3]; MPL3115A2_readBytes_(MPL3115A2_ADDRESS, MPL3115A2_REGISTER_PRESSURE_MSB, 3, out, true); pressure = (out[0]<<16)|(out[1]<<8)|out[2]; // receive DATA pressure >>= 4; float baro = pressure; baro /= 400.0; return baro; } //**************************************************************************/ // // @brief Gets the floating-point sea level pressure setpint level in kPa // Default Pressure == 101326Pa // //**************************************************************************/ float MPL3115A2_getPressureSeaLevel() { uint32_t pressure; float baro; MPL3115A2_write8(MPL3115A2_CTRL_REG1, MPL3115A2_CTRL_REG1_SBYB | MPL3115A2_CTRL_REG1_OS128 | MPL3115A2_CTRL_REG1_BAR); // B9 uint8_t sta = 0; while (! (sta & MPL3115A2_REGISTER_STATUS_PDR)) { sta = MPL3115A2_read8(MPL3115A2_REGISTER_STATUS); nrf_delay_ms(15); } uint8_t out[2]; MPL3115A2_readBytes_(MPL3115A2_ADDRESS, 0x14, 2, out, true); // Reg... BAR ---> MSB:14 + LSB:15 // pressure = 0xC5E70; Factory Default Value // pressure = (out[0]<<12)|(out[1]<<4); // Barometric pressure at Sea Level (used for Altimeter Adjust) pressure >>= 3; baro = (float) pressure; baro /= 100.0; return baro; }
uint32_t bootloader_dfu_sd_update_continue(void) { uint32_t err_code; if ((dfu_sd_image_validate() == NRF_SUCCESS) && (dfu_bl_image_validate() == NRF_SUCCESS)) { return NRF_SUCCESS; } // Ensure that flash operations are not executed within the first 100 ms seconds to allow // a debugger to be attached. nrf_delay_ms(100); err_code = dfu_sd_image_swap(); APP_ERROR_CHECK(err_code); err_code = dfu_sd_image_validate(); APP_ERROR_CHECK(err_code); err_code = dfu_bl_image_swap(); APP_ERROR_CHECK(err_code); return err_code; }
/** * @brief Function for application main entry. * @return 0. int return type required by ANSI/ISO standard. */ int main(void) { init(); for (int i =0; true; i++) { // Set payload pointer NRF_RADIO->PACKETPTR = (uint32_t) (i%2==0? packet:scan_rsp); NRF_RADIO->EVENTS_READY = 0U; NRF_RADIO->TASKS_TXEN = 1; while (NRF_RADIO->EVENTS_READY == 0U) { } NRF_RADIO->TASKS_START = 1U; NRF_RADIO->EVENTS_END = 0U; while(NRF_RADIO->EVENTS_END == 0U) { } NRF_RADIO->EVENTS_DISABLED = 0U; // Disable radio NRF_RADIO->TASKS_DISABLE = 1U; while(NRF_RADIO->EVENTS_DISABLED == 0U) { } if (i%2 == 0) { nrf_delay_us(200); } else { nrf_delay_ms(3); } } }
/*--------------------------- -----------------------*/ void system_module_init() { // uart init simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, 0); xprintf("start up..\r\n"); // system_HFCLK_init(); // if(!system_battery_self_test()) { system_low_battery(); } // system_bootloader_check(); // system_led_flicker_init(); nrf_gpio_pin_set(RED_LED); // system_parameter_init(); // system_I2C_init(); // system_gpio_LoToHi_INT_init(ACCE_TAP_PIN_NUMBER); nrf_delay_ms(2000); nrf_gpio_pin_clear(RED_LED); }
/** * @brief Function for application main entry. */ int main(void) { uint32_t err_code; err_code = nrf_drv_clock_init(); APP_ERROR_CHECK(err_code); setup_example(); while (true) { nrf_delay_ms(1000); nrf_drv_clock_lfclk_request(NULL); nrf_delay_ms(1000); nrf_drv_clock_lfclk_release(); } }
/**@brief Function for swapping existing SoftDevice with newly received. */ uint32_t dfu_sd_image_swap(void) { uint32_t err_code = NRF_SUCCESS; bootloader_settings_t bootloader_settings; bootloader_settings_load(&bootloader_settings); if ((bootloader_settings.bank_1 & BANK_VALID_MASK) & (BANK_VALID_SD)) { bootloader_settings.bank_1 &= ~(BANK_VALID_SD); bootloader_settings_save(&bootloader_settings); err_code = copy((uint32_t *)get_address(SOFTDEVICE_PART), (uint32_t *)SOFTDEVICE_REGION_START, bootloader_settings.sd_image_size); nrf_delay_ms(100); if (err_code == NRF_SUCCESS) { NVIC_SystemReset(); } } return err_code; }
int main(void) { ret_code_t err_code; /* 2-channel PWM, 200Hz, output on DK LED pins. */ app_pwm_config_t pwm1_cfg = APP_PWM_DEFAULT_CONFIG_2CH(5000L, BSP_LED_0, BSP_LED_1); /* Switch the polarity of the second channel. */ pwm1_cfg.pin_polarity[1] = APP_PWM_POLARITY_ACTIVE_HIGH; /* Initialize and enable PWM. */ err_code = app_pwm_init(&PWM1,&pwm1_cfg,pwm_ready_callback); APP_ERROR_CHECK(err_code); app_pwm_enable(&PWM1); uint32_t value; while(true) { for (uint8_t i = 0; i < 40; ++i) { value = (i < 20) ? (i * 5) : (100 - (i - 20) * 5); ready_flag = false; /* Set the duty cycle - keep trying until PWM is ready... */ while (app_pwm_channel_duty_set(&PWM1, 0, value) == NRF_ERROR_BUSY); /* ... or wait for callback. */ while(!ready_flag); APP_ERROR_CHECK(app_pwm_channel_duty_set(&PWM1, 1, value)); nrf_delay_ms(25); } } }
/**@brief Function for application main entry. Does not return. */ int main(void) { bool is_test_success; // Configure all LEDs as outputs. nrf_gpio_range_cfg_output(LED_START, LED_STOP); // Set LED_0 high to indicate that the application is running. nrf_gpio_pin_set(LED_0); for (;;) { is_test_success = test_spi_tx_rx(); if (!is_test_success) { // Set LED2 high to indicate that error has occurred. nrf_gpio_pin_set(LED_2); for (;;) { // No implementation needed. } } nrf_gpio_pin_toggle(LED_1); nrf_delay_ms(DELAY_MS); } }
/**@brief Function for application main entry. */ int main(void) { uint32_t err_code; bool erase_bonds; // Initialize. timers_init(); buttons_leds_init(&erase_bonds); ble_stack_init(); device_manager_init(erase_bonds); gap_params_init(); advertising_init(); services_init(); conn_params_init(); saadc_init(); // Start execution. application_timers_start(); err_code = ble_advertising_start(BLE_ADV_MODE_FAST); APP_ERROR_CHECK(err_code); // Enter main loop. for (;;) { // trigger next ADC conversion nrf_drv_saadc_sample_convert(0,&adc_sample); advdata.p_manuf_specific_data->data.p_data[0] = adc_sample/100 + '0'; advdata.p_manuf_specific_data->data.p_data[1] = adc_sample%100/10 + '0'; advdata.p_manuf_specific_data->data.p_data[2] = adc_sample%10 + '0'; nrf_delay_ms(100); ble_advdata_set(&advdata, NULL); } }