2022-12-09 09:22 AM
2022-12-09 09:54 AM
Yes, syntax is wrong for HAL_UART_Transmit(), it wants a POINTER, and will send a pair of raw bytes over the wire. Will look like random junk bytes in a terminal application.
HAL_UART_Transmit(&huart1, (uint8_t *)&readValue, sizeof(readValue), 100);
for human readable numbers
char string[10];
HAL_UART_Transmit(&huart1, (uint8_t *)string, sprintf(string, "%d\n", readValue), 100);
Post code in-line via </> icon, screen shots are unhelpful
2022-12-09 09:54 AM
Yes, syntax is wrong for HAL_UART_Transmit(), it wants a POINTER, and will send a pair of raw bytes over the wire. Will look like random junk bytes in a terminal application.
HAL_UART_Transmit(&huart1, (uint8_t *)&readValue, sizeof(readValue), 100);
for human readable numbers
char string[10];
HAL_UART_Transmit(&huart1, (uint8_t *)string, sprintf(string, "%d\n", readValue), 100);
Post code in-line via </> icon, screen shots are unhelpful
2022-12-09 10:13 AM
Thanks for the reply :folded_hands:
but again the problem is not solved!
void SystemClock_Config(void);
static void MX_GPIO_Init(void);
static void MX_ADC1_Init(void);
static void MX_USART1_UART_Init(void);
/* USER CODE BEGIN PFP */
/* USER CODE END PFP */
/* Private user code ---------------------------------------------------------*/
/* USER CODE BEGIN 0 */
uint16_t readValue;
char string[10];
/* USER CODE END 0 */
/**
* @brief The application entry point.
* @retval int
*/
int main(void)
{
/* USER CODE BEGIN 1 */
/* USER CODE END 1 */
/* MCU Configuration--------------------------------------------------------*/
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();
/* USER CODE BEGIN Init */
/* USER CODE END Init */
/* Configure the system clock */
SystemClock_Config();
/* USER CODE BEGIN SysInit */
/* USER CODE END SysInit */
/* Initialize all configured peripherals */
MX_GPIO_Init();
MX_ADC1_Init();
MX_USART1_UART_Init();
/* USER CODE BEGIN 2 */
HAL_ADC_Start(&hadc1);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
HAL_ADC_PollForConversion(&hadc1,1000);
readValue = HAL_ADC_GetValue(&hadc1);
HAL_UART_Transmit(&huart1, (uint8_t *)&readValue, sizeof(readValue), 100);
2022-12-09 10:37 AM
>>but again the problem is not solved!
"The Problem" is ill defined.
No idea what board or chip you are using.
No idea how and to what the UART is configured and connected.
No idea what terminal app you have connected, what you are seeing, or what you expect to see.
2022-12-09 11:32 AM
Try paste here red console log complete not as screenshot. Seems error on board connection....
2022-12-10 02:23 AM
I use stm32G01291 and CubeIDE
Actually I am a data scientist and just want to get data from ADC and transmit it to python in order to some analysis and ML algorithms!
I used for configuration like this:
ADC1 - IN9 (tick)
Parameter Settings --> ADC Settings --> Continuous Conversion Mode (Enabled)
Enable USART1 asynchronous
Parameter Settings --> Basic Parameters --> Baud rate 9600
2022-12-10 02:34 AM
Actually codes work now I can see the readValue in live Expression but I am not sure that I can get from serial on the python too! do you think is it enough writing code
for USRAT1 transmit by USB?
2022-12-10 02:45 AM
2022-12-10 03:42 AM
Seems you are on linux and OCD. For UART to USB you need VCP ...
Too stm32G01291 dont exist
Start any request here with board name or custom.
2022-12-10 04:27 AM
Thanks again for the reply!
I solved the problem it was related to debugging. I use macOS.