cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F407 Buffer printing HAL_UART_Transmit

davidec
Associate III

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

  }

  }

 

  }

16 REPLIES 16

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);
			        	  }
	}

 sprintf(str, "%hu",(uint16_t*)buf1[c]); // conversion in str of value

 Did you fix the error on this line? Show the corrected code.

 

If you feel a post has answered your question, please click "Accept as Solution".
davidec
Associate III
  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;
	  }
	  }

So show what is in buf1 array, and what you're seeing being printed. And what are you printing to?

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.
CAN Jammer an open source CAN bus hacking tool
CANableV3 Open Source

davidec
Associate III

Screenshot 2023-10-24 alle 11.02.56.png

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.

 

Screenshot 2023-10-24 025636.pngScreenshot 2023-10-24 025645.png

If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.
CAN Jammer an open source CAN bus hacking tool
CANableV3 Open Source

davidec
Associate III

I am using a TTL converter because via usb I cannot see the serial port. Is there some setting I'm missing?