cancel
Showing results for 
Search instead for 
Did you mean: 

Issue in sending ADC value over BLE(BlueNRG-LP)

Nikhil Gayke
Associate III

I am having STEVAL-IDB011V1 board. I am developing the battery profile for that i have refer the ADC_Battery_sensor and BLE_sensorDemo example but the code is stuck in below loop. Please let me know what is the issue in firmware. Is the issue is in ADC initialization. Please find the attached firmware link.

/**

 * @brief Disable the inversion of the ADC data output bits (1's complement)

 *     when a differential input is connected to the ADC

 * @rmtoll CONF   BIT_INVERT_DIFF   LL_ADC_InvertOutputBitDiffModeDisable

 * @param ADCx ADC instance

 * @retval None

 */

__STATIC_INLINE void LL_ADC_InvertOutputBitDiffModeDisable(ADC_TypeDef *ADCx)

{

 CLEAR_BIT(ADCx->CONF, ADC_CONF_BIT_INVERT_DIFF);

}

@Sebastien DENOUAL​ @Salvo​ @Salvatore DI SALVO​ @BlueNRG-LP Hands-On: Expanding Bluetooth​ @Sebastien DENOUAL​ 

https://drive.google.com/file/d/1Ijkz83Vn9KHylf9Kwu9mUnPLL7aWp-jZ/view?usp=sharing

1 ACCEPTED SOLUTION

Accepted Solutions
Sebastien DENOUAL
ST Employee

HI @Nikhil Gayke​ ,

I can confirm ADC code example you are using is running well on STEVAL_IDB011. Do you confirm the same ? I mean default ADC_Battery_sensor code example on STEVAL (before your merge into  BLE_sensorDemo)

In you code, I suppose during merge you missed something in your ADC init.

This function is pure ADC register read ( no loop). If you can't read a register, may be you didn't activate ADC correctly :

Please check :

  • ADC clock are activated, ADC is enabled,...

 /* Peripheral clock enable */

 LL_APB1_EnableClock(LL_APB1_PERIPH_ADCDIG | LL_APB1_PERIPH_ADCANA);

 /* This function must not be called on QFN32 package */

 LL_ADC_LDOEnable(ADC);

 /* Enable the ADC */

 LL_ADC_Enable(ADC);

[...]

Regards,

Sebastien

View solution in original post

6 REPLIES 6
Nikhil Gayke
Associate III

Hi @Sebastien DENOUAL​  please revert to this query

Sebastien DENOUAL
ST Employee

HI @Nikhil Gayke​ ,

I can confirm ADC code example you are using is running well on STEVAL_IDB011. Do you confirm the same ? I mean default ADC_Battery_sensor code example on STEVAL (before your merge into  BLE_sensorDemo)

In you code, I suppose during merge you missed something in your ADC init.

This function is pure ADC register read ( no loop). If you can't read a register, may be you didn't activate ADC correctly :

Please check :

  • ADC clock are activated, ADC is enabled,...

 /* Peripheral clock enable */

 LL_APB1_EnableClock(LL_APB1_PERIPH_ADCDIG | LL_APB1_PERIPH_ADCANA);

 /* This function must not be called on QFN32 package */

 LL_ADC_LDOEnable(ADC);

 /* Enable the ADC */

 LL_ADC_Enable(ADC);

[...]

Regards,

Sebastien

Nikhil Gayke
Associate III

Hi @Sebastien DENOUAL​ same code i have referred it is working fine but now i am getting garbage data over app.

Nikhil Gayke
Associate III

Hi @Sebastien DENOUAL​  do you have did any changes in firmware.

Nikhil Gayke
Associate III

 /* Parameters for ADC initialization */

 __HAL_RCC_ADCDIG_CLK_ENABLE();

 __HAL_RCC_ADCANA_CLK_ENABLE();

  

  /* Enable the ADC peripheral */

 HAL_ADC_StructInit(&hadc);

 hadc.Init.DataRatio = USER_RATIO;

 hadc.Init.DataWidth = USER_DATAWIDTH;

 hadc.Init.SampleRate = USER_SAMPLERATE;

  

 if (HAL_ADC_Init(&hadc) != HAL_OK) 

{

  

}

  

 /* Set the input channel */

 xChannel.ChannelType = ADC_CH_BATTERY_LEVEL_DETECTOR;

 xChannel.SequenceNumber = ADC_SEQ_POS_01;

 HAL_ADC_ConfigChannel(&hadc, &xChannel);

 /* Set the GAIN */

#if (USE_CALIBRATION==1)

 if(LL_ADC_GET_CALIB_GAIN_FOR_VINMX_3V6() != 0xFFF) {

  LL_ADC_SetCalibPoint1Gain(ADC, LL_ADC_GET_CALIB_GAIN_FOR_VINMX_3V6() );

  offset_vinm0 = LL_ADC_GET_CALIB_OFFSET_FOR_VINMX_3V6();

  if(offset_vinm0 < -64 || offset_vinm0 > 63) {

   LL_ADC_SetCalibPoint1Offset(ADC, 0);

  }

  else {

   LL_ADC_SetCalibPoint1Offset(ADC, offset_vinm0);

   offset_vinm0 = 0;

  }

 }

 else {

  LL_ADC_SetCalibPoint1Gain(ADC, LL_ADC_DEFAULT_RANGE_VALUE_3V6);

 }

#else

 LL_ADC_SetCalibPoint1Gain(ADC, LL_ADC_DEFAULT_RANGE_VALUE_3V6);

#endif

i have used above adc init function

@Salvatore DI SALVO​ @Salvo​ @Sebastien DENOUAL​ 

Sebastien DENOUAL
ST Employee

Hi @Nikhil Gayke​ ,

I'm using default code without modifications.

If it was OK and your side before and now it fails and you collect garbage value, I would advise to reinstall SDK in a different folder to check change you did. Looks to be easiest way.

Regards,

Sebastien.