(void)err; chSysHalt("ADC error"); } /* * ADC conversion group. * Mode: Continuous, 1 sample of 1 channel, SW triggered. * Channels: IN3 */ static const ADCConversionGroup adcgrpcfg = { false, ADC_NUM_CHANNELS, adc_callback, adc_error_callback, ADC_CFGR_CONT | ADC_CFGR_RES_12BITS, /* CFGR */ ADC_TR(0, 4095), /* TR1 */ 0, /* CCR */ { /* SMPR[2] */ ADC_SMPR1_SMP_AN3(ADC_SMPR_SMP_601P5), 0 }, { /* SQR[4] */ ADC_SQR1_SQ1_N(ADC_CHANNEL_IN3), 0, 0, 0 } }; float bus_voltage_get(void) {
//BSEMAPHORE_DECL(adcSemDataReady, 0); #define ADC_GRP1_NUM_CHANNELS 1 #define ADC_GRP1_BUF_DEPTH 1 ADCConversionGroup adcSettings = { TRUE, ADCTEMPCHANNELS, adcCallBack, adcErrorCallBack, ADC_CFGR1_RES_12BIT, /* CFGRR1 */ ADC_TR(0, 0), /* TR */ ADC_SMPR_SMP_28P5, 0 /* CHSELR */ }; void adcCallBack(ADCDriver *adcp, adcsample_t *buffer, size_t n) { /* if (samples == buffer) { nx += n; } else {
// TS ADC raw data acquired at a temperature of 110 °C (± 5 °C), VDDA= 3.3 V (± 10 mV) #define TS_CAL2 (adcsample_t *)0x1FFFF7C2 #define ADC_RES 4096 #define ADC_NUM_CHANNELS 5 static adcsample_t samples[ADC_NUM_CHANNELS]; static ADCConfig adccfg = {0}; static ADCConversionGroup adcgrpcfg = { FALSE, ADC_NUM_CHANNELS, NULL, NULL, ADC_CFGR1_RES_12BIT, ADC_TR(0, 0), ADC_SMPR_SMP_239P5, ADC_CHSELR_CHSEL0 | ADC_CHSELR_CHSEL1 | ADC_CHSELR_CHSEL9 | \ ADC_CHSELR_CHSEL16 | ADC_CHSELR_CHSEL17 }; static float get_vdda_voltage(adcsample_t vrefint) { return 3.3 * *VREFINT_CAL / vrefint; } static float get_temp(adcsample_t ts_data) { return (110.0 - 30.0)/(*TS_CAL2 - *TS_CAL1) * (ts_data - *TS_CAL1) + 30; } adc_values_t readADC(void) { adc_values_t values;
*/ void adcerrorcallback(ADCDriver *adcp, adcerror_t err); /* * ADC conversion group 1. * Mode: One shot, 2 channels, SW triggered. * Channels: IN0, IN5. */ const ADCConversionGroup portab_adcgrpcfg1 = { .circular = false, .num_channels = ADC_GRP1_NUM_CHANNELS, .end_cb = NULL, .error_cb = adcerrorcallback, .cfgr = 0U, .cfgr2 = 0U, .tr1 = ADC_TR(0, 4095), .smpr = { ADC_SMPR1_SMP_AN0(ADC_SMPR_SMP_247P5) | ADC_SMPR1_SMP_AN5(ADC_SMPR_SMP_247P5), 0U }, .sqr = { ADC_SQR1_SQ1_N(ADC_CHANNEL_IN0) | ADC_SQR1_SQ2_N(ADC_CHANNEL_IN5), 0U, 0U, 0U } }; /* * ADC conversion group 2.
void adc_set_watchdog_low_threshold(uint32_t adc, uint8_t threshold) { ADC_TR(adc) = (ADC_TR(adc) & ~ADC_TR_LT) | ADC_TR_LT_VAL(threshold); }