Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Arduino Mega中的高比特率_Arduino_Bluetooth Lowenergy - Fatal编程技术网

Arduino Mega中的高比特率

Arduino Mega中的高比特率,arduino,bluetooth-lowenergy,Arduino,Bluetooth Lowenergy,我正在使用Arduino Mega计算BLE模块的吞吐量。模块工作在3.3V,所以我在BLE和Arduino之间有逻辑电平移位器。BLE UART设置为115200,以64Kbps的速度发送数据(使用CC2540 BLE数据包嗅探器验证)。BLE发送的数据包采用十六进制格式:400102030405060708090A0B0C0D0E0F10111121323{40=@,23=#}。我正在发送100个数据包。这是我的代码摘要。该代码适用于较低比特率32Kbps,但不适用于64Kbs(BLE连接间

我正在使用Arduino Mega计算BLE模块的吞吐量。模块工作在3.3V,所以我在BLE和Arduino之间有逻辑电平移位器。BLE UART设置为115200,以64Kbps的速度发送数据(使用CC2540 BLE数据包嗅探器验证)。BLE发送的数据包采用十六进制格式:400102030405060708090A0B0C0D0E0F10111121323{40=@,23=#}。我正在发送100个数据包。这是我的代码摘要。该代码适用于较低比特率32Kbps,但不适用于64Kbs(BLE连接间隔为10ms)。它不会显示此比特率的任何结果

void loop() 
{
if(rxflag)
{
rxflag = false;
switch(rxState)
{

case get_first_header:
if(rxChar=='@')
{
startPoint=millis();
rxState=get_last_header;
}
break;

case get_last_header:
if(rxChar=='#')
{
packetNo++;
if(packetNo==100) 
{
endPoint=millis();
totalTime= endPoint-startPoint;
Serial.print("Total Time of Packet=");
Serial.println(totalTime);
}
break;
}
}
}

void serialEvent1() 
{
if (Serial1.available()>0) 
{
rxChar = (char)Serial1.read();
rxflag = true;
}
}

“清除”串行缓冲区时:

void serialEvent1() 
{
  if (Serial1.available()>0)
  {
    rxChar = (char)Serial1.read();    // was previous value of rxChar read ?  mystery...
                                      // this is a serious problem.

                                      // 1 byte at a time?  This can slow down
    rxflag = true;                    // reception quite a bit, esp. if there
  }                                   // is xon/xoff. 
}
当您在中断例程中设置了一个事件时,您需要在读取数据之前重置它,除非使用该标志作为中断数据的锁

这里,您应该考虑如何显著地提高吞吐量和减少接收错误。

void serialEvent1() 
{
   rxflag = true;
}

//...
void lopp()
{
   // ...
   if (rxflag)
   {
       rxflag = false;                 // reset/read order is to avoid stalling.
       while (Serial1.available())
       {
           // reading 4 or up 16 bytes at a time on a local buffer 
           // would help the tiny mega get this done job done faster.
           //
           //  char buffer[8] buffer;  // 2 dwords on the stack.  don't overuse!
           //
           char c = (char)Serial.read();
           // run state machine...
       }
   }
   // ...
}