uhh
This commit is contained in:
@@ -9,7 +9,8 @@
|
||||
* Copyright (c) 2025 STMicroelectronics.
|
||||
* All rights reserved.
|
||||
*
|
||||
* This software is licensed under terms that can be found in the LICENSE file * in the root directory of this software component.
|
||||
* This software is licensed under terms that can be found in the LICENSE file
|
||||
* in the root directory of this software component.
|
||||
* If no LICENSE file comes with this software, it is provided AS-IS.
|
||||
*
|
||||
******************************************************************************
|
||||
@@ -21,9 +22,10 @@ extern "C" {
|
||||
|
||||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
#include <stdio.h>
|
||||
//#include <stdio.h>
|
||||
} // end extern "C"
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
@@ -33,7 +35,7 @@ extern "C" {
|
||||
|
||||
/* Private define ------------------------------------------------------------*/
|
||||
/* USER CODE BEGIN PD */
|
||||
#define Print2UART1 int __io_putchar(int data)
|
||||
#define Print2UART1 int __io_putchar(int data) // prints to serial monitor
|
||||
//float duty = 58.52 // (((2396*4096)*65534)/65534)*100
|
||||
//int duty = 59;
|
||||
float duty = 58.52;
|
||||
@@ -59,11 +61,13 @@ float volts;
|
||||
/* USER CODE END PV */
|
||||
|
||||
/* Private function prototypes -----------------------------------------------*/
|
||||
extern "C" {
|
||||
void SystemClock_Config(void);
|
||||
static void MX_GPIO_Init(void);
|
||||
static void MX_ADC1_Init(void);
|
||||
static void MX_TIM1_Init(void);
|
||||
static void MX_USART1_UART_Init(void);
|
||||
}
|
||||
/* USER CODE BEGIN PFP */
|
||||
|
||||
/* USER CODE END PFP */
|
||||
@@ -82,7 +86,6 @@ main(void)
|
||||
{
|
||||
|
||||
/* USER CODE BEGIN 1 */
|
||||
|
||||
/* USER CODE END 1 */
|
||||
|
||||
/* MCU Configuration--------------------------------------------------------*/
|
||||
@@ -115,14 +118,14 @@ main(void)
|
||||
while (1)
|
||||
{
|
||||
HAL_ADC_Start(&hadc1);
|
||||
HAL_ADC_PollForConversion(&hadc1, 100);
|
||||
HAL_ADC_PollForConversion(&hadc1, 100); //poll ADC1 periph, timeout 100ms
|
||||
|
||||
rawValue = (float)HAL_ADC_GetValue(&hadc1);
|
||||
rawValue = HAL_ADC_GetValue(&hadc1);
|
||||
|
||||
HAL_Delay(500);
|
||||
|
||||
//volts = rawValue; // TODO change this to an actual conversion
|
||||
volts = rawValue / duty;
|
||||
volts = (float)rawValue / duty;
|
||||
|
||||
//printf("The value is %hu volts.\r\n", volts);
|
||||
printf("The value is %f volts.\r\n", volts);
|
||||
@@ -131,6 +134,7 @@ main(void)
|
||||
|
||||
__HAL_TIM_SET_COMPARE(&htim1, TIM_CHANNEL_1, duty); // TODO dude what is going on
|
||||
// rawValue/4096*65545
|
||||
// i think it works now?
|
||||
HAL_Delay(100);
|
||||
/* USER CODE END WHILE */
|
||||
|
||||
@@ -367,6 +371,7 @@ static void MX_GPIO_Init(void)
|
||||
}
|
||||
|
||||
/* USER CODE BEGIN 4 */
|
||||
/*
|
||||
int
|
||||
__io_putchar(int ch)
|
||||
{
|
||||
@@ -375,6 +380,15 @@ __io_putchar(int ch)
|
||||
//return ch;
|
||||
return (int)NULL;
|
||||
}
|
||||
*/
|
||||
|
||||
extern "C" int
|
||||
__io_putchar(int ch)
|
||||
{
|
||||
uint8_t c = ch; // we just want 1 byte
|
||||
HAL_UART_Transmit(&huart1, &c, 1, HAL_MAX_DELAY);
|
||||
return ch;
|
||||
}
|
||||
|
||||
/* USER CODE END 4 */
|
||||
|
||||
@@ -406,3 +420,4 @@ void assert_failed(uint8_t *file, uint32_t line)
|
||||
/* USER CODE END 6 */
|
||||
}
|
||||
#endif /* USE_FULL_ASSERT */
|
||||
|
||||
|
||||
Reference in New Issue
Block a user