mirror of
https://github.com/tinygo-org/tinygo.git
synced 2026-08-16 02:33:28 +00:00
Fix ADC channel selecting and ADC value reading
This commit is contained in:
committed by
Ron Evans
parent
fd89e9b83a
commit
127557d27e
@@ -24,7 +24,7 @@ func InitADC() {
|
|||||||
enableAltFuncClock(unsafe.Pointer(stm32.ADC1))
|
enableAltFuncClock(unsafe.Pointer(stm32.ADC1))
|
||||||
|
|
||||||
// enable
|
// enable
|
||||||
stm32.ADC1.CR2.SetBits(stm32.ADC_CR2_ADON)
|
stm32.ADC1.CR2.SetBits(stm32.ADC_CR2_ADON | stm32.ADC_CR2_ALIGN)
|
||||||
|
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -49,7 +49,7 @@ func (a ADC) Configure(ADCConfig) {
|
|||||||
func (a ADC) Get() uint16 {
|
func (a ADC) Get() uint16 {
|
||||||
// set rank
|
// set rank
|
||||||
ch := uint32(a.getChannel())
|
ch := uint32(a.getChannel())
|
||||||
stm32.ADC1.SQR3.SetBits(ch)
|
stm32.ADC1.SetSQR3_SQ1(ch)
|
||||||
|
|
||||||
// start conversion
|
// start conversion
|
||||||
stm32.ADC1.CR2.SetBits(stm32.ADC_CR2_ADON)
|
stm32.ADC1.CR2.SetBits(stm32.ADC_CR2_ADON)
|
||||||
@@ -59,9 +59,7 @@ func (a ADC) Get() uint16 {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// read result as 16 bit value
|
// read result as 16 bit value
|
||||||
result := uint16(stm32.ADC1.DR.Get()) << 4
|
return uint16(stm32.ADC1.DR.Get())
|
||||||
|
|
||||||
return result
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a ADC) getChannel() uint8 {
|
func (a ADC) getChannel() uint8 {
|
||||||
|
|||||||
Reference in New Issue
Block a user