const float BETA = 3950;
void setup() {
// __HAL_RCC_GPIOA_CLK_ENABLE(); // enable clock to GPIOA
// GPIO_InitTypeDef ADCpin; //create an instance of GPIO_InitTypeDef C struct
// ADCpin.Pin = GPIO_PIN_1; // Select pin PA0
// ADCpin.Mode = GPIO_MODE_ANALOG; // Select Analog Mode
// ADCpin.Pull = GPIO_NOPULL; // Disable internal pull-up or pull-down resistor
// HAL_GPIO_Init(GPIOA, &ADCpin); // initialize PA0 as analog input pin
__HAL_RCC_GPIOA_CLK_ENABLE(); // enable clock to GPIOA
GPIO_InitTypeDef ADCpin; //create an instance of GPIO_InitTypeDef C struct
ADCpin.Pin = GPIO_PIN_0; // Select pin PA0
ADCpin.Mode = GPIO_MODE_ANALOG; // Select Analog Mode
ADCpin.Pull = GPIO_NOPULL; // Disable internal pull-up or pull-down resistor
HAL_GPIO_Init(GPIOA, &ADCpin); // initialize PA0 as analog input pin
Serial.begin(9600);
}
void loop() {
int analogValue = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1);
// int analogValue =(int)HAL_ADC_GetValue(GPIO_PIN_1)
int analogValue1 = analogRead(A1);
//Serial.print(analogValue);
float celsius = 1 / (log(1 / (1023. / analogValue1 - 1)) / BETA + 1.0 / 298.15) - 273.15;
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.println(" ℃");
delay(1000);
}