简体   繁体   中英

VREF Output on STM32L0

I have an STM32L051 and want to drive an external DAC (SPI).

For that I would like to use the feature, mentioned in the manual , to output the internal reference voltage to the PB1 pin of the STM32.

I use the STM32Cube HAL as a basis. However the examples of using the VREF are limited to internal use for ADCs and comparators.

If I understand correctly, I can use the CFGR3 register to both enable the VREF as well as connect it to the PB1. Using the Cube drivers, I can use the HAL_SYSCFG_VREFINT_OutputSelect(SYSCFG_VREFINT_OUT_PB1) function, but to enable it, I should use either HAL_ADCEx_EnableVREFINT() or HAL_COMPEx_EnableVREFINT() . The manual information on SEL_VREF_OUT indicates that ENBUF_VREFINT_ADC must be set.

Furthermore no mention is made about the configuration of the pin itself. Should I simply declare it as a DAC Pin? An ADC Pin?

Answer

It is as simple as

if ( HALD_ADCEx_EnableVREFINT() != HAL_OK )
{
  Error_Handling();
}
HAL_SYSCFG_VREFINT_OutputSelect(SYSCFG_VREFINT_OUT_PB1);

And I can see the 1.22 V on the PB1 output.

It does not require further pin (GPIO) configuration.


Complications and justification for the question (can be skipped)

I had some issues with the board from out electronic dept. and thus switched to the STM32L053-Discovery board. The above solution did not work, and I kept seeing 0V on PB1 (or PB0).

I assumed that was due to some configuration missing. However, after some further tests, I actually found that on that Discovery board, both PB1 and PB0 are reserved for a sensor. By closing the SB23 bridge, I could use PB1 back to the GPIO, and thus see the reference voltage on the pin.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM