Browse Source

updated the lisa_m_2 (STM32 F1) ADC examples for recent code changes to stm32f1 adc.c and adc.h

pull/40/head
Stephen Dwyer 12 years ago
parent
commit
2b8fbfc433
  1. 12
      examples/stm32/f1/lisa-m-2/adc_injec/adc_injec.c
  2. 10
      examples/stm32/f1/lisa-m-2/adc_injec_timtrig/adc_injec_timtrig.c
  3. 8
      examples/stm32/f1/lisa-m-2/adc_injec_timtrig_irq/adc_injec_timtrig_irq.c
  4. 14
      examples/stm32/f1/lisa-m-2/adc_injec_timtrig_irq_4ch/adc_injec_timtrig_irq_4ch.c
  5. 4
      examples/stm32/f1/lisa-m-2/adc_regular/adc.c

12
examples/stm32/f1/lisa-m-2/adc_injec/adc_injec.c

@ -73,16 +73,16 @@ void adc_setup(void)
adc_disable_scan_mode(ADC1); adc_disable_scan_mode(ADC1);
adc_set_single_conversion_mode(ADC1); adc_set_single_conversion_mode(ADC1);
/* We can only use discontinuous mode on either the regular OR injected channels, not both */ /* We can only use discontinuous mode on either the regular OR injected channels, not both */
adc_disable_discontinous_mode_regular(ADC1); adc_disable_discontinuous_mode_regular(ADC1);
adc_enable_discontinous_mode_injected(ADC1); adc_enable_discontinuous_mode_injected(ADC1);
/* We want to start the injected conversion in software */ /* We want to start the injected conversion in software */
adc_enable_external_trigger_injected(ADC1,ADC_CR2_JEXTSEL_JSWSTART); adc_enable_external_trigger_injected(ADC1,ADC_CR2_JEXTSEL_JSWSTART);
adc_set_right_aligned(ADC1); adc_set_right_aligned(ADC1);
/* We want to read the temperature sensor, so we have to enable it. */ /* We want to read the temperature sensor, so we have to enable it. */
adc_enable_temperature_sensor(ADC1); 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. */ /* Wait for ADC starting up. */
for (i = 0; i < 800000; i++) /* Wait a bit. */ for (i = 0; i < 800000; i++) /* Wait a bit. */
@ -155,10 +155,10 @@ int main(void)
adc_start_conversion_injected(ADC1); adc_start_conversion_injected(ADC1);
/* Wait for end of conversion. */ /* Wait for end of conversion. */
while (!(ADC_SR(ADC1) & ADC_SR_JEOC)); while (!(adc_eoc_injected(ADC1)));
ADC_SR(ADC2) &= ~ADC_SR_JEOC; //clear injected end of conversion ADC_SR(ADC2) &= ~ADC_SR_JEOC; //clear injected end of conversion
temperature = ADC_JDR1(ADC1); //get the result from ADC_JDR1 on ADC1 (only bottom 16bits) temperature = adc_read_injected(ADC1,1); //get the result from ADC_JDR1 on ADC1 (only bottom 16bits)
/* /*
* That's actually not the real temperature - you have to compute it * That's actually not the real temperature - you have to compute it

10
examples/stm32/f1/lisa-m-2/adc_injec_timtrig/adc_injec_timtrig.c

@ -99,16 +99,16 @@ void adc_setup(void)
adc_disable_scan_mode(ADC1); adc_disable_scan_mode(ADC1);
adc_set_single_conversion_mode(ADC1); adc_set_single_conversion_mode(ADC1);
/* We can only use discontinuous mode on either the regular OR injected channels, not both */ /* We can only use discontinuous mode on either the regular OR injected channels, not both */
adc_disable_discontinous_mode_regular(ADC1); adc_disable_discontinuous_mode_regular(ADC1);
adc_enable_discontinous_mode_injected(ADC1); adc_enable_discontinuous_mode_injected(ADC1);
/* We want to start the injected conversion with the TIM2 TRGO */ /* We want to start the injected conversion with the TIM2 TRGO */
adc_enable_external_trigger_injected(ADC1,ADC_CR2_JEXTSEL_TIM2_TRGO); adc_enable_external_trigger_injected(ADC1,ADC_CR2_JEXTSEL_TIM2_TRGO);
adc_set_right_aligned(ADC1); adc_set_right_aligned(ADC1);
/* We want to read the temperature sensor, so we have to enable it. */ /* We want to read the temperature sensor, so we have to enable it. */
adc_enable_temperature_sensor(ADC1); 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. */ /* Wait for ADC starting up. */
for (i = 0; i < 800000; i++) /* Wait a bit. */ for (i = 0; i < 800000; i++) /* Wait a bit. */
@ -179,7 +179,7 @@ int main(void)
* sampling rate. * sampling rate.
*/ */
temperature = ADC_JDR1(ADC1); //get the result from ADC_JDR1 on ADC1 (only bottom 16bits) temperature = adc_read_injected(ADC1,1); //get the result from ADC_JDR1 on ADC1 (only bottom 16bits)
/* /*
* That's actually not the real temperature - you have to compute it * That's actually not the real temperature - you have to compute it

8
examples/stm32/f1/lisa-m-2/adc_injec_timtrig_irq/adc_injec_timtrig_irq.c

@ -114,13 +114,13 @@ void adc_setup(void)
/* We want to start the injected conversion with the TIM2 TRGO */ /* We want to start the injected conversion with the TIM2 TRGO */
adc_enable_external_trigger_injected(ADC1,ADC_CR2_JEXTSEL_TIM2_TRGO); adc_enable_external_trigger_injected(ADC1,ADC_CR2_JEXTSEL_TIM2_TRGO);
/* Generate the ADC1_2_IRQ */ /* Generate the ADC1_2_IRQ */
adc_enable_jeoc_interrupt(ADC1); adc_enable_eoc_interrupt_injected(ADC1);
adc_set_right_aligned(ADC1); adc_set_right_aligned(ADC1);
/* We want to read the temperature sensor, so we have to enable it. */ /* We want to read the temperature sensor, so we have to enable it. */
adc_enable_temperature_sensor(ADC1); 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. */ /* Wait for ADC starting up. */
for (i = 0; i < 800000; i++) /* Wait a bit. */ for (i = 0; i < 800000; i++) /* Wait a bit. */
@ -207,5 +207,5 @@ void adc1_2_isr(void)
{ {
/* Clear Injected End Of Conversion (JEOC) */ /* Clear Injected End Of Conversion (JEOC) */
ADC_SR(ADC1) &= ~ADC_SR_JEOC; ADC_SR(ADC1) &= ~ADC_SR_JEOC;
temperature = ADC_JDR1(ADC1); temperature = adc_read_injected(ADC1,1);
} }

