cancel
Showing results for 
Search instead for 
Did you mean: 

regarding storage of values in last two bytes in an array

RWagh.2
Associate II

Hello Folks,

I have connected my STML011G4U7 with ISO7816. In my code I am parsing ATR which is an 8 byte array and sending it. Here I need to measure the voltage from ADC which would be (3.3 V) and store it in the last two bytes of an array. How will I do that?

byte ATR[] = { 0x3B, 0x06, 0x55, 0x63, 0x63, 0x3D, 0x00, 0x00 };

I need to store the value coming from ADC in the last two bytes ADCH and ADCL. How will I do that?

19 REPLIES 19
S.Ma
Principal

ATR[6] = (uint8_t) (adcval>>8); // msb

ATR[7] = (uint8_t) (adcval & 0x00FF); // lsb

Thanks a lot 🙂

I just read the value from ADC where I am giving 3.3V but the value I am getting is !.08V somewhere. What could be the problem?

I want to readd the Vcc through the ADC pin

The ADC can only measure voltages that are between GND and VDDA, because in STM32L011 VREF+ is internally hardwired to VDDA.

To measure a voltage absolutely you would have to perform a rational measurement, i.e. measurement of Vrefint and measurement of the voltage at the ADC input. The ratio between the two can then be used to calculate the input voltage.

However, since VREF+ is fixed to VDD, you will always measure the same thing at the ADC input, since the reference voltage changes at the same rate as the voltage to be measured.

In your specific case you can measure Vrefint (don't forget to calibrate) and convert the measurement result to VDD. The RM0377 describes in section 13.9 and section Converting a supply-relative ADC measurement to an absolute voltage value, how to calculate this.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi Peter> Thanks for the information. Could you show me how to calibrate it?

The ADC calibration is described in RM0377 under section 13.3.3, the example code can be found under A.8.1.

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Hi Peter! Can't we do calibration by using HAL_library and get to know the VREFINT_CAL?

Yes, of course. You can find examples in the repository in stm32l0xx_hal_adc_ex.c, calling HAL_ADCEx_Calibration_Start, e.g.:

/* Run the ADC calibration in single-ended mode */  
if (HAL_ADCEx_Calibration_Start(&AdcHandle, ADC_SINGLE_ENDED) != HAL_OK)
{
  /* Calibration Error */
  Error_Handler();
}

and you can access the value for VREFINT_CAL of the STM32L011 e.g. like this:

#define VREFINT_CAL ((uint16_t*) ((uint32_t) 0x1FF80078))

Regards

/Peter

In order to give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.