2022-01-10 06:05 AM
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
HAL_ADC_Start(&hadc2);
HAL_ADC_Start(&hadc1);
if (HAL_ADC_PollForConversion(&hadc2, 10) == HAL_OK)
{
adcValTemp = HAL_ADC_GetValue(&hadc2);
// Temperature Calculation
adcTemp = (3300 * adcValTemp) / 4096;
Temp = (adcTemp - 2636) / -13.6;
//itoa(adcValTemp, string_adcValTemp, 10);
//CDC_Transmit_FS(string_adcValTemp, strlen((const char*)string_adcValTemp));
CDC_Transmit_FS(adcValTemp, sizeof(adcValTemp));
}
HAL_Delay(500);
if (HAL_ADC_PollForConversion(&hadc1, 10) == HAL_OK)
{
adcVal = HAL_ADC_GetValue(&hadc1);
itoa(adcVal, string_adcVal, 10);
CDC_Transmit_FS(string_adcVal, strlen((const char*)string_adcVal));
}
HAL_Delay(500);
}
2022-01-10 06:06 AM
here i also go the c# code
public partial class Form1 : Form
{
string inbuffer;
public Form1()
{
InitializeComponent();
serialPort1.Open();
}
private void DisplayText(object sender, EventArgs e)
{
label1.Text = Convert.ToString(inbuffer);
}
private void serialPort1_DataReceived(object sender, System.IO.Ports.SerialDataReceivedEventArgs e)
{
inbuffer = serialPort1.ReadExisting();
this.Invoke(new EventHandler(DisplayText));
}
}
}
2022-01-10 07:09 AM
Read both values and send them at the same time within the same USB packet. In your reception program, you will need to unpack them again in the proper order.
2022-01-10 07:20 AM
could you do me a little example ? i dont get it thanks :D
2022-01-10 08:42 AM
In your code you mix value types ... binary data send ... ascii data send
adcValTemp = HAL_ADC_GetValue(&hadc2);
...
CDC_Transmit_FS(adcValTemp, sizeof(adcValTemp));
Too you say how can i read two adc at the same time,
but used code differ. For same moment measure you need triggered ADC not polled, and wait read result in IT or DMA mode....