14
examples/stm32/f1/lisa-m-2/adc_injec_timtrig_irq_4ch/adc_injec_timtrig_irq_4ch.c

@ -122,11 +122,11 @@ void adc_setup(void)
/* We want to start the injected conversion with the TIM2 TRGO */ /* We want to start the injected conversion with the TIM2 TRGO */
adc_enable_external_trigger_injected(ADC1,ADC_CR2_JEXTSEL_TIM2_TRGO); adc_enable_external_trigger_injected(ADC1,ADC_CR2_JEXTSEL_TIM2_TRGO);
/* Generate the ADC1_2_IRQ */ /* Generate the ADC1_2_IRQ */
adc_enable_jeoc_interrupt(ADC1); adc_enable_eoc_interrupt_injected(ADC1);
adc_set_right_aligned(ADC1); adc_set_right_aligned(ADC1);
/* We want to read the temperature sensor, so we have to enable it. */ /* We want to read the temperature sensor, so we have to enable it. */
adc_enable_temperature_sensor(ADC1); 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);
/* Select the channels we want to convert. /* Select the channels we want to convert.
* 16=temperature_sensor, 17=Vrefint, 13=ADC1, 10=ADC2 * 16=temperature_sensor, 17=Vrefint, 13=ADC1, 10=ADC2
@ -137,7 +137,7 @@ void adc_setup(void)
channel_array[3] = 10; channel_array[3] = 10;
adc_set_injected_sequence(ADC1, 4, channel_array); adc_set_injected_sequence(ADC1, 4, channel_array);
adc_on(ADC1); adc_power_on(ADC1);
/* Wait for ADC starting up. */ /* Wait for ADC starting up. */
for (i = 0; i < 800000; i++) /* Wait a bit. */ for (i = 0; i < 800000; i++) /* Wait a bit. */
@ -223,8 +223,8 @@ void adc1_2_isr(void)
{ {
/* Clear Injected End Of Conversion (JEOC) */ /* Clear Injected End Of Conversion (JEOC) */
ADC_SR(ADC1) &= ~ADC_SR_JEOC; ADC_SR(ADC1) &= ~ADC_SR_JEOC;
temperature = ADC_JDR1(ADC1); temperature = adc_read_injected(ADC1,1);
v_refint = ADC_JDR2(ADC1); v_refint = adc_read_injected(ADC1,2);
lisam_adc1 = ADC_JDR3(ADC1); lisam_adc1 = adc_read_injected(ADC1,3);
lisam_adc2 = ADC_JDR4(ADC1); lisam_adc2 = adc_read_injected(ADC1,4);
} }

4
examples/stm32/f1/lisa-m-2/adc_regular/adc.c

@ -143,9 +143,9 @@ int main(void)
adc_start_conversion_direct(ADC1); adc_start_conversion_direct(ADC1);
/* Wait for end of conversion. */ /* Wait for end of conversion. */
while (!(ADC_SR(ADC1) & ADC_SR_EOC)); while (!(adc_eoc(ADC1)));
temperature = ADC_DR(ADC1); temperature = adc_read_regular(ADC1);
/* /*
* That's actually not the real temperature - you have to compute it * That's actually not the real temperature - you have to compute it

Loading…
Cancel
Save