Author Topic: Losing incoming serial characters at 9600 baud  (Read 1947 times)

mikeboich

  • RFduino Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Losing incoming serial characters at 9600 baud
« on: January 22, 2015, 02:24:04 PM »
I'm trying to use the RFDuino with a Sparkfun Razor AHARS board.  I'm receiving yaw, pitch and roll values over the serial link.  The values are binary floating point, which are 4 bytes each.  I have the AHARS running in a mode where it sends me one frame (12 bytes) each time I send it a request, so buffer overruns shouldn't be an issue.  Nevertheless, I'm losing characters at 9600 baud.

I created a minimal test case that shows the problem.  I have a sender, sending a fixed pattern of data, and a receiver, reading the serial port and checking for the expected data.

The sender, running on the Sparkfun board waits to receive a 'g' character, and then sends serial data continuously at 9600 baud, cycling through the values 0..255.  The receiver just sends the 'g', and then monitors the serial port (actually it uses the Arduino serialEvent hook), and places the characters in a ring buffer.  If the receiver gets a character other than the next byte in the sequence, it sets one of the GPIOs to high, and echoes the contents of the ring buffer (up to 10 bytes), so that I can see the discrepancy on my logic analyzer.

With BLE not enabled, the first byte is always missed, and then the link runs reliably.  With BLE enabled, the first byte always arrived correctly, but a byte gets dropped every couple of seconds.  The logic analyzer shows the incoming data looking as it should.

I'm attaching the two sketches.  I could also submit files from the Saleae logic analyzer if those are of interest.

Any suggestions or workaround ideas?

thx

Mike Boich

mikeboich

  • RFduino Newbie
  • *
  • Posts: 12
  • Karma: +0/-0
    • View Profile
Re: Losing incoming serial characters at 9600 baud
« Reply #1 on: January 23, 2015, 08:37:29 AM »
I think I've answered my own question, a least partially.  RFduinoBLE.radioActive appears to have a period of 30 milliseconds when there is a BLE connection active.  That is, it goes active for some period of time every 30 milliseconds.  Typically that period is 5-6 milliseconds, at least in my application.

The NRF51822 USART has a 6 character hardware buffer.  Whenever the BLE radio is active for more than aprroximately 6.5 milliseconds, I see a character get missed.  This makes sense, since that's how long it takes to overrun the buffer at 9600 baud. 

The only remaining question is whether that active period is payload dependent, in which case I could perhaps manage the BLE traffic in my application to avoid the longer periods.  That doesn't sound very robust though.

I could either switch to 4800 baud, or changes schemes entirely.  Is SPI subject to the same BLE-related timing issues?

Mike
« Last Edit: January 23, 2015, 08:58:42 AM by mikeboich »

Buzkilan

  • RFduino Newbie
  • *
  • Posts: 1
  • Karma: +0/-0
    • View Profile
Re: Losing incoming serial characters at 9600 baud
« Reply #2 on: March 31, 2015, 11:03:07 AM »
Were you able to make it working without loosing serial data?

 

anything