Exemple #1
0
/**
 * main() function
 * @return 0. int return type required by ANSI/ISO standard.
 */
int main(void)
{
  simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC);

#ifndef ENABLE_LOOPBACK_TEST

  uart_start();
  while(true)
  {
    uint8_t cr = simple_uart_get();
    simple_uart_put(cr);

    if(cr == 'q' || cr == 'Q')
    {
      uart_quit();
      while(1){}
    }
  }

#else
  /* This part of the example is just for testing, can be removed if you do not have a loopback setup */

  // ERROR_PIN configure as output
  nrf_gpio_cfg_output(ERROR_PIN);
  while(true)
  {
    uart_loopback_test();
  }
#endif
}
/*---------------------------  -----------------------*/
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);
    
    
}
Exemple #3
0
void init(void)
{
  /* Start 16 MHz crystal oscillator */
  NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
  NRF_CLOCK->TASKS_HFCLKSTART = 1;

  /* Wait for the external oscillator to start up */
  while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) 
  {
  }

  // Set radio configuration parameters
  radio_configure();
  
  simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC);

  // Set payload pointer
  //NRF_RADIO->PACKETPTR = (uint32_t)scan_rsp; //packet;  


  // We will only announce on channel 37 for now
  int channel = 37;
  NRF_RADIO->DATAWHITEIV = channel & 0x3F;
  NRF_RADIO->FREQUENCY = ch2freq(channel);

}
/**@brief Function for application main entry.
 */
int main(void) {
// Initialize
	leds_init();
	timers_init();
	gpiote_init();
	buttons_init();
	simple_uart_config(UART_RTS, UART_TX, UART_CTS, UART_RX, 0);
	ble_stack_init();
	scheduler_init();
	gap_params_init();
	services_init();
	advertising_init();
	conn_params_init();
	sec_params_init();
// Start execution
	//app_button_enable();
	advertising_start();
	uart_tx_str("nRF51822 run");

// Enter main loop

	for (;;) {
		app_sched_execute();
		power_manage();
	}
}
Exemple #5
0
/*
==============================================
Function: initialize_all(void)

	Initialize oscillator, radio, bluetooth,
	twi and vibration	

==============================================
*/
static void initialize_all()
{
	char buf[30];
	// Start 16 MHz crystal oscillator.
	NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
	NRF_CLOCK->TASKS_HFCLKSTART    = 1;
	
        // oscillator
	while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {
		// busy wait until the oscilator is up and running
	}
	
	simple_uart_config(0, 23, 0, 22, 0);
	simple_uart_putstring("INIT\n");
	
	// initiliaze radio
    radio_configure(); 
    simple_uart_putstring("Configured radio\n");

	// initialize bluetooth
    start_ble(MUG_LIST); 
	simple_uart_putstring("BLUETOOTH STARTED\n");
		
	// initialize twi
	twi_master_init();
	simple_uart_putstring("TWI master init\n");

	init_vibration();
	simple_uart_putstring("Vibration init\n");


}
Exemple #6
0
void log_uart_init(void)
{
    simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER,
                        CTS_PIN_NUMBER, RX_PIN_NUMBER,
                        HWFC);

    nrf_delay_ms(10);
}
/**@brief  Function for initializing the UART module.
 */
static void uart_init(void)
{
    /**@snippet [UART Initialization] */
    simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC);
    
    NRF_UART0->INTENSET = UART_INTENSET_RXDRDY_Enabled << UART_INTENSET_RXDRDY_Pos;
    
    NVIC_SetPriority(UART0_IRQn, APP_IRQ_PRIORITY_LOW);
    NVIC_EnableIRQ(UART0_IRQn);
    /**@snippet [UART Initialization] */
}
Exemple #8
0
/**
 * Configures INTERRUPT_PIN for input and
 * configures GPIOTE to give interrupt on pin change.
 */
