diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-03-18 20:02:03 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-03-18 20:02:03 +0000 |
commit | 9388b24c161f037371ac11262301d030c07feafe (patch) | |
tree | 7547e59e36f4b9733fd174b29b0061e18bba4a97 /testhal/STM32F37x/ADC | |
parent | 8b4219aa883e47406c1134f8b10982393a99b61e (diff) | |
download | ChibiOS-9388b24c161f037371ac11262301d030c07feafe.tar.gz ChibiOS-9388b24c161f037371ac11262301d030c07feafe.tar.bz2 ChibiOS-9388b24c161f037371ac11262301d030c07feafe.zip |
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5452 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal/STM32F37x/ADC')
-rw-r--r-- | testhal/STM32F37x/ADC/main.c | 61 |
1 files changed, 28 insertions, 33 deletions
diff --git a/testhal/STM32F37x/ADC/main.c b/testhal/STM32F37x/ADC/main.c index c2e81b4c3..20e8ff8db 100644 --- a/testhal/STM32F37x/ADC/main.c +++ b/testhal/STM32F37x/ADC/main.c @@ -54,7 +54,7 @@ static void adcerrorcallback(ADCDriver *adcp, adcerror_t err) { /*
* ADC conversion group.
* Mode: Linear buffer, 8 samples of 2 channels, SW triggered.
- * Channels: IN7, IN8.
+ * Channels: IN1, IN9.
*/
static const ADCConversionGroup adcgrpcfg1 = {
FALSE,
@@ -63,51 +63,49 @@ static const ADCConversionGroup adcgrpcfg1 = { adcerrorcallback,
.u.adc = {
0, /* CR1 */
- 0, /* CR2 */
+ ADC_CR2_SWSTART, /* CR2 */
0, /* LTR */
- 4095, /* HTR */
+ 0, /* HTR */
{ /* SMPR[2] */
0,
- 0
+ ADC_SMPR2_SMP_AN9(ADC_SAMPLE_41P5) | ADC_SMPR2_SMP_AN1(ADC_SAMPLE_41P5),
},
{ /* SQR[3] */
0,
0,
- 0
+ ADC_SQR3_SQ2_N(ADC_CHANNEL_IN9) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN1)
}
}
};
-#if 0
/*
* ADC conversion group.
* Mode: Continuous, 16 samples of 8 channels, SW triggered.
- * Channels: IN7, IN8, IN7, IN8, IN7, IN8, Sensor, VBat/2.
+ * Channels: IN1, IN9, IN1, IN9, IN1, IN9, VBat, Sensor.
*/
static const ADCConversionGroup adcgrpcfg2 = {
TRUE,
ADC_GRP2_NUM_CHANNELS,
adccallback,
adcerrorcallback,
- 0, /* CFGR */
- ADC_TR(0, 4095), /* TR1 */
- ADC_CCR_TSEN | ADC_CCR_VBATEN, /* CCR */
- { /* SMPR[2] */
- ADC_SMPR1_SMP_AN7(ADC_SMPR_SMP_19P5)
- | ADC_SMPR1_SMP_AN8(ADC_SMPR_SMP_19P5),
- ADC_SMPR2_SMP_AN16(ADC_SMPR_SMP_61P5)
- | ADC_SMPR2_SMP_AN17(ADC_SMPR_SMP_61P5),
- },
- { /* SQR[4] */
- ADC_SQR1_SQ1_N(ADC_CHANNEL_IN7) | ADC_SQR1_SQ2_N(ADC_CHANNEL_IN8) |
- ADC_SQR1_SQ3_N(ADC_CHANNEL_IN7) | ADC_SQR1_SQ4_N(ADC_CHANNEL_IN8),
- ADC_SQR2_SQ5_N(ADC_CHANNEL_IN7) | ADC_SQR2_SQ6_N(ADC_CHANNEL_IN8) |
- ADC_SQR2_SQ7_N(ADC_CHANNEL_IN16) | ADC_SQR2_SQ8_N(ADC_CHANNEL_IN17),
- 0,
- 0
+ .u.adc = {
+ 0, /* CR1 */
+ ADC_CR2_SWSTART, /* CR2 */
+ 0, /* LTR */
+ 0, /* HTR */
+ { /* SMPR[2] */
+ ADC_SMPR1_SMP_SENSOR(ADC_SAMPLE_239P5) | ADC_SMPR1_SMP_VREF(ADC_SAMPLE_239P5),
+ ADC_SMPR2_SMP_AN9(ADC_SAMPLE_41P5) | ADC_SMPR2_SMP_AN1(ADC_SAMPLE_41P5)
+ },
+ { /* SQR[3] */
+ 0,
+ ADC_SQR2_SQ8_N(ADC_CHANNEL_SENSOR) | ADC_SQR2_SQ7_N(ADC_CHANNEL_VBAT),
+ ADC_SQR3_SQ6_N(ADC_CHANNEL_IN9) | ADC_SQR3_SQ5_N(ADC_CHANNEL_IN1) |
+ ADC_SQR3_SQ4_N(ADC_CHANNEL_IN9) | ADC_SQR3_SQ3_N(ADC_CHANNEL_IN1) |
+ ADC_SQR3_SQ2_N(ADC_CHANNEL_IN9) | ADC_SQR3_SQ1_N(ADC_CHANNEL_IN1)
+ }
}
};
-#endif
/*
* Red LEDs blinker thread, times are in milliseconds.
@@ -142,20 +140,17 @@ int main(void) { chSysInit();
/*
- * Setting up analog inputs used by the demo.
- */
- palSetGroupMode(GPIOC, PAL_PORT_BIT(1) | PAL_PORT_BIT(2),
- 0, PAL_MODE_INPUT_ANALOG);
-
- /*
* Creates the blinker thread.
*/
chThdCreateStatic(waThread1, sizeof(waThread1), NORMALPRIO, Thread1, NULL);
/*
- * Activates the ADC1 driver and the temperature sensor.
+ * Activates the ADC1 driver, the temperature sensor and the VBat
+ * measurement.
*/
adcStart(&ADCD1, NULL);
+ adcSTM32EnableTSVREFE();
+ adcSTM32EnableVBATE();
/*
* Linear conversion.
@@ -166,14 +161,14 @@ int main(void) { /*
* Starts an ADC continuous conversion.
*/
-// adcStartConversion(&ADCD1, &adcgrpcfg2, samples2, ADC_GRP2_BUF_DEPTH);
+ adcStartConversion(&ADCD1, &adcgrpcfg2, samples2, ADC_GRP2_BUF_DEPTH);
/*
* Normal main() thread activity, in this demo it does nothing.
*/
while (TRUE) {
if (palReadPad(GPIOA, GPIOA_WKUP_BUTTON)) {
-// adcStopConversion(&ADCD1);
+ adcStopConversion(&ADCD1);
}
chThdSleepMilliseconds(500);
}
|