From f7cfbbce2b94b5ac0094a0e34e1766fe1ceb12c8 Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 7 Apr 2012 20:35:17 -0700 Subject: [PATCH] altos: Show temperature in stm-demo Use the ADC to show current temperature Signed-off-by: Keith Packard --- src/stm-demo/ao_demo.c | 19 +++++++++++++++++++ src/stm-demo/ao_pins.h | 5 ++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/stm-demo/ao_demo.c b/src/stm-demo/ao_demo.c index 63647aac..ea4dadfa 100644 --- a/src/stm-demo/ao_demo.c +++ b/src/stm-demo/ao_demo.c @@ -111,10 +111,29 @@ ao_spi_read(void) { } } + + +static void +ao_temp (void) +{ + struct ao_adc adc; + int temp; + + ao_adc_get(&adc); + + /* + * r = (110 - 25) / (ts_cal_hot - ts_cal_cold) + * 25 + (110 - 25) * (temp - ts_cal_cold) / (ts_cal_hot - ts_cal_cold) + */ + temp = 25 + (110 - 25) * (adc.temp - stm_temp_cal.ts_cal_cold) / (stm_temp_cal.ts_cal_hot - stm_temp_cal.ts_cal_cold); + printf ("temp: %d\n", temp); +} + __code struct ao_cmds ao_demo_cmds[] = { { ao_dma_test, "D\0DMA test" }, { ao_spi_write, "W\0SPI write" }, { ao_spi_read, "R\0SPI read" }, + { ao_temp, "t\0Show temp" }, { 0, NULL } }; diff --git a/src/stm-demo/ao_pins.h b/src/stm-demo/ao_pins.h index fecd8cda..42f4123d 100644 --- a/src/stm-demo/ao_pins.h +++ b/src/stm-demo/ao_pins.h @@ -119,6 +119,7 @@ struct ao_adc { uint16_t tick; int16_t idd; int16_t temp; + int16_t vref; }; #define AO_ADC_IDD 4 @@ -127,13 +128,15 @@ struct ao_adc { #define AO_ADC_RCC_AHBENR ((1 << STM_RCC_AHBENR_GPIOAEN)) #define AO_ADC_TEMP 16 +#define AO_ADC_VREF 17 #define HAS_ADC_TEMP 1 -#define AO_NUM_ADC 2 +#define AO_NUM_ADC 3 #define AO_ADC_SQ1 AO_ADC_IDD #define AO_ADC_SQ2 AO_ADC_TEMP +#define AO_ADC_SQ3 AO_ADC_VREF #endif /* _AO_PINS_H_ */ -- 2.30.2