Skip to content

Commit

Permalink
More ADC fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
grudzinski committed Jan 15, 2025
1 parent 7d55cae commit f837e94
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions src/machine/machine_stm32_adc_f1.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,6 @@ func InitADC() {
// enable
stm32.ADC1.CR2.SetBits(stm32.ADC_CR2_ADON)

// 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

return
}

Expand All @@ -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) {
Expand All @@ -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
}

Expand Down

0 comments on commit f837e94

Please sign in to comment.