void adc1_2_isr(void)
{
    /* Clear Injected End Of Conversion (JEOC) */
    ADC_SR(ADC1) &= ~ADC_SR_JEOC;
    temperature = adc_read_injected(ADC1,1);
    v_refint = adc_read_injected(ADC1,2);
    lisam_adc1 = adc_read_injected(ADC1,3);
    lisam_adc2 = adc_read_injected(ADC1,4);
}
int main(void)
{
	uint8_t channel_array[16];
	uint16_t temperature = 0;

	rcc_clock_setup_in_hse_12mhz_out_72mhz();
	gpio_setup();
	usart_setup();
	timer_setup();
	adc_setup();

	gpio_set(GPIOA, GPIO8);	                /* LED1 on */
	gpio_set(GPIOC, GPIO15);		/* LED2 on */

	/* Send a message on USART1. */
	usart_send_blocking(USART2, 's');
	usart_send_blocking(USART2, 't');
	usart_send_blocking(USART2, 'm');
	usart_send_blocking(USART2, '\r');
	usart_send_blocking(USART2, '\n');

	/* Select the channel we want to convert. 16=temperature_sensor. */
	channel_array[0] = 16;
	/* Set the injected sequence here, with number of channels */
	adc_set_injected_sequence(ADC1, 1, channel_array);

	/* Continously convert and poll the temperature ADC. */
	while (1) {
		/*
		 * Since the injected sampling is triggered by the timer, it gets
		 * updated automatically, we just need to periodically read out the value.
		 * It would be better to check if the JEOC bit is set, and clear it following
		 * so that you do not read the same value twice, especially for a slower
		 * sampling rate.
		 */

		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
		 * as described in the datasheet.
		 */
		my_usart_print_int(USART2, temperature);

		gpio_toggle(GPIOA, GPIO8); /* LED2 on */

	}

	return 0;
}
Example #3
0
  void adc_isr(void)
#endif
{
  uint8_t channel = 0;
  uint16_t value  = 0;
  struct adc_buf * buf;

#if USE_ADC_WATCHDOG
  /*
    We need adc sampling fast enough to detect battery plug out, but we did not
    need to get actual actual value so fast. So timer fire adc conversion fast,
    at least 500 hz, but we inject adc value in sampling buffer only at 50hz
   */
  const uint32_t timeStampDiff = get_sys_time_msec() - adc_watchdog.timeStamp;
  const bool_t shouldAccumulateValue = timeStampDiff > 20;
  if (shouldAccumulateValue)
    adc_watchdog.timeStamp = get_sys_time_msec();

  if (adc_watchdog.cb != NULL) {
    if (adc_awd(adc_watchdog.adc)) {
      ADC_SR(adc_watchdog.adc) &= ~ADC_SR_AWD; // clear int flag
      adc_watchdog.cb();
    }
  }
#endif

#if USE_AD1
  // Clear Injected End Of Conversion
  if (adc_eoc_injected(ADC1)){
    ADC_SR(ADC1) &= ~ADC_SR_JEOC;
#if USE_ADC_WATCHDOG
    if (shouldAccumulateValue) {
#endif
    for (channel = 0; channel < nb_adc1_channels; channel++) {
      buf = adc1_buffers[channel];
      if (buf) {
        value = adc_read_injected(ADC1, channel+1);
        adc_push_sample(buf, value);
      }
    }
#if USE_ADC_WATCHDOG
  }
#endif

#if !USE_AD2 && !USE_AD3
    adc_new_data_trigger = TRUE;
#endif
  }
#endif
#if USE_AD2
  if (adc_eoc_injected(ADC2)){
    ADC_SR(ADC2) &= ~ADC_SR_JEOC;
#if USE_ADC_WATCHDOG
    if (shouldAccumulateValue) {
#endif
    for (channel = 0; channel < nb_adc2_channels; channel++) {
      buf = adc2_buffers[channel];
      if (buf) {
        value = adc_read_injected(ADC2, channel+1);
        adc_push_sample(buf, value);
      }
    }
#if USE_ADC_WATCHDOG
  }
#endif
#if !USE_AD3
    adc_new_data_trigger = TRUE;
#endif
  }
#endif
#if USE_AD3
  if (adc_eoc_injected(ADC3)){
    ADC_SR(ADC3) &= ~ADC_SR_JEOC;
#if USE_ADC_WATCHDOG
    if (shouldAccumulateValue) {
#endif
    for (channel = 0; channel < nb_adc3_channels; channel++) {
      buf = adc3_buffers[channel];
      if (buf) {
        value = adc_read_injected(ADC3, channel+1);
        adc_push_sample(buf, value);
      }
    }
#if USE_ADC_WATCHDOG
  }
#endif
    adc_new_data_trigger = TRUE;
  }
#endif


  return;
}
void adc1_2_isr(void)
{
    /* Clear Injected End Of Conversion (JEOC) */
    ADC_SR(ADC1) &= ~ADC_SR_JEOC;
    temperature = adc_read_injected(ADC1,1);
}