static void gpio_init(void){
    simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC);
    NRF_GPIO->PIN_CNF[INTERRUPT_PIN] = (GPIO_PIN_CNF_SENSE_Low << GPIO_PIN_CNF_SENSE_Pos)
                                        | (GPIO_PIN_CNF_DRIVE_S0S1 << GPIO_PIN_CNF_DRIVE_Pos)
                                        | (NRF_GPIO_PIN_NOPULL << GPIO_PIN_CNF_PULL_Pos)
                                        | (GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos)
                                        | (GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos); 

    // Enable interrupt:
    NVIC_EnableIRQ(GPIOTE_IRQn);
    NRF_GPIOTE->INTENSET = GPIOTE_INTENSET_PORT_Set << GPIOTE_INTENSET_PORT_Pos;  
    sd_nvic_SetPriority(GPIOTE_IRQn, NRF_APP_PRIORITY_LOW);   
}
/**
 * @brief Function for application main entry.
 */
int main(void)
{
    gpio_init();
	interrupt_init();
	LTC2492_Init();
	nrf_gpio_pin_set(LED_1);
	
	simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC);
	
	
	int size = 128; 
	double storage[128];
	memset(storage, 0, sizeof(*storage) * size);
	//double * storage = malloc(sizeof(*storage) * size ); 
	int i = 0; 
    while (true)
    {	
		
		nrf_delay_ms(150); 
		
		nrf_gpio_pin_toggle(LED_1);
		uint32_t output = SPI0_LTC2492_Read();
		
		uint8_t chuncks_8bit[4];
		chuncks_8bit[0] = (output & 0xFF000000) >> 24; ;
		chuncks_8bit[1] = (output & 0x00FF0000) >> 16; 
		chuncks_8bit[2] = (output & 0x0000FF00) >> 8; 
		chuncks_8bit[3] = (output & 0x000000FF) >> 0; 
		
		int count; 
		for (count = 0; count < 4; count++) {
			simple_uart_put(chuncks_8bit[count]);
		}
		
		
		
		storage[i] = output; 
		i++; 
		
		if (i == 128) {
			i = 0; 
		}
		
			
	}
	
		
}
Exemple #10
0
/**
 * @brief Function for application main entry.
 * @return 0. int return type required by ANSI/ISO standard.
 */
int main(void)
{
    const uint8_t *key_packet;
    uint8_t key_packet_size;

#ifdef USE_UART
    simple_uart_config(0, SIMPLE_UART_TXD_PIN_NUMBER, 0, SIMPLE_UART_RXD_PIN_NUMBER, false); // Hardware flow control not used in this example.
#else
    // Configure pins 24-30 for LEDs. Note that pin 31 is not connected.
    nrf_gpio_range_cfg_output(24, 30);
#endif

    // Enable pulldowns on row port, see matrix_row_port.
    nrf_gpio_range_cfg_input(16, 23, NRF_GPIO_PIN_PULLDOWN);

    // Column pin configuration, see matrix_column_port.
    nrf_gpio_range_cfg_output(0, 15);

    if (cherry8x16_init(matrix_row_port, matrix_column_port, CHERRY8x16_DEFAULT_KEY_LOOKUP_MATRIX) != CHERRY8x16_OK)
    {
#ifdef USE_UART
        simple_uart_putstring((const uint8_t *)"Init failed.");
#else
        nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT3, 0x55);
#endif
        while (true) 
        {
            // Do nothing.
        }
    }

    while(true)
    {
        if (cherry8x16_new_packet(&key_packet, &key_packet_size))
        {
#ifdef USE_UART
            // Send the whole key packet over UART.
            uart_puthidstring((char*)&key_packet[KEY_PACKET_KEY_INDEX]);
#else
            // Show modifier key state using the LEDs. Note LED's use GPIO pins from 8 to 15.
        nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT3, key_packet[KEY_PACKET_MODIFIER_KEY_INDEX]);
#endif
        }
        nrf_delay_ms(25);
    }
}
Exemple #11
0
/**@brief Function for application main entry.
 */
