0

BLE SPI Friend quetions
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

BLE SPI Friend quetions

by davidmcq137 on Sun Feb 10, 2019 4:28 pm

Hi all,

I have a bluefruit SPI friend and would like to use it with one iof my ESP8266/Huzzah boards running Lua with nodemcu. I see you have libraries for Arduino and while I am not asking for that level of support for Lua, I do need some basic information to get me started.

I have a lot experience with the 8266 and nodemcu now, this is the first time I've had any issues getting it to work as desired.

I also purchased the UART version of the BLE friend, and that works perfectly. I've noted from the 3 flashes on the SPI card once connected to your iphone app, so that it must wake up in AT command mode.

At the very least I'd like to be able to talk to it in AT mode and eventually put it in transparent "uart" mode to act as a data pipe. I've done this without and issue over serial with the UART module but so far cannot even get an AT command to respond on the SPI.

The nodemcu library has some basic spi calls (read and write), and I've done the setup with a clock divider of 20 (80MHz is the base clock on the 8266 SPI, I see on your site the BLE friend only supports 4MHz .. hence the 20. I am using CPOL-LOW and CPHA_LOW (I've tried all combinations and that does not seem to be the problem).

Does the SPI friend wake up in slave mode? I am assuming/hoping that since the 8266 with nodemcu only supports being a master.

Any clues you can offer on how to talk SPI to the BLE SPI friend from the 8266 are most welcome!

here is a snip of the setup and an attempt at a command.. I am reading the "interrupt" pin of the BLE breakout with gpio2.

Code: Select all | TOGGLE FULL SIZE
spi.setup(1, spi.MASTER, spi.CPOL_LOW, spi.CPHA_LOW, 8, 20, spi.HALFDUPLEX)
gpio.mode(2, gpio.INPUT)

k=spi.send(1, "A","T","I", 13, 10)
print("sent", k)
rr = spi.recv(1, 2)
for i=1,2,1 do
   print(i, string.byte(rr, i))
end


I have tried various alternatives such as sending the characters as 8-bit ints (e.g. 65 instead of "A") to no avail.

thanks
Dave M

davidmcq137
 
Posts: 11
Joined: Wed Dec 12, 2018 11:38 am

Re: BLE SPI Friend quetions

by ktownsend on Mon Feb 11, 2019 3:10 pm

There are some details on the protocol used over SPI here: https://learn.adafruit.com/introducing- ... -transport

I don't have a reference for Lua, but here is a reference implementation for CircuitPython talking to the Bluefruit SPI friend using the protocol above, which may help: https://github.com/adafruit/Adafruit_Ci ... uefruitSPI

Hope this helps!

ktownsend
 
Posts: 1447
Joined: Thu Nov 05, 2009 2:18 am

Re: BLE SPI Friend quetions

by davidmcq137 on Mon Feb 11, 2019 8:23 pm

Many thanks! I'll have a look and if I get it going I can post the results back here if that could help others.

Dave

davidmcq137
 
Posts: 11
Joined: Wed Dec 12, 2018 11:38 am

Re: BLE SPI Friend quetions

by davidmcq137 on Wed Feb 20, 2019 10:54 pm

Hi Kevin.

I was able to use your docs and python code to create a working port that talks to the BLE SPI friend on an 8266/Huzzah module running with the nodemcu environment and in lua. Wow .. that was a LOT of work .. when you need emacs and a digital sampling scope on the same desk you know it's going to be fun (!). I am doing some further testing and refinement but I wanted to thank you for providing the essential docs (I know both were out in public but I had not found them!) that allowed this to work.

I could smell trouble when I saw some of your debug print statements having balancing time delays for debugging on and off .. I tried to identify the critical elements of timing and
some of the limits where the code breaks. I also had to implement a "manual" chip select .. the nodemcu library has an spi module and it supplies cs signals itself but they were too tight in timing for the BLE friend ... using the 100 usec values in the SDEP docs works fine. It's running at 4MHz clock speed like your python version. I did simplify and non-OO-ify the code (I apologized for this in the comments!) . Lua does have such capabilities but not as well-used as they are in Python.

I am more than happy to share what I have with anyone else who might benefit from it once I have it tidied up a bit more.

Dave

davidmcq137
 
Posts: 11
Joined: Wed Dec 12, 2018 11:38 am

Re: BLE SPI Friend quetions

by ktownsend on Thu Feb 21, 2019 4:04 am

Glad to hear you got this working, and please do share the results when you feel they're ready!

ktownsend
 
Posts: 1447
Joined: Thu Nov 05, 2009 2:18 am

Please be positive and constructive with your questions and comments.