cancel
Showing results for 
Search instead for 
Did you mean: 

Printing Garbage Value

Divesh Dutt
Associate II

Hi there,

I am working with tfmini lidar and i am using USART3.However i am getting the garbage in the virtual port any idea how can i resolve this but i am getting the right header i.e YY in decimal.

Any suggestion would be appreciated.

Thanks

0693W00000AMIO5QAP.png

1 ACCEPTED SOLUTION

Accepted Solutions
John E KVAM
ST Employee

After much conversation, this is not an ST part. It's from Sparkfun, but based on an LED emitter and photo diode.


If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.

View solution in original post

14 REPLIES 14
John E KVAM
ST Employee

That looks like you are at the wrong baud-rate. Try at 9600, 115200 and 460800. Those are the popular ones.

Or you can look in the main, and search for the word 'Baud'. It will tell you the rate.

  • john

If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.
Divesh Dutt
Associate II

Hi John.

The baud rate that i'm using with lidar is 115200 (i'm using UART3 to connect lidar and st board)since lidar works on this baud rate as mentioned in its data sheet and i'm printing this data to vcp at the rate of 9600(on UART2).would this be a problem?(if this is the problem how to solve this since st-link is connected to UART2 which is always programmed to work on 9600).

John E KVAM
ST Employee

In my main - generated by the STM32CubeMX - which is a really cool tool for getting started on any STM32 project - I have:

huart2.Instance = USART2;

huart2.Init.BaudRate = 460800; //921600;//USART2_BAUD_RATE;

huart2.Init.WordLength = UART_WORDLENGTH_8B;

huart2.Init.StopBits = UART_STOPBITS_1;

huart2.Init.Parity = UART_PARITY_NONE;

huart2.Init.Mode = UART_MODE_TX_RX;

huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;

huart2.Init.OverSampling = UART_OVERSAMPLING_16;

if (HAL_UART_Init(&huart2) != HAL_OK)

{

Error_Handler();

}

I don't have any problem - although I did download and run

STSW-LINK007 Development ToolsSoftware Development ToolsST-LINK, ST-LINK/V2, ST-LINK/V2-1, STLINK-V3 boards firmware upgrade

which is the latest upgrade.

I'm thinking this should work for you too.

and if you have not tried STM32CubeMX, you really should.


If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.
Divesh Dutt
Associate II

hi john,

i tried both 460800 and 921600 but i was getting garbage data(After upgrading to the st-link firmware) i was still getting the garbage and when i changed UART2 to 9600.i was getting some readable data but not until when i started waving my hand in front of lidar.Here is the picture attached below.

and yes I am using CubeMx ;)

0693W00000AMnTGQA1.png

What are you expecting here? Numbers in ASCII?

The data packets returned have binary data in them, not really designed to be human-readable at the terminal console.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Divesh Dutt
Associate II

Yes i am expecting ascii.i am printing the data same as i got from lidar.

i'm assuming the data is coming in ascii.since header 'Y' is printing this way.i want to change them to binary format after to do some useful with them.

John E KVAM
ST Employee

I'd quit trying to get the data from the sensor to start.

I'd begin with "hello world" and make sure you get the prints right.

Divide up the problem.

is it the sensor? Or the interface?


If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.
Divesh Dutt
Associate II

Hi John,

I tried printing "hello" which is working completely fine.May be it is sensor but i am still confuse is the sensor baud rate not programmed right since it says 115200 on the data sheet.I am planning to use USB to TTL to give a try if i can alter sensor baudrate.I am not getting any another idea.

John E KVAM
ST Employee

the sensor talks to the STM32 via an I2C, it is the STM32 that generates the printf. The printf then goes to the ST-Link (which is itself an STM32) with changes the protocol to go over your USB cable and then the PC converts it back to a simulated RS-232 interface which you see in your TeraTerm.

But if your 'hello world" works than all that piping does too.

So lets talk about your code (my example is for the VL53L1 ULD but your will look similar):

Heres the initialization

printf("Autonomous Ranging Test\n");
  status = VL53L1_WaitDeviceBooted(Dev);
  status = VL53L1_DataInit(Dev);
  status = VL53L1_StaticInit(Dev);
  status = VL53L1_SetPresetMode(Dev, VL53L1_PRESETMODE_LOWPOWER_AUTONOMOUS);
  status = VL53L1_SetDistanceMode(Dev, VL53L1_DISTANCEMODE_LONG);
  status = VL53L1_SetMeasurementTimingBudgetMicroSeconds(Dev, 50000);
  status = VL53L1_SetInterMeasurementPeriodMilliSeconds(Dev, 500);
  status = VL53L1_StartMeasurement(Dev);
 
	if(status){
		printf("VL53L1_StartMeasurement failed \n");
		while(1);
	}	

and the meat of the function should look like this:

do // polling mode
		{
		  status = VL53L1_WaitMeasurementDataReady(Dev);
			if(!status)
			{
				status = VL53L1_GetRangingMeasurementData(Dev, &RangingData);
				if(status==0){
					printf("%d,%d,%.2f,%.2f\n", RangingData.RangeStatus,RangingData.RangeMilliMeter,
									(RangingData.SignalRateRtnMegaCps/65536.0),RangingData.AmbientRateRtnMegaCps/65336.0);
				}
				status = VL53L1_ClearInterruptAndStartMeasurement(Dev);
			}
		}
		while (1);

and it's that big print statement that should get you the data.

So what does your printf look like?


If this or any post solves your issue, please mark them as 'Accept as Solution' It really helps. And if you notice anything wrong do not hesitate to 'Report Inappropriate Content'. Someone will review it.