hey i want to read a temperature sensor and a humidity sensor i want to send the values via cdc to my pc and then read them in c# windows forms my question is now how can i read two adc at the same time so i have separate data ? here you have my stm code
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-01-10 6: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);
}
- Labels:
-
ADC
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-01-10 6: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));
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-01-10 7: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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-01-10 7:20 AM
could you do me a little example ? i dont get it thanks :D
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-01-10 8: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....
