regarding storage of values in last two bytes in an array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-12-01 2:54 AM
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?
- Labels:
-
ADC
-
STM32L0 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-12-01 4:02 AM
ATR[6] = (uint8_t) (adcval>>8); // msb
ATR[7] = (uint8_t) (adcval & 0x00FF); // lsb
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-12-01 4:53 AM
Thanks a lot :)
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-12-01 5:02 AM
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?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-12-01 5:02 AM
I want to readd the Vcc through the ADC pin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-12-01 6:26 AM
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-12-01 6:40 AM
Hi Peter> Thanks for the information. Could you show me how to calibrate it?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-12-01 6:54 AM
The ADC calibration is described in RM0377 under section 13.3.3, the example code can be found under A.8.1.
Regards
/Peter
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-12-01 7:04 AM
Hi Peter! Can't we do calibration by using HAL_library and get to know the VREFINT_CAL?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-12-01 8:10 AM
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
