This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

How to configure "ble_nus_send_string" in nRF51822

Hi every body,

i try to use 10 bit ADC resolution instead of 8 bit in the ble_uard_adc example, the problem is the ble_nus_send_string is configure to 8 bit, how can i re-configure it to 16 bit to send a 10-bit ADC analog reading?

Thanks

Parents
  • Hi ahmed

    The input parameters in the ble_nus_send_string function include a length parameter and accept a pointer to data.

    To get 10-bit sampling, change the configuration to 10-bit

    //ADC initialization
    static void adc_init(void)
    {	
    	/* Enable interrupt on ADC sample ready event*/		
    	NRF_ADC->INTENSET = ADC_INTENSET_END_Msk;   
    	sd_nvic_SetPriority(ADC_IRQn, NRF_APP_PRIORITY_LOW);  
    	sd_nvic_EnableIRQ(ADC_IRQn);
    	
    	NRF_ADC->CONFIG	= (ADC_CONFIG_EXTREFSEL_None << ADC_CONFIG_EXTREFSEL_Pos) /* Bits 17..16 : ADC external reference pin selection. */
    									| (ADC_CONFIG_PSEL_AnalogInput2 << ADC_CONFIG_PSEL_Pos)					/*!< Use analog input 2 as analog input. */
    									| (ADC_CONFIG_REFSEL_VBG << ADC_CONFIG_REFSEL_Pos)							/*!< Use internal 1.2V bandgap voltage as reference for conversion. */
    									| (ADC_CONFIG_INPSEL_AnalogInputOneThirdPrescaling << ADC_CONFIG_INPSEL_Pos) /*!< Analog input specified by PSEL with no prescaling used as input for the conversion. */
    									| (ADC_CONFIG_RES_10bit << ADC_CONFIG_RES_Pos);									/*!< 8bit ADC resolution. */ 
    	
    	/* Enable ADC*/
    	NRF_ADC->ENABLE = ADC_ENABLE_ENABLE_Enabled;
    }
    

    So in order to transmit two bytes instead of one, you can do that as follows:

    /* Interrupt handler for ADC data ready event */
    void ADC_IRQHandler(void)
    {
    	uint8_t adc_result[2];
    	
    	/* Clear dataready event */
    	NRF_ADC->EVENTS_END = 0;	
    
    	/* Write ADC result both to the UART and over BLE */
    	adc_result[0] = NRF_ADC->RESULT;
    	adc_result[1] = NRF_ADC->RESULT >> 8;
    	app_uart_put(adc_result[0]);
    	app_uart_put(adc_result[1]);
    	ble_nus_send_string(&m_nus, adc_result, 2);
    	nrf_gpio_pin_toggle(LED_3);        //indicate on LED that the ADC interrupt handler is executing
    	
    	//Use the STOP task to save current. Workaround for PAN_028 rev1.5 anomaly 1.
    	NRF_ADC->TASKS_STOP = 1;
    	
    	//Release the external crystal
    	sd_clock_hfclk_release();
    }
    

    Update 7.5.2015 I include the code I have tested this with

    adc_example_with_softdevice_and_UART_send_two_bytes.zip

    The procedure:

    • Flash softdevice S110 7.1.0
    • Insert the above application into SDK 6.1.0, compile and flash
    • I used nRF51 DK but other dev kits can be used as well, i.e. nRF51 Dongle, nRF51422/nRF51822 development kit or nRF51422/nRF51822 evaluation kit
    • Connect with Master Control Panel, i.e. select the device (name:Nordic_UART), discover services, then enable services. You should see non zero values being notified. The image above shows the received value in Master Control Panel when the voltage is 2.0V on pin P0.01

    image description

Reply Children
No Data
Related