int main(void)
{
	system_HFCLK_init();
	// uart init
    simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, 0); 
    xprintf("APP start up..\r\n");
	
	mcu_bootloader_check();
    // Initialize.
    app_trace_init();
    leds_init();
    buttons_init();
    ble_stack_init();
    device_manager_init();
    timers_init();
    gap_params_init();
    advertising_init();
    services_init();
    sensor_sim_init();
    conn_params_init();
	
	//I2C and sensor initial
	system_I2C_init();
	OLED_Init();
	sensor_init();
	enter_pedo_mode();	
	
	GPIO_HiToLo_INT_config(BUTTON_2);
	
	// Test battery
	if(!battery_self_detect())
    {
        system_low_battery();
    }
	
	// Start execution.
    application_timers_start();
    advertising_start();
	
	// Enter main loop.
    for (;;)
    {
        power_manage();
    }
}
void init(void)
{
    /* Start 16 MHz crystal oscillator */
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART = 1;

    /* Wait for the external oscillator to start up */
    while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
    {
    }

    // Set radio configuration parameters
    radio_configure();

    // Set payload pointer
    NRF_RADIO->PACKETPTR = (uint32_t)packet;

    simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC);
}
void init()
{
  /* Start 16 MHz crystal oscillator */
  NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
  NRF_CLOCK->TASKS_HFCLKSTART = 1;

  /* Wait for the external oscillator to start up */
  while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
  {
  }

  // Set radio configuration parameters
  

  simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC);

  // Set payload pointer
	
	radio_configure(1, 0);  
}
Exemple #14
0
//Initialize the mhTerminal
void Terminal::Init()
{
#ifdef ENABLE_TERMINAL
	registeredCallbacks = new SimplePushStack(MAX_TERMINAL_COMMAND_LISTENER_CALLBACKS);

	//Start UART communication
	simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC);

	char versionString[15];
	Utility::GetVersionStringFromInt(Config->firmwareVersion, versionString);

	if (promptAndEchoMode)
	{
		//Send Escape sequence
		simple_uart_put(27); //ESC
		simple_uart_putstring((const u8*) "[2J"); //Clear Screen
		simple_uart_put(27); //ESC
		simple_uart_putstring((const u8*) "[H"); //Cursor to Home

		//Send App start header
		simple_uart_putstring((const u8*) "--------------------------------------------------" EOL);
		simple_uart_putstring((const u8*) "Terminal started, compile date: ");
		simple_uart_putstring((const u8*) __DATE__);
		simple_uart_putstring((const u8*) "  ");
		simple_uart_putstring((const u8*) __TIME__);
		simple_uart_putstring((const u8*) ", version: ");
		simple_uart_putstring((const u8*) versionString);

#ifdef NRF52
		simple_uart_putstring((const u8*) ", nRF52");
#else
		simple_uart_putstring((const u8*) ", nRF51");
#endif

		simple_uart_putstring((const u8*) EOL "--------------------------------------------------" EOL);
	}

	terminalIsInitialized = true;
