Is there something wrong with my code/settings? I tried using putty's terminal to view the output; however, even though I configured it correctly with the baud settings, etc., no data is appearing. I am able to see the "hello world" in the terminal though. It is on a NUCLEO-F767ZI Microprocessor. I am using STM32CubeIDE.
This is my code:
#include <stdio.h>
#include <stdlib.h>
#include "stm32f7xx_hal.h"
/* Define your UART handle */
UART_HandleTypeDef huart3;
ADC_HandleTypeDef hadc; // Declare 'hadc' here
void Error_Handler(void) { while (1); }
void SystemClock_Config(void) { /* Configure system clock here */ }
/* Initialize UART */
void init_uart(void) {
huart3.Instance = USART3;
huart3.Init.BaudRate = 9600; // Baud rate: 9600 bps
huart3.Init.WordLength = UART_WORDLENGTH_8B;
huart3.Init.StopBits = UART_STOPBITS_1; // Stop bits: 1
huart3.Init.Parity = UART_PARITY_NONE; // Parity: None
huart3.Init.Mode = UART_MODE_TX_RX;
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
HAL_UART_Init(&huart3);
}
/* Custom implementation of _write for printf redirection */
int _write(int file, char *ptr, int len) {
HAL_UART_Transmit(&huart3, (uint8_t*)ptr, len, HAL_MAX_DELAY);
return len;
}
void init_gpio(void) {
// GPIO initialization code
}
void init_timer(void) {
// Timer initialization code
}
void init_adc(void) {
// ADC initialization code
}
int main(void) {
HAL_Init();
SystemClock_Config();
init_uart();
init_gpio();
init_timer();
init_adc();
uint32_t start_time = 0;
float input_voltage = 0.0f;
while (1) {
printf("Hello World\n");
start_time = HAL_GetTick(); // Start time for capturing voltage data
while (HAL_GetTick() - start_time < 5000000) // Capture data for 5 seconds
{
// Read data from ADC and process if needed
// (similar to your previous ADC reading code)
// Print voltage and time
HAL_ADC_Start(&hadc); // Declare 'hadc' here
HAL_ADC_PollForConversion(&hadc, HAL_MAX_DELAY);
uint32_t adc_value = HAL_ADC_GetValue(&hadc);
input_voltage = (float)adc_value / 4095.0f * 3.3f;
HAL_ADC_Stop(&hadc);
printf("Time: %lu ms, Input Voltage: %.2f V\n", HAL_GetTick() - start_time, input_voltage);
// No fflush(stdout) here
HAL_Delay(1); // Delay between voltage measurements
}
printf("Measurement done\n"); // Output to indicate end of measurement
}
}