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
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
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:
Dear Stefan,
First of all , thank you very much four your support
When i try to transmit two byte that mentioned above, i get a zero value in adc_result[1] and the adc_result[0] contains a normal value.
Please i have another question, if i want to use two 10-bit ADC channels and send there values at same string but separated by comma "," how can i do this?
Thanks again for your valued advice
Best Regards
Hi ahmed
What voltage are you feeding to Analog input pin 2 (AIN2 or P0.01)? I suspect that you have low voltage on AIN2, then you will get low ADC output value and the last two bits will be zero, which are the two bits put into adc_result[1]
You can only send raw bytes over the air via the softdevice. If you want a specific format you need to apply that on the receiver side.
Hi Stefan,
The voltage on pin2 around 1.5 to 1.8 volt, i try to use potentiometer on the input but the value of adc_result[1] still 0.
The row data that can be sent over the air is it just numerical data or alphabetical data? because i need to separate between the two adc result, and the receiver side you mean ( PC application or BLE module), now the pc application that i programmed receive the adc result like this type "result 1,result 2" but via wire and i want to make it via Bluetooth.
Thank alot for your support
Best Regards
Thank alot my friend