cancel
Showing results for 
Search instead for 
Did you mean: 

How can i read a sensor value with UART communication?

suba
Associate II
 
6 REPLIES 6
es131245
Associate II

We do not know what type of a sensor are you using.

If it have analog voltage output use ADC to read its data.

UART is a communication method.

UART can be used to output data from an MCU to other device.

Its usefull if MCU board doent have any display and you want to use PC instead.

suba
Associate II

yeah ! that's fine here i use

HAL_GPIO_WritePin(GPIOA,GPIO_PIN_10,GPIO_PIN_SET);

 HAL_ADC_Start(&hadc1);

 HAL_ADC_PollForConversion(&hadc1,HAL_Delay);

 row = HAL_ADC_GetValue(&hadc1);

 HAL_GPIO_WritePin(GPIOA,GPIO_PIN_10,GPIO_PIN_RESET);

 sprintf(msg,"%hu\r\n", row);

 HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_Delay);

 HAL_Delay(1);

then why i couldnt read a sensor value?

You want to read an analog voltage level using ADC, and output it to UART?

And there's no UART communication? Then debug UART - in debugger, read out the UART and GPIO registers values and check them against the RM, if they are of the expected value.

Or is there UART communication but the value is not expected? Then debug ADC - in debugger, read out the ADC registers values and check them.

JW

Sorry Mr.Jan I can't understand this . Will you please explain clea

Was the brain turned on, when you were reading Jan's text? What specifically you didn't understand? Basically he said - implement one thing at a time. Start with USART sending "Hello, world!", learn debugging, implement ADC reading and only then bring it all together.

suba
Associate II

Thank to both of you ​