Code changes to stm32f1 adc.c and adc.h

remove rcc_set_adc_clk - use rcc version
Added functions:
 - adc_power_on
 - adc_start_conversion_direct
 - adc_set_dual_mode
 - adc_eoc
 - adc_eoc_injected
 - adc_read_regular
 - adc_read_injected
 - adc_set_injected_offset
Tested dual mode scanned regular, but no tests of injected yet.
Changes: "discontinuous" was misspelled.
 - adc_set_discontinuous_mode_regular - added "length" parameter
 - adc_disable_discontinuous_mode_regular - name change
 - adc_enable_discontinuous_mode_injected - name change
 - adc_enable_automatic_injected_group_conversion - disable triggers
 - adc_enable_jeoc_interrupt - name change to match common usage in lib
 - adc_disable_jeoc_interrupt - ditto
 - adc_enable_external_trigger_regular - remove incorrect test on parameter
 - adc_enable_external_trigger_injected - ditto
 - adc_set_sample_time - name change to match function's purpose
 - adc_set_conversion_time_on_all_channels - ditto
 - adc_set_injected_sequence - changed order of register loading (ref Barlow's issue)
 - adc_enable_analog_watchdog_on_all_channels - flipped AWDSGL
 - adc_enable_analog_watchdog_on_selected_channel - ditto
added aliases for expected commonly used functions to avoid sudden user code breakage

In adc.h, corrected errors in SQR names
added "deprecated" compiler warnings to adc_on and to aliases defined in adc.c
This commit is contained in:
Ken Sarkies
2012-10-05 13:50:42 +09:30
parent ecb0cbbf78
commit 7d0611609b
4 changed files with 224 additions and 94 deletions

View File

@@ -3,6 +3,7 @@
*
* Copyright (C) 2010 Thomas Otto <tommi@viadmin.org>
* Copyright (C) 2012 Piotr Esden-Tempski <piotr@esden.net>
* Copyright (C) 2012 Ken Sarkies <ksarkies@internode.on.net>
*
* This library is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
@@ -71,14 +72,13 @@ void adc_setup(void)
/* We configure everything for one single conversion. */
adc_disable_scan_mode(ADC1);
adc_set_single_conversion_mode(ADC1);
adc_enable_discontinous_mode_regular(ADC1);
adc_disable_external_trigger_regular(ADC1);
adc_set_right_aligned(ADC1);
/* We want to read the temperature sensor, so we have to enable it. */
adc_enable_temperature_sensor(ADC1);
adc_set_conversion_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC);
adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC);
adc_on(ADC1);
adc_power_on(ADC1);
/* Wait for ADC starting up. */
for (i = 0; i < 800000; i++) /* Wait a bit. */
@@ -138,10 +138,9 @@ int main(void)
/* Continously convert and poll the temperature ADC. */
while (1) {
/*
* If the ADC_CR2_ON bit is already set -> setting it another time
* starts the conversion.
* Start the conversion directly (ie without a trigger).
*/
adc_on(ADC1);
adc_start_conversion_direct(ADC1);
/* Wait for end of conversion. */
while (!(ADC_SR(ADC1) & ADC_SR_EOC));

View File

@@ -69,14 +69,13 @@ void adc_setup(void)
/* We configure everything for one single conversion. */
adc_disable_scan_mode(ADC1);
adc_set_single_conversion_mode(ADC1);
adc_enable_discontinous_mode_regular(ADC1);
adc_disable_external_trigger_regular(ADC1);
adc_set_right_aligned(ADC1);
/* We want to read the temperature sensor, so we have to enable it. */
adc_enable_temperature_sensor(ADC1);
adc_set_conversion_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC);
adc_set_sample_time_on_all_channels(ADC1, ADC_SMPR_SMP_28DOT5CYC);
adc_on(ADC1);
adc_power_on(ADC1);
/* Wait for ADC starting up. */
for (i = 0; i < 800000; i++) /* Wait a bit. */
@@ -131,10 +130,9 @@ int main(void)
adc_set_regular_sequence(ADC1, 1, channel_array);
/*
* If the ADC_CR2_ON bit is already set -> setting it another time
* starts the conversion.
* Start the conversion directly (not trigger mode).
*/
adc_on(ADC1);
adc_start_conversion_direct(ADC1);
/* Wait for end of conversion. */
while (!(ADC_SR(ADC1) & ADC_SR_EOC));