I'm working with nano 33 IoT for BLE.
My system connects nano 33 IoT through UART.
Nano 33 IoT is getting some data from UART and updates characteristic the data.
My code in loop is like below.
Please post your code and explain your application a bit to allow us to give you better answers.
As sterretje mentioned the UART is already handled by interrupt. You are talking to a buffer in RAM.
Why is that? The SAMD21 could execute every instruction that could fit into its memory in less than 3ms.
About your code snipped:
You are using while. That is usually not a good idea because it can block your code for a random amount of time.
Then you follow up with a readStringUntil that can block your code for even longer.
I would recommend you try to
make the loop run as often as possible
assemble the String character by character, build in some error checking in case no newLine is send
you can print every character you receive back to Serial Monitor while they arrive, the same principle of a buffer applies here, you write to a buffer and the USB stack puts everything into packets and sends them when it can
if the String is complete update the characteristic
if you like you can even avoid using Strings altogether, use a char array instead
This will allow you to extend the sketch with many other things without breaking what you already have. Try to avoid delay, while, waiting for anything ...
May I ask why you use a String characteristic? Many new BLE user do this to create a serial pipe. This is wasting the smart ideas of GATT. BLE was intentionally not designed as a serial replacement. There is no Serial Port Profile in BLE while there is one in Bluetooth Classic.