diff --git a/application.c b/application.c index 050bd51..3446fff 100644 --- a/application.c +++ b/application.c @@ -55,6 +55,10 @@ static uint32_t boot_time = 0; #define SIGNAL_CHANNEL 2 /**< PA2/ADC1_IN2 used to measure signal voltage */ const uint8_t channels[] = {ADC_CHANNEL17, ADC_CHANNEL(TARGET_CHANNEL), ADC_CHANNEL(SIGNAL_CHANNEL)}; /**< voltages to convert (channel 17 = internal voltage reference) */ +#define SIGNAL_PD_PIN PA3 /**< pin to pull signal low for voltage measurement */ +#define SIGNAL_PU_PIN PA4 /**< pin to pull signal to target voltage (controlling gate of pMOS) */ +#define TARGET_EN PA5 /**< pin to provide target voltage to LV side of voltage shifter (pulling them high through 10 kO) */ + size_t putc(char c) { size_t length = 0; // number of characters printed @@ -563,6 +567,17 @@ void main(void) // important: do not re-enable backup_domain_write_protect, since this will prevent clearing flags (but RTC registers do not need to be unlocked) puts("OK\n"); + puts("setup voltage control: "); + rcc_periph_clock_enable(GPIO_RCC(SIGNAL_PD_PIN)); // enable clock for port domain + gpio_set(GPIO_PORT(SIGNAL_PD_PIN), GPIO_PIN(SIGNAL_PD_PIN)); // ensure we are not draining it + gpio_set_output_options(GPIO_PORT(SIGNAL_PD_PIN), GPIO_OTYPE_OD, GPIO_OSPEED_2MHZ, GPIO_PIN(SIGNAL_PD_PIN)); // set output as open-drain + gpio_mode_setup(GPIO_PORT(SIGNAL_PD_PIN), GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN(SIGNAL_PD_PIN)); // configure pin as output + rcc_periph_clock_enable(GPIO_RCC(SIGNAL_PU_PIN)); // enable clock for port domain + gpio_set(GPIO_PORT(SIGNAL_PU_PIN), GPIO_PIN(SIGNAL_PU_PIN)); // ensure we are not enable pMOS + gpio_set_output_options(GPIO_PORT(SIGNAL_PU_PIN), GPIO_OTYPE_OD, GPIO_OSPEED_2MHZ, GPIO_PIN(SIGNAL_PU_PIN)); // set output as open-drain + gpio_mode_setup(GPIO_PORT(SIGNAL_PU_PIN), GPIO_MODE_OUTPUT, GPIO_PUPD_NONE, GPIO_PIN(SIGNAL_PU_PIN)); // configure pin as output + puts("OK\n"); + puts("setup ADC to measure voltages: "); rcc_periph_clock_enable(RCC_ADC1); // enable clock for ADC domain adc_power_off(ADC1); // switch off ADC while configuring it