-
- Notifications
You must be signed in to change notification settings - Fork 7k
Description
To gauge the bytes/s data transmission capabilities of the Nano 33 BLE Sense's USB CDC Virtual Serial COM I was trying to run this code from an older post on the Arduino forum which was originally used on the Leonardo (which also has native USB like the Nano):
const unsigned long NUMERATOR = 1000000000; void setup(){ Serial.begin(115200); //Does nothing on the nano 33 ble sense. while (!Serial); //Wait for serial port to connect. Needed for native USB on nano 33 ble sense. Serial.println("Begin printing."); } void loop(){ Serial.println("Enter loop."); unsigned long startClock = micros(); for (int i = 1000; i > 0; i--) { Serial.write('.'); //Non-blocking so wait until complete using Serial.flush() directly after... Serial.flush(); //Blocks forever on nano 33 ble sense. } unsigned long endClock = micros(); uint32_t bytesPerSecond = NUMERATOR / (endClock-startClock); Serial.println(""); Serial.print(bytesPerSecond); Serial.println(" bytes/second"); while(1); }
BTW: When this code was ran on the Leonardo, they reportedly measured 39258 bytes/s. I'm not getting anything because I'm never able to escape the for loop!
I think the problem is the Serial.flush() line used to wait on the Serial.write('.') to complete. It seems to block forever instead of for a short time. Anyone know of an alternative to Serial.flush() that I can use on the Nano 33 BLE Sense or some other strategy to test the data transmission rate?
Also, can anyone look into how to fix the Serial.flush() please?