Distance measurement issue

Issues like this are what makes c / c++ one of the harder languages to use. Unfortunately they are also what makes it one of the faster and most efficient languages to use. :slight_smile:

There is no reason why you can’t get the CIR and distance at the same time. I’d check that when outputting CIR you’re not skipping part of the ranging code.
The other possibility is that you are hitting timing issues. Reading the CIR data takes a while, if you need to send a reply or listen for a new packet soon after receiving the packet you are getting the CIR from then you may be missing the required time because you’re still reading the data out of the chip.

Also printing the data out over a serial port will take a huge amount of time. Printf isn’t fast and physical serial ports move at a crawl. Unless your serial output is running at full USB speed or is set up to buffer the data and output it in the background then outputting that much data as soon as you get it will guarantee you miss any future time requirements. If timing is critical then save the CIR data into an array and output it later.