We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hello Guys,
I am using NucleoF070RB board to read battery voltage using voltage sensor module. I read ADC can be started by three ways Poll Conversion, Interrupts, DMA. I found many examples regarding the Arduino but could not find about STM32 Nucleo boards.
I do not have coding experience. I did the following.
int main(void){ /* USER CODE BEGIN 1 */ uint16_t raw; char msg[10]; /* USER CODE END 1 */
while (1) { // Test: Set GPIO pin high HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_SET); // Get ADC value HAL_ADC_Start(&hadc); HAL_ADC_PollForConversion(&hadc, HAL_MAX_DELAY); raw= HAL_ADC_GetValue(&hadc); // Test GPIO pin low HAL_GPIO_WritePin(GPIOA, GPIO_PIN_10, GPIO_PIN_RESET); // Convert string and print sprintf(msg, "%hu\r\n", raw); HAL_UART_Transmit(&huart2, (uint8_t*)msg, strlen(msg), HAL_MAX_DELAY);
My confusion is now how to intialise the condition for ADC resolution.
Voltage divider Vin= Vout* R2/(R1+R2) where R1 = 30K, R2 = 7.5K
ADC Resolution= 12 bit ADC = 4096 bits (0 to 4095)
Reference voltage = 3.3V (Microcontroller)
Vout= (Analog read x Reference voltage)/ 4096
I want to write the above formula in the code. But I am confusing how to write it. Can soome one help me
Thanks and Regards
Banala
Did you read the description of the forum you posted in ??
Banala said:I do not have coding experience
I would strongly recommend that you do not try to learn the 'C' programming language on a microcontroller.
www.avrfreaks.net/.../3040421
It will be a far more comfortable learning experience on a "normal" platform such as a PC.
Once you have got the language basics, then you can move on to adding all the extra complications and restriction of a microcontroller.
Here are some 'C' learning & reference materials for you:
blog.antronics.co.uk/.../
Do you have any experience with electronics ?
www.avrfreaks.net/.../2079906
Banala, have you seen a solution to this? I am new also but I can solve this for you