-
Notifications
You must be signed in to change notification settings - Fork 42
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
analogRead() on CH32V003A4M6 only returns 0 #94
Comments
I have used ADC on the CH32V003J4M6 (the SOP8 package). I first had to After that I had no trouble using the regular ADC channels. However to read PADC_VREF to be able to calculate VCC, I had to implement a workaround in analogInputToPinName() in pins_arduino.cpp. (vRef is about 1.2V: "VREFINT Internal reference voltage TA = -40℃~85℃ Min:1.17 Typ:1.2 Max:1.23 V"). Have you checked to see that ADC is enabled? |
Thank you, that was definitely the fix. Why wouldn't the ADC be enabled by default? |
Been there, done that... In my case it was enabling SPI. Most of us made that assumption. In Arduino land we're not used to make configurations that way. I prefer to set my options in the IDE. Reason might be both. Some of these defines definitely affect code size. For some it doesn't matter. I use the CH32V003 which is limited to 16kB programming flash that can fill up quickly. Multiple times I had to select which features I needed most and dump the rest. After finding out that my chips without crystal ran at incorrect speed, I also needed to change a header file. For my own projects I added such option to the IDE. Someone else posted the same change as PR. I still want to make a change that puts all peripheral options in the IDE. Finally be aware that this Arduino core isn't very mature yet. Other people and myself proposed several changes to make the core more usefull (eg. implement Serial.available(), i2c-slave mode, ADC vRef/VCC, Eeprom emulation, etc). |
In my project I use the CH32V003J4M6 (the SOP8 package). I checked my code and saw that it uses A2 as pin name. Since your A4M6 has OSCO and OSCI on the same pins as A0 and A1, I assume you're using the internal oscillator. |
I am using the CH32V00x configuration when compiling. Programming goes fine. Log:
I have attempted many line configurations
analogRead(PIN_A0)
analogRead(PA2)
analogRead(A0)
All return 0
This package variant should work, yes?
The V003-EVT uses F4P6 but that code should still work on A4M6 as long as I use pins that are exposed right?
I tested Serial outputs and digitalWrite() working just fine, but no analog reads.
Arduino Studio 2.3.2
Boards Mgr Rev 1.0.4
WCH-Link hw:1v3
The text was updated successfully, but these errors were encountered: