Fix stm32f103 ADC (#4702)

fix: Fix stm32f103 ADC
This commit is contained in:
Roman Grudzinski
2025-01-16 12:06:22 +03:00
committed by GitHub
parent 5a1b885024
commit fd89e9b83a
3 changed files with 15 additions and 24 deletions
+1 -16
View File
@@ -23,15 +23,6 @@ func InitADC() {
// Enable ADC clock
enableAltFuncClock(unsafe.Pointer(stm32.ADC1))
// set scan mode
stm32.ADC1.CR1.SetBits(stm32.ADC_CR1_SCAN)
// clear CONT, ALIGN, EXTRIG and EXTSEL bits from CR2
stm32.ADC1.CR2.ClearBits(stm32.ADC_CR2_CONT | stm32.ADC_CR2_ALIGN | stm32.ADC_CR2_EXTTRIG_Msk | stm32.ADC_CR2_EXTSEL_Msk)
stm32.ADC1.SQR1.ClearBits(stm32.ADC_SQR1_L_Msk)
stm32.ADC1.SQR1.SetBits(2 << stm32.ADC_SQR1_L_Pos) // 2 means 3 conversions
// enable
stm32.ADC1.CR2.SetBits(stm32.ADC_CR2_ADON)
@@ -61,7 +52,7 @@ func (a ADC) Get() uint16 {
stm32.ADC1.SQR3.SetBits(ch)
// start conversion
stm32.ADC1.CR2.SetBits(stm32.ADC_CR2_SWSTART)
stm32.ADC1.CR2.SetBits(stm32.ADC_CR2_ADON)
// wait for conversion to complete
for !stm32.ADC1.SR.HasBits(stm32.ADC_SR_EOC) {
@@ -70,12 +61,6 @@ func (a ADC) Get() uint16 {
// read result as 16 bit value
result := uint16(stm32.ADC1.DR.Get()) << 4
// clear flag
stm32.ADC1.SR.ClearBits(stm32.ADC_SR_EOC)
// clear rank
stm32.ADC1.SQR3.ClearBits(ch)
return result
}