#endif
}
Exemple #15
0
int main()
{
    simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, 0);
    xprintf("\n\n\n\n\n\r\n region2 start..\r\n");
       
    if(region1_is_valid())
    {
        xprintf("dump to region11111\r\n");
        bootloader_app_start();
    }
    
    system_app_pages_erase(CODE_REGION_1_START, CODE_REGION_1_SIZE);
    xprintf(" app area has eased..\r\n");

    ble_start(); 
  
    for( ; ;)
    {
        ble_rec_handle();       
        
        if(get_dfu_state() == SYSTEM_UPDATE_END)
        {            
            xprintf("system update end.\r\n");
            sd_softdevice_disable();
            
            flash_specword_write((uint32_t*)BOOTLOADER_SETTINGS_ADDRESS, SYSTEM_APP_VALID_OFFSET, SYSTEM_APP_VALID); 
            NVIC_SystemReset();  
        }
       
        if(get_dfu_state() == SYSTEM_UPDATE_FAILURE)
        {
            xprintf("system update failed.\r\n");
            NVIC_SystemReset();            
        }
    }

    
}
Exemple #16
0
int main(void)
{
    // Start 16 MHz crystal oscillator.
    NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
    NRF_CLOCK->TASKS_HFCLKSTART    = 1;

    // Wait for the external oscillator to start up.
    while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0) {}

    // Enable UART comms
    simple_uart_config(0, 23, 0, 22, 0);
    unsigned char buf[32];
    uint8_t uart_data;

    // Enable LED
    nrf_gpio_cfg_output(0);

    // Set radio configuration parameters.
    radio_configure();

    // Print Device ID
    uint64_t this_device_id = (((uint64_t) NRF_FICR->DEVICEID[1] << 32) | ((uint64_t) NRF_FICR->DEVICEID[0]));
    sprintf((char*)buf, "ID: %llx\n",  this_device_id);
    simple_uart_putstring(buf);

    // Initialise LibAlek
    // init_vibration();

    uint8_t availability;

    while(true){
        uint64_t device_id = 0;

        // vibration_update();
        if (receive_packet()){
            device_id = packet[1];
            if (this_device_id == device_id){
                if (packet[0] == 0xcfcf){  // Master init sequence
                    simple_uart_putstring("Got init!\n");
                    packet[0] = 0xaf;  // Send ACK to Master
                    send_packet(1);    // ... 3 times ...

                    simple_uart_putstring("[a]ccept or [r]eject:\n");
                    uart_data = simple_uart_get();
                    switch (uart_data) {
                      case 'a':
                        availability = 0xaa;
                        simple_uart_putstring("Accepted\n");
                        break;
                      case 'r':
                        availability = 0xff;
                        simple_uart_putstring("Rejected\n");
                        break;
                    }
                    uart_data = simple_uart_get();
                } else if (packet[0] == 0xabab) {  // Master poll availability
                    simple_uart_putstring("Sent availability status!\n");
                    packet[0] = availability;  // Send ACK to Master
                    send_packet(1);
                } else if (packet[0] == 0xdede) {  // Master kettle boiling
                    simple_uart_putstring("Got invitation!\n");
                    packet[0] = 0xaf;  // Send ACK to Master
                    send_packet(1);    // ... 3 times ...
                    for (uint8_t i=0; i<100; i++){
                        nrf_gpio_pin_toggle(0);
                        nrf_delay_ms(200);
                    }
                } else {
                    sprintf((char*)buf, "Brocken command: %llx\n", packet[0]);
                    simple_uart_putstring(buf);
                }
            } else {
                simple_uart_putstring("Not applicable packet\n");
                sprintf((char*)buf, "Target:  %llx\n", packet[1]);
                simple_uart_putstring(buf);
                sprintf((char*)buf, "Command: %llx\n", packet[0]);
                simple_uart_putstring(buf);
            }
        }
    }
}
Exemple #17
0
int main(void)
{
    uint8_t err_code = NRF_SUCCESS;
    nrf_report_t report;
    btle_status_codes_t btle_err_code = BTLE_STATUS_CODE_SUCCESS;

    /* Silence the compiler */
    (void) g_sd_assert_pc;
    (void) g_evt;

    nrf_gpio_cfg_output (LED_0);
    nrf_gpio_cfg_output (LED_1);
    nrf_gpio_range_cfg_output (0, 7);

    nrf_gpio_pin_set (LED_0);

    simple_uart_config (RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC);

    __LOG("Program init", __FUNCTION__);

    err_code = sd_softdevice_enable ((uint32_t) NRF_CLOCK_LFCLKSRC_XTAL_75_PPM, sd_assert_cb);
    ASSERT (err_code == NRF_SUCCESS);
    __LOG ("Softdevice enabled");

    err_code = sd_nvic_EnableIRQ(SD_EVT_IRQn);
    ASSERT (err_code == NRF_SUCCESS);

    err_code = sd_nvic_SetPriority(SWI0_IRQn, NRF_APP_PRIORITY_LOW);
    ASSERT (err_code == NRF_SUCCESS);

    err_code = sd_nvic_EnableIRQ(SWI0_IRQn);
    ASSERT (err_code == NRF_SUCCESS);

    __LOG ("Interrupts enabled");

    btle_err_code = btle_scan_init (SWI0_IRQn);
    ASSERT (btle_err_code == BTLE_STATUS_CODE_SUCCESS);
    __LOG ("Scanner initialized");

    btle_err_code = btle_scan_param_set (scan_param);
    ASSERT (btle_err_code == BTLE_STATUS_CODE_SUCCESS);
    __LOG ("Scanner parameters set");

    btle_err_code = btle_scan_enable_set (scan_enable);
    ASSERT (btle_err_code == BTLE_STATUS_CODE_SUCCESS);
    __LOG ("Scanner enabled");

    //nrf_adv_conn_init ();

    while (true)
    {
        if (sw_interrupt)
        {
            while (btle_scan_ev_get (&report) != BTLE_STATUS_CODE_COMMAND_DISALLOWED)
            {
                __LOG("Type: %X, Addr: %X:%X:%X:%X:%X:%X, RSSI: %i",
                      report.event.params.le_advertising_report_event.event_type,
                      report.event.params.le_advertising_report_event.address[5],
                      report.event.params.le_advertising_report_event.address[4],
                      report.event.params.le_advertising_report_event.address[3],
                      report.event.params.le_advertising_report_event.address[2],
                      report.event.params.le_advertising_report_event.address[1],
                      report.event.params.le_advertising_report_event.address[0],
                      report.event.params.le_advertising_report_event.rssi);
            }

            __LOG("Done");

            sw_interrupt = false;
        }
    }
}
Exemple #18
0
/**
 * @brief Function for application main entry.
 */
int main(void)
{
		uint8_t data;
    bool who_am_i;
		bool init = true;
	
		nrf_gpio_cfg_output	(LED_0);
		nrf_gpio_cfg_output	(LED_1);
		nrf_gpio_pin_set(LED_0);
	
    simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC);
    simple_uart_putstring((const uint8_t *)" \r\nStart I2C \r\n");
		nrf_delay_ms(500);
		
		if(!twi_master_init()){
        while (true) 
        {
					nrf_gpio_pin_set(LED_0);
					nrf_delay_ms(500);
					nrf_gpio_pin_clear(LED_0);
					nrf_delay_ms(500);
        }
		}
		
		nrf_gpio_pin_set(LED_1);
		nrf_gpio_pin_clear(LED_0);

		who_am_i = read_register(MMA8452_ADDRESS << 1,WHO_AM_I,&data);
		
		
		if(who_am_i){							//data == 0x2A
			nrf_delay_us(100);
			write_register(MMA8452_ADDRESS << 1,XYZ_DATA_CFG, 0x02);
			nrf_delay_us(100);
			write_register(MMA8452_ADDRESS << 1,CTRL_REG1, 0x33);
			nrf_gpio_pin_clear(LED_1);
			nrf_gpio_pin_set(LED_0);
			char c[30];
			sprintf(c,"%d",data);
			simple_uart_putstring((const uint8_t *) "\r\n WHO_AM_I : ");
			simple_uart_putstring((const uint8_t *) c);
			data = '0';
			simple_uart_putstring((const uint8_t *) "\r\nMMA8452Q is online...");
		}
		else{
			nrf_gpio_pin_clear(LED_0);
			nrf_gpio_pin_clear(LED_1);
			simple_uart_putstring((const uint8_t *) "\r\nMMA8452Q is offline...");
		}
		
		short int x[3];


		while(1){
				readAccelData(x);
			
				float accelG[3];  // Stores the real accel value in g's
				
				for (int i = 0 ; i < 3 ; i++)
				{
//					accelG[i] = (float) x[i] / ((1<<12)/(2*GSCALE));  // get actual g value, this depends on scale being set
					accelG[i] = (float) x[i] / 256;  // get actual g value, this depends on scale being set
					accelG[i] *= 10;
				}
//				int a = accelG[1]*10;
//				int b = accelG[2]*10;
////				parse(a,b);
//			
				char c[30];
				sprintf(c,"%d",x[0]);
				simple_uart_putstring((const uint8_t *) "\r\n");
				simple_uart_putstring((const uint8_t *) c);
				sprintf(c,"%d",x[1]);
				simple_uart_putstring((const uint8_t *) "  ");
				simple_uart_putstring((const uint8_t *) c);
				sprintf(c,"%d",x[2]);
				simple_uart_putstring((const uint8_t *) "  ");
				simple_uart_putstring((const uint8_t *) c);
		}
}
void debug_init(void)
{
  simple_uart_config(RTS_PIN_NUMBER, TX_PIN_NUMBER, CTS_PIN_NUMBER, RX_PIN_NUMBER, HWFC);
}