I got an issue with my way to address the registers of the ADCs. When I try to read them, I get zero in the result. And it seems I cannot change anything there. I tried to change the clock pre scaler value, and it did not change the conversion time.
This is my code:
Code: Select all
/*
Tests with Nucleo-64 STM32G474RE summer 2026
Test of Analog input on via Arduino Framework
Test of Digital input output via Arduino Framework
Test of Serial Monitor
*/
// the setup function runs once when you press reset or power the board
bool di= false;
int potmeter = 0;
uint32_t maskCommonCCRPresc = 0b00000000001111000000000000000000; //0b00000000 00111100 00000000 00000000
uint32_t presc256 = 0b00000000001011000000000000000000;
uint32_t presc4 = 0b00000000000010000000000000000000;
uint32_t adcClkFrq;
uint32_t ADCregister;
void setup() {
// initialize pin inputs and outputs
delay(8000);
pinMode(A2, OUTPUT); // External LED and in series with 180 ohm to GND
pinMode(A5, INPUT); // Switch is connected to VCC and recistor to GND.
pinMode(A0, INPUT_ANALOG);
analogReadResolution(12);
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
ADCregister = ADC12_COMMON->CCR;
Serial.print("ADC12_CCR: ");
Serial.println(ADCregister, BIN);
ADC12_COMMON->CCR = (ADC12_COMMON->CCR & ~maskCommonCCRPresc) | presc256;
ADCregister = ADC12_COMMON->CCR;
Serial.print("ADC12_CCR after manipulation: ");
Serial.println(ADCregister, BIN);
}
// the loop function runs over and over again forever
void loop() {
digitalWrite(A2, digitalRead(A5)); // turn the A2 output according to A5 input
digitalWrite(LED_BUILTIN, HIGH); // Takes about 210 ns or about 36 CPU clockcycles.
potmeter = analogRead(A0); // Inputs a 10 bit value from AD-converter even though it is a 12 bit ADC in MPU.
// The reason is likely due to portability of software.
digitalWrite(LED_BUILTIN, LOW); // I measured the excecution time here by digital oscilloscope. It is 150 us !!!
ADCregister = ADC12_COMMON->CCR;
Serial.print("ADC12_CCR: ");
Serial.println(ADCregister, BIN);
ADCregister = ADC1->CR;
Serial.print("ADC1_CR: ");
Serial.println(ADCregister, BIN);
ADCregister = ADC2->CR;
Serial.print("ADC2_CR: ");
Serial.println(ADCregister, BIN);
Serial.print("Potvalue: ");
Serial.println(potmeter);
delay(2000); // wait for a 0.1 second
}
ADC12_CCR: 0
ADC12_CCR after manipulation: 0
ADC12_CCR: 0
ADC1_CR: 0
ADC2_CR: 0
Potvalue: 885
ADC12_CCR: 0
ADC1_CR: 0
ADC2_CR: 0
Potvalue: 879
ADC12_CCR: 0
ADC1_CR: 0
ADC2_CR: 0
Potvalue: 885