Ble friend spi

For CircuitPython issues, ask in the Adafruit CircuitPython forum.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
richardf
 
Posts: 44
Joined: Tue Feb 14, 2012 4:35 pm

Ble friend spi

Post by richardf »

I have both the BLE friend UART and SPI connected to a Teensy.
Software functions on both - HOWEVER

I don't understand the SPI's use of IRQ.
Assuming there are no transmissions to the BLE, the software checks for available().
The UART is connected with hardware flow control on the Teensy and it rips right through the available() with very little delay.

Not so for the SPI, when in DATA mode, which forces calls to sendPacket and getResponse which call available() multiple times
resulting in about 1 second to get out of the checking for input.

int Adafruit_BluefruitLE_SPI::available(void)
{
if (! m_rx_fifo.empty() ) {
return m_rx_fifo.count();
}

if ( _mode == BLUEFRUIT_MODE_DATA )
{
// DATA Mode: query for BLE UART data
sendPacket(SDEP_CMDTYPE_BLE_UARTRX, NULL, 0, 0);

// Waiting to get response from Bluefruit
getResponse();
// Serial.print("available. In BLUEFRUIT_MODE_DATA count: "); Serial.println(m_rx_fifo.count());
return m_rx_fifo.count();
}else
{
return (digitalRead(m_irq_pin));
}
}

Why does the code only use the m_irq_pin when not in the BLUEFRUIT_MODE_DATA mode?

What can be done to reduce all of this SPI traffic just to determine that there is no data available?

thanks,

Richard Ferraro

User avatar
gpshead
 
Posts: 2
Joined: Sun Oct 16, 2011 4:26 pm

Re: Ble friend spi

Post by gpshead »

The behavior I see from the Bluefruit SPI friend (and related bluefruits) is that the IRQ pin is not asserted immediately upon UART RX receive on the Bluefruit module. It appears to only raise the IRQ line for pending UART RX data if you have not done a UART RX (0x0A02) transaction within the last ~second. It _also_ appears to raise it regardless of if there is actually UART data in the Bluefruit's FIFO. (making it effectively a form of heartbeat)

Unfortunate. I'd prefer an IRQ as soon as a bluetooth UART data packet made its way into the FIFO and none when their isn't.

For latency sensitive responses you need to poll the Bluefruit with UART RX commands as often as makes sense for your needs within your main loop rather than waiting for the IRQ pin.

Bluefruit firmware version 0.7.7.

User avatar
sportscliche
 
Posts: 17
Joined: Sat Mar 10, 2018 1:43 am

Re: Ble friend spi

Post by sportscliche »

My experience as well. After some experimentation, I determined that a delay of at least 4 ms is needed before looking for a response on the MISO. Same delay for TX and RX. I de-assert CS between packets, ie CS is high during the 4 ms delay. Couldn’t really find anything useful to do with IRQ.

Other info: SPI mode 0, MSB first, wait 100 us after pulling CS low before clocking in MOSI data. My SPI clock running at 1 MHz; not sure if that matters.

Locked
Please be positive and constructive with your questions and comments.

Return to “Wireless: WiFi and Bluetooth”