cancel
Showing results for 
Search instead for 
Did you mean: 

I-CUBE-LRWAN ADC reading not working

Nvan.9
Associate II

Hi,

I use the I-CUBE-LRWAN code in the B-L072Z-LRWAN1.

When I want to read an ADC channel I use to read pin PA5:

a = HW_AdcReadChannel(ADC_CHANNEL_5);

And to read ADC channel PA4 I use:

a = HW_AdcReadChannel(ADC_CHANNEL_4);

By using the mlm32l0xx_hw.c.

But for some reason only PA4 provides an correct ADC reading.

All my other pins don't show the correct reading.

Can anyone tell me how this is possible?

Thanks in advance.

2 REPLIES 2

>>Can anyone tell me how this is possible?

The implementation lacks completeness, or has dependencies you haven't addressed?

Check if the pins you want to use are connected to other thing internally to the Murata module, or externally on the DISCO board.

Check that the implementation for HW_AdcReadChannel() is complete, and allows for remapping of channels. Source code is provided you may need to do static analysis to determine the limitations and extensibility of the implementation as provided.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Nvan.9
Associate II

Nothing is internally/ externally connected on the DISCO board, this is a code thingy.

I just find it weird that STM provides in the I-CUBE a fully customized ADC reading function, but does only allow certain ADC channels to have proper readout. In any case I expect this to be reported in some comments.

For your info, if I would create my own code for ADC readings via DMA for example, than the rest of the I-CUBE system will start to behave improperly so I'm bound to this function.

I really believe this is a bug.

mlm32l0xx_hw.c

uint16_t HW_AdcReadChannel( uint32_t Channel )
{
 
  ADC_ChannelConfTypeDef adcConf;
  uint16_t adcData = 0;
  
  if( AdcInitialized == true )
  {
    /* wait the the Vrefint used by adc is set */
    while (__HAL_PWR_GET_FLAG(PWR_FLAG_VREFINTRDY) == RESET) {};
      
    ADCCLK_ENABLE();
    
    /*calibrate ADC if any calibraiton hardware*/
    HAL_ADCEx_Calibration_Start(&hadc, ADC_SINGLE_ENDED );
    
    /* Deselects all channels*/
    adcConf.Channel = ADC_CHANNEL_MASK;
    adcConf.Rank = ADC_RANK_NONE; 
    HAL_ADC_ConfigChannel( &hadc, &adcConf);
      
    /* configure adc channel */
    adcConf.Channel = Channel;
    adcConf.Rank = ADC_RANK_CHANNEL_NUMBER;
    HAL_ADC_ConfigChannel( &hadc, &adcConf);
 
    /* Start the conversion process */
    HAL_ADC_Start( &hadc);
      
    /* Wait for the end of conversion */
    HAL_ADC_PollForConversion( &hadc, HAL_MAX_DELAY );
      
    /* Get the converted value of regular channel */
    adcData = HAL_ADC_GetValue ( &hadc);
 
    __HAL_ADC_DISABLE( &hadc) ;
 
    ADCCLK_DISABLE();
  }
  return adcData;
}