Sending float voltage value via USB CDC.
Hello,
I want to send the float type voltage value that I read with stm32f429I discovery card using adc reference voltage via usb cdc. My problem is this; I read the adc reference voltage and voltage value, and I can assign it to a float type variable. But when I want to send this variable via usb, the voltage value is read infinitely and I cannot send it. Can you help with this problem? The codes I use are below;
#include "main.h"
#include "usb_device.h"
#include "usbd_cdc_if.h"
#include <string.h>
#include <stdio.h>
#define VREFIN_CAL ((uint16_t*)((uint32_t)0x1FFF7A2A))
uint16_t adc_value[2];
float Vadc = 0, Vdda = 0;
int count = 0;
char volt_array[16];
void Read_ADC()
{
if(HAL_ADC_PollForConversion(&hadc1, 1000000) == HAL_OK)
{
adc_value[count] = HAL_ADC_GetValue(&hadc1);
count++;
if(count == 2)
count = 0;
Vdda = (float) 3.3 * (*VREFIN_CAL) / adc_value[1];
Vadc = Vdda * adc_value[0] / 4095;
}
}
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_ADC1_Init();
MX_I2C1_Init();
MX_SPI1_Init();
MX_TIM2_Init();
MX_USB_DEVICE_Init();
HAL_ADC_Start(&hadc1);
while (1)
{
Read_ADC();
sprintf(volt_array, "%.4f\n\r", Vadc);
CDC_Transmit_HS((uint8_t*)volt_array, strlen(volt_array));
}
}
Thank you for your help.
