Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stm32: Fix ADC channel selecting and ADC value reading #4703

Conversation

grudzinski
Copy link

No description provided.

@@ -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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ADC can ALIGN left as we did in code << 4 by setting flag stm32.ADC_CR2_ALIGN.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good trick!

@@ -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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unset prev value and set new

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for using setter function here.

@deadprogram
Copy link
Member

Thanks for the additional fix here @grudzinski now merging.

@deadprogram deadprogram merged commit 127557d into tinygo-org:dev Jan 17, 2025
17 checks passed
@deadprogram deadprogram changed the title Fix ADC channel selecting and ADC value reading stm32: Fix ADC channel selecting and ADC value reading Jan 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants