summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDamien George <damien.p.george@gmail.com>2018-09-20 23:50:54 +1000
committerDamien George <damien.p.george@gmail.com>2018-09-20 23:50:54 +1000
commit3220cedc31f2ce161286baf58cfdfd396697348a (patch)
tree28650bf995d2b7f91699f45c5164c33b98c77034
parent9849209ad8514ba19ca1c50ebab2d23b155c93ba (diff)
stm32/adc: Fix ADC calibration scale for L4 MCUs, they use 3.0V.
-rw-r--r--ports/stm32/adc.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/ports/stm32/adc.c b/ports/stm32/adc.c
index 583108feb..c20e1bca4 100644
--- a/ports/stm32/adc.c
+++ b/ports/stm32/adc.c
@@ -63,6 +63,7 @@
#define ADC_FIRST_GPIO_CHANNEL (0)
#define ADC_LAST_GPIO_CHANNEL (15)
+#define ADC_SCALE_V (3.3f)
#define ADC_CAL_ADDRESS (0x1ffff7ba)
#define ADC_CAL1 ((uint16_t*)0x1ffff7b8)
#define ADC_CAL2 ((uint16_t*)0x1ffff7c2)
@@ -71,6 +72,7 @@
#define ADC_FIRST_GPIO_CHANNEL (0)
#define ADC_LAST_GPIO_CHANNEL (15)
+#define ADC_SCALE_V (3.3f)
#define ADC_CAL_ADDRESS (0x1fff7a2a)
#define ADC_CAL1 ((uint16_t*)(ADC_CAL_ADDRESS + 2))
#define ADC_CAL2 ((uint16_t*)(ADC_CAL_ADDRESS + 4))
@@ -79,6 +81,7 @@
#define ADC_FIRST_GPIO_CHANNEL (0)
#define ADC_LAST_GPIO_CHANNEL (15)
+#define ADC_SCALE_V (3.3f)
#if defined(STM32F722xx) || defined(STM32F723xx) || \
defined(STM32F732xx) || defined(STM32F733xx)
#define ADC_CAL_ADDRESS (0x1ff07a2a)
@@ -93,6 +96,7 @@
#define ADC_FIRST_GPIO_CHANNEL (0)
#define ADC_LAST_GPIO_CHANNEL (16)
+#define ADC_SCALE_V (3.3f)
#define ADC_CAL_ADDRESS (0x1FF1E860)
#define ADC_CAL1 ((uint16_t*)(0x1FF1E820))
#define ADC_CAL2 ((uint16_t*)(0x1FF1E840))
@@ -102,6 +106,7 @@
#define ADC_FIRST_GPIO_CHANNEL (1)
#define ADC_LAST_GPIO_CHANNEL (16)
+#define ADC_SCALE_V (3.0f)
#define ADC_CAL_ADDRESS (0x1fff75aa)
#define ADC_CAL1 ((uint16_t*)(ADC_CAL_ADDRESS - 2))
#define ADC_CAL2 ((uint16_t*)(ADC_CAL_ADDRESS + 0x20))
@@ -144,7 +149,7 @@
#define CORE_TEMP_AVG_SLOPE (3) /* (2.5mv/3.3v)*(2^ADC resoultion) */
// scale and calibration values for VBAT and VREF
-#define ADC_SCALE (3.3f / 4095)
+#define ADC_SCALE (ADC_SCALE_V / 4095)
#define VREFIN_CAL ((uint16_t *)ADC_CAL_ADDRESS)
typedef struct _pyb_obj_adc_t {
@@ -791,7 +796,7 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_core_vref_obj, adc_all_read_core_v
STATIC mp_obj_t adc_all_read_vref(mp_obj_t self_in) {
pyb_adc_all_obj_t *self = MP_OBJ_TO_PTR(self_in);
adc_read_core_vref(&self->handle);
- return mp_obj_new_float(3.3 * adc_refcor);
+ return mp_obj_new_float(ADC_SCALE_V * adc_refcor);
}
STATIC MP_DEFINE_CONST_FUN_OBJ_1(adc_all_read_vref_obj, adc_all_read_vref);
#endif