从Arduino Nano 33 BLE Sense通过USB传输数据的最快方式



我使用以下测试代码来测量使用Arduino的Serial.write((方法在USB上发送单个字节所需的时间。示波器测量了发送一个字节的85微秒。

#include "mbed.h"
#include "nrf_delay.h"
#include "nrf_gpio.h"
#define OUTPUT_PIN NRF_GPIO_PIN_MAP(1,11)
const byte PRINT_BYTE = 254;
uint32_t startClock;
uint32_t stopClock;
uint32_t arithmeticMinuend = 4294967295;
uint32_t arithmeticSubtrahend = 2147483648;
uint32_t arithmeticDifference = 0;
uint32_t timeDifference1 = 0;
uint32_t timeDifference2 = 0;
void setup() {
delay(1000);
Serial.begin(115200);
delay(1000);
while (!Serial);
delay(1000);
nrf_gpio_cfg_output(OUTPUT_PIN);
us_ticker_init();
startClock = us_ticker_read();
stopClock = us_ticker_read();
}
void loop() {
Serial.println("Starting program:");
timeDifference1 = microsecondsToSubtract2LongsOnce();
timeDifference2 = microsecondsToSubtract2LongsAndPrint();
us_ticker_free();
Serial.print("timeDifference1 = ");
Serial.print(timeDifference1);
Serial.print(" us.ntimeDifference2 = ");
Serial.print(timeDifference2);
Serial.println(" us.");
us_ticker_init();
microsecondsToSubtract2LongsOnceMeasuredWithScope();
us_ticker_free();
delay(10);
us_ticker_init();
microsecondsToSubtract2LongsTwiceMeasuredWithScope();
us_ticker_free();
delay(10);
us_ticker_init();
microsecondsToToggleOutputPinMeasuredWithScope();
us_ticker_free();

while(1) {

}
}
//Prints 0-1 us:
uint32_t microsecondsToSubtract2LongsOnce() {
startClock = us_ticker_read();
stopClock = us_ticker_read();
return stopClock - startClock;
}
//Prints 406 us:
uint32_t microsecondsToSubtract2LongsAndPrint() {
startClock = us_ticker_read();
Serial.write(PRINT_BYTE);
stopClock = us_ticker_read();
return stopClock - startClock;
}
//Measured 1.8 us on scope:
void microsecondsToSubtract2LongsOnceMeasuredWithScope() {
nrf_gpio_pin_toggle(OUTPUT_PIN);
startClock = us_ticker_read();
stopClock = us_ticker_read();
nrf_gpio_pin_toggle(OUTPUT_PIN);
}
//Measured 85 us on scope:
void microsecondsToSubtract2LongsTwiceMeasuredWithScope() {
nrf_gpio_pin_toggle(OUTPUT_PIN);
startClock = us_ticker_read();
Serial.write(PRINT_BYTE);
stopClock = us_ticker_read();
nrf_gpio_pin_toggle(OUTPUT_PIN);
}
//Measured 500 ns on scope:
void microsecondsToToggleOutputPinMeasuredWithScope() {
nrf_gpio_pin_toggle(OUTPUT_PIN);
nrf_gpio_pin_toggle(OUTPUT_PIN);
}

我希望能够通过USB并行发送所有传感器数据,所以我需要能够比这更快地传输!有人有更好的解决方案吗?

为了提高Serial通信的传输速度,必须增加Serial.begin()中的波特率值。在这里你可以找到一个波特率和速度表。

在您的情况下,115200的波特率对应于您测量的值86us的字节持续时间。

根据Nordic的文件,nrf52840支持波特率,直到1M

最新更新