diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-03-30 09:12:52 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-03-30 09:12:52 +0000 |
commit | 320f18b7afb953a1447ea3e1b2246d5d1a842294 (patch) | |
tree | 9d53f5c2ae909e4e9e4c4e14298b556671ccf66e /testhal/STM32F37x | |
parent | 042c2ddba82250d60de4882ae7b0293666747d2d (diff) | |
download | ChibiOS-320f18b7afb953a1447ea3e1b2246d5d1a842294.tar.gz ChibiOS-320f18b7afb953a1447ea3e1b2246d5d1a842294.tar.bz2 ChibiOS-320f18b7afb953a1447ea3e1b2246d5d1a842294.zip |
STM32F37x SDADC driver working.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5519 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'testhal/STM32F37x')
-rw-r--r-- | testhal/STM32F37x/SDADC/main.c | 57 |
1 files changed, 26 insertions, 31 deletions
diff --git a/testhal/STM32F37x/SDADC/main.c b/testhal/STM32F37x/SDADC/main.c index 4b3e69df4..eb4790873 100644 --- a/testhal/STM32F37x/SDADC/main.c +++ b/testhal/STM32F37x/SDADC/main.c @@ -24,8 +24,8 @@ #define ADC_GRP1_NUM_CHANNELS 1
#define ADC_GRP1_BUF_DEPTH 8
-#define ADC_GRP2_NUM_CHANNELS 8
-#define ADC_GRP2_BUF_DEPTH 16
+#define ADC_GRP2_NUM_CHANNELS 1
+#define ADC_GRP2_BUF_DEPTH 32
static adcsample_t samples1[ADC_GRP1_NUM_CHANNELS * ADC_GRP1_BUF_DEPTH];
static adcsample_t samples2[ADC_GRP2_NUM_CHANNELS * ADC_GRP2_BUF_DEPTH];
@@ -52,6 +52,18 @@ static void adcerrorcallback(ADCDriver *adcp, adcerror_t err) { }
/*
+ * SDADC configuration.
+ */
+static const ADCConfig sdadc_config = {
+ 0,
+ {
+ SDADC_CONFR_GAIN_1X | SDADC_CONFR_SE_ZERO_VOLT | SDADC_CONFR_COMMON_VSSSD,
+ 0,
+ 0
+ }
+};
+
+/*
* ADC conversion group.
* Mode: Linear buffer, 8 samples of 1 channel, SW triggered.
* Channels: ADC_IN5P.
@@ -64,11 +76,6 @@ static const ADCConversionGroup adcgrpcfg1 = { .u.sdadc = {
SDADC_CR2_JSWSTART, /* CR2 */
SDADC_JCHGR_CH(5), /* JCHGR */
- { /* CONFxR[3]*/
- SDADC_CONFR_GAIN_1X | SDADC_CONFR_SE_DIFF | SDADC_CONFR_COMMON_VSSSD,
- 0,
- 0
- },
{ /* CONFCHR[2]*/
SDADC_CONFCHR1_CH5(0),
0
@@ -76,36 +83,25 @@ static const ADCConversionGroup adcgrpcfg1 = { }
};
-#if 0
/*
* ADC conversion group.
- * Mode: Continuous, 16 samples of 8 channels, SW triggered.
- * Channels: IN7, IN8, IN7, IN8, IN7, IN8, Sensor, VBat/2.
+ * Mode: Continuous, 32 samples of 1 channel, SW triggered.
+ * Channels: ADC_IN5P.
*/
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.sdadc = {
+ SDADC_CR2_JSWSTART, /* CR2 */
+ SDADC_JCHGR_CH(5), /* JCHGR */
+ { /* CONFCHR[2]*/
+ SDADC_CONFCHR1_CH5(0),
+ 0
+ }
}
};
-#endif
/*
* Red LEDs blinker thread, times are in milliseconds.
@@ -147,26 +143,25 @@ int main(void) { /*
* Activates the SDADC1 driver.
*/
- adcStart(&SDADCD1, NULL);
+ adcStart(&SDADCD1, &sdadc_config);
adcSTM32Calibrate(&SDADCD1);
/*
* Linear conversion.
*/
adcConvert(&SDADCD1, &adcgrpcfg1, samples1, ADC_GRP1_BUF_DEPTH);
- chThdSleepMilliseconds(1000);
/*
* Starts an ADC continuous conversion.
*/
-// adcStartConversion(&SDADC1, &adcgrpcfg2, samples2, ADC_GRP2_BUF_DEPTH);
+ adcStartConversion(&SDADCD1, &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(&SDADCD1);
+ adcStopConversion(&SDADCD1);
}
chThdSleepMilliseconds(500);
}
|