STM32F407 Buffer printing HAL_UART_Transmit
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2023-10-23 08:37 AM
Good morning everyone, after collecting some data and storing it in various buffers, I am trying to write them to the serial port for further processing. I am experiencing issues as I can see that something is being written to the serial port, but not all the samples in the buffer are being printed. Any suggestions?
while (1)
{
HAL_UART_Receive (&huart2, UART1_rxBuffer, 1, 5000); //receive and store string
if(UART1_rxBuffer[0] == 115){
HAL_UART_Transmit(&huart2, UART1_rxBuffer, 1, 100); //print received string
if(flag == 1){ //check add finished
for(c=0;c<ADC_BUF_SIZE/2;c++){
sprintf(str, "%hu",(uint16_t*)buf1[c]); // conversion in str of value
HAL_UART_Transmit(&huart2, (uint8_t*)str, strlen(str), HAL_MAX_DELAY);
HAL_Delay(10);
}
HAL_UART_Transmit(&huart2,(uint8_t *)space,strlen(space),10); // string = “— — — — ;”
UART1_rxBuffer[0]=0; // start flag clear
flag = 0; // conversion adc clear
}
}
}
- Labels:
-
STM32F4 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2023-10-23 12:21 PM
i have already done it. The adc sample the signal that i need and after the buffer filling I need, it does not change buf1 and buf2. The problem remains for me to print the values to serial and then process them externally.
for(i=0;i<ADC_BUF_SIZE/2;i++)
{
buf1[i] = (uint16_t)(adcBuf[i]&0x0000FFFF);
buf2[i] = (uint16_t)(adcBuf[i]>>16);
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2023-10-23 12:32 PM
> sprintf(str, "%hu",(uint16_t*)buf1[c]); // conversion in str of value
Did you fix the error on this line? Show the corrected code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2023-10-23 12:37 PM
while (1)
{
HAL_UART_Receive (&huart2, UART1_rxBuffer, 1, 5000);
if(UART1_rxBuffer[0] == 115){
HAL_UART_Transmit(&huart2, UART1_rxBuffer, 1, 100);
if(flag == 1){
for(c=0;c<ADC_BUF_SIZE/2;c++){
sprintf(str, "%u\r\n",((uint16_t*)buf1)[c]); // conversion in str of value
HAL_UART_Transmit(&huart2, (uint8_t*)str, strlen(str), HAL_MAX_DELAY);
HAL_Delay(100);
}
HAL_UART_Transmit(&huart2,(uint8_t *)space,strlen(space),10);
UART1_rxBuffer[0]=0;
flag = 0;
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2023-10-23 12:52 PM - edited 2023-10-23 12:53 PM
So show what is in buf1 array, and what you're seeing being printed. And what are you printing to?
If you find my solution useful, please click the Accept as Solution so others see the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2023-10-24 02:04 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2023-10-24 03:03 AM
So what interface are you using to communicate with uart2? I suspect that is your weak link.
I am using a STM32F407VG-Discovery, used your code and saved the same data that you've provided. When i press the letter 's', I am able to output all the data correctly.
If you find my solution useful, please click the Accept as Solution so others see the solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
2023-10-24 03:18 AM
I am using a TTL converter because via usb I cannot see the serial port. Is there some setting I'm missing?
- « Previous
-
- 1
- 2
- Next »