This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

SPI Slave and BLE on nRF51822

Hi,

I'm trying to build a SPI Slave <-> BLE bridge, so that everything received over SPI bus is forwarded on BLE and vice versa. In order for the reverse direction to work, the master has to continously pull data from the nRF51822. The problem is that if the BLE part of the code is compiled in and running, the SPI bus just locks up after a random time, between 2 and 60 seconds depending on data rate). I'm using ARM mbed, and the SPISlave::receive() function, which is supposed to tell if any data has been received from the master, starts returning false after that time no matter what the master actually sends to it. My SPI settings are 1 MHz, 8 bit, mode 0.

I've found a couple of posts here about incompatibilities between the PPI and the BLE stack. (Here and here and here.) However it's not clear if what I'm trying to achieve is possible or not. Some comments say that a SPI clock below 2 MHz should have no bad effects. I'm using only 1 MHz. Another comment says this is a problem with the S110 SoftDevice. (Well, I don't know which SoftDevice I have, how can I check it?) There's a mention of "using SPI over the SoftDevice API" but no information how to actually do that. Do I have give up on mbed to use the SoftDevice API? Is SPIS and the BLE stack totally incompatible and hopeless to work together? Thanks!

Parents
  • The problem was data jam on the SPI bus. Once the SPI peripheral hits a buffer underrun (or "overread error" as the Reference Manual calls it), it becomes essentially unusable under mbed because it blocks all data reception until a reply is prepared in the send buffer. (But since this normally only happens after a reception, this becomes a deadlock). If you fill the buffer with an "unsolicited" reply, the bus will start working again.

    In my case the overrun was caused by the delay introduced by mbed's BLE implementation. A working BLE radio can block the CPU for as long as 1495 microseconds (that's not the theoretical maximum, just the highest value I've seen). If the SPI peripheral has to execute more than one transaction (as dictated by the master) during the time when the BLE stack (or anything else) uses the CPU, you enter the above deadlock.

  • I tried radio notifications, and it worked, but it was unsuitable for this purpose since sometimes the CPU was still busy when the notification was inactive.

    What actually worked and ensured a stable communication between the slave and the master was per-transaction flow control. When the slave fills the buffer with data, it also sets a pin high that interrupts the master and enables it to do one transaction. As soon as the slave sees the transaction completed, it reads the data sent by the master from the buffer, sets the interrupt line to low, prepares the next transaction, and interrupts the master again by setting the interrupt line high again. This ensures that whenever the master sends something, there's a transaction already prepared on the slave side, and no more data is sent by the master before the slave is ready to receive again.

Reply
  • I tried radio notifications, and it worked, but it was unsuitable for this purpose since sometimes the CPU was still busy when the notification was inactive.

    What actually worked and ensured a stable communication between the slave and the master was per-transaction flow control. When the slave fills the buffer with data, it also sets a pin high that interrupts the master and enables it to do one transaction. As soon as the slave sees the transaction completed, it reads the data sent by the master from the buffer, sets the interrupt line to low, prepares the next transaction, and interrupts the master again by setting the interrupt line high again. This ensures that whenever the master sends something, there's a transaction already prepared on the slave side, and no more data is sent by the master before the slave is ready to receive again.

Children
No Data
Related