1
\$\begingroup\$

I am piecing together my own ADC example for STM's blue-pill module by reading the reference manual (btw I an inexperienced in embedded development).

The code outline so far is:

void do_adc(void)
{
    unsigned int ra;
    ra=GET32(ADC_CR2);

    ra|=1;   // ADON
    PUT32(ADC_CR2, ra);

    // wait for EOC flag
    while ((GET32(ADC_SR) & 0x02) == 1)
    {
        led_blink();
    }

    ra = GET16(ADC_DR);

    PUT32(USART1_DR,ra);
    sleep();

    PUT32(USART1_DR,'\r');
    sleep();
    PUT32(USART1_DR,'\n');
    sleep();
}

int notmain(void)
{

    init_led_adc_and_uart();
    disable_adc();
    calibrate_adc();
    enable_adc();
    while (1)
    {
        led_blink();
        do_adc();
    }
}

I have written code for each of those functions which most probably is not correct, but that's not the question at the moment. I am still wondering where the Vref pin on the blue-pill; based on this diagram, is?

If my understanding is correct, then I would connect a temperature sensor to physical pin 10 (aka ADC channel 0), ensure that sensor has a voltage of ~3.3v. Then for reference, connect the same input somewhere on the blue-pill so it can do the conversion.

However based on the diagram I linked, I am not sure where the analog referene is?

Btw: I flashed my code onto the chip and the led continuously blinks, so the code is probably fine, but I need to workout the connections!

\$\endgroup\$
2
\$\begingroup\$

There isn't one in a 48 pin package, it's too small to have extra functions like that. Even the 64 pin doesn't have one, only when you get to 100 do they include the ref pins. enter image description here

They do have an internal reference, you'll have to configure it.

enter image description here
Sources: https://www.st.com/resource/en/datasheet/cd00161566.pdf

\$\endgroup\$
  • \$\begingroup\$ What would happen if I simply start a conversion without configuring this? I just tried that and the output in uart is an empty string. \$\endgroup\$ – Sam Hammamy Aug 7 '18 at 3:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.