Skip to content

Commit

Permalink
Fix ADC channel selecting and ADC value reading
Browse files Browse the repository at this point in the history
  • Loading branch information
grudzinski committed Jan 16, 2025
1 parent fd89e9b commit fcd2534
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions src/machine/machine_stm32_adc_f1.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func InitADC() {
enableAltFuncClock(unsafe.Pointer(stm32.ADC1))

// enable
stm32.ADC1.CR2.SetBits(stm32.ADC_CR2_ADON)
stm32.ADC1.CR2.SetBits(stm32.ADC_CR2_ADON | stm32.ADC_CR2_ALIGN)

return
}
Expand All @@ -49,7 +49,7 @@ func (a ADC) Configure(ADCConfig) {
func (a ADC) Get() uint16 {
// set rank
ch := uint32(a.getChannel())
stm32.ADC1.SQR3.SetBits(ch)
stm32.ADC1.SetSQR3_SQ1(ch)

// start conversion
stm32.ADC1.CR2.SetBits(stm32.ADC_CR2_ADON)
Expand All @@ -59,9 +59,7 @@ func (a ADC) Get() uint16 {
}

// read result as 16 bit value
result := uint16(stm32.ADC1.DR.Get()) << 4

return result
return uint16(stm32.ADC1.DR.Get())
}

func (a ADC) getChannel() uint8 {
Expand Down

0 comments on commit fcd2534

Please sign in to comment.