cancel
Showing results for 
Search instead for 
Did you mean: 

BlueNRG: what HCI Packet Protocol to use over SPI

torsten2
Associate II
Posted on May 05, 2015 at 17:22

Hello,

the Bluetooth Core Specification defines how the different HCI Command, HCI ACL Data and HCI Events are transported over rs232, USB and 3 wire Uart. There is no definition for SPI and unfortunately I was not able to find a way, how the

BlueNRG could differentiate between and HCI Command and HCI ACL Data. How are HCI Commands Packages transported (I don�t mean the framing as defined in Vol. 2 of the BL Spec. but as defined for Uart, USB, etc. in vol. 4 of the BL Spec)?

But first things first: I want to use only the HCI layer of the BlueNRG. I�ve tried to send the HCI_LE_Set_Event_Mask to the BlueNRG. First by sending a write header: 0x0A, 0x00, 0x00, 0x00, 0x00. Doing so in a loop until the BlueNRG response with a header with the SPI READY indication and a write buffer size > 0. This is what I get after a couple of loops : 0x02, 0x00, 0x06, 0x00, 0x00. So there is room for 0x600 Bytes. 

Now I send the HCI_LE_Set_Event_Mask command as following sequence: 0x01, 0x20, 0x08, 0xff, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00. And start to poll the SPI for a response, by sending a read header: 0x0B, 0x00, 0x00, 0x00, 0x00. Doing so in loop until the BlueNRG response with a header with SPI READY indication and a read buffer size > 0. And this loops for ever, as the read buffer remains zero. Event when the HCI Command is not correctly encoded, shouldn�t be there at least some kind of error response?

Are there any examples, that use pure HCI?

Thank you for every feedback,

Torsten

#bluenrg-hci
6 REPLIES 6
torsten2
Associate II
Posted on May 08, 2015 at 18:21

I’ve found some example use of the BlueNRG in the sources on mbed.org (https://developer.mbed.org/teams/ST-Americas-mbed-Team/code/Nucleo_BLE_BlueNRG/). From what I can read there, to write an HCI command, one have to exchange within one transaction the 5 byte header, followed by 0x01 (the

HCI packet indicator as defined for UARTs) followed by the command.

So if I try to send an HCI_Reset, this should be the following byte sequence: 0x01,0x03, 0x0C, 0x00 (HCI_Command, OCF, OGF, parameter size). Right? I’ve put both, the CS line and the irq line on an oscilloscope, I see the CS line toggling, the irq lines stays low for a couple of CS activations then the line goes high and stays high (is the irq signal active high?). But still, the read buffer size stays 0.

To recap, what I’m doing:

I set the CS line to low

send 0x0A, 0x00, 0x00, 0x00, 0x00.

if the first received byte is not 0x02, goto:send 0x0A, 0x00, 0x00, 0x00, 0x00.

if the received write buffer size is smaller than 4 goto:send 0x0A, 0x00, 0x00, 0x00, 0x00.

send0x01, 0x03, 0x0C, 0x00 and ignore the data received

set the CS line to high

set the CS line to low

send 0X0B, 0x00, 0x00, 0x00, 0x00

if the first received byte is not 0x02, goto: send 0x0B, 0x00, 0x00, 0x00, 0x00.

if the received read buffer size is equal to 0 goto: send 0x0B, 0x00, 0x00, 0x00, 0x00.

set the CS line to high

The received response from the BlueNRG is most of the time: 0x02, 0x00, 0x06, 0x00, 0x00 (I’ve found a post on Stackoverflow, indication that at least I’m not the only person who might think that this might be a valid response:http://stackoverflow.com/questions/27053902/unknown-bluenrg-spi-response), the received read size is always zero.

Can anyone see what I’m doing wrong? Or could at least confirm that I’m on the right track?

Thank you very much for taking the time to read this 🙂

Cheers Torsten

P.S: See attached the cs and irq lines (blue == irq)

________________

Attachments :

cs_irq.png : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Ht2h&d=%2Fa%2F0X0000000aJD%2FABM_KPHi3Z4krtEcW7sw.G.25C7vrHa6Dx1qh5f8aQ8&asPdf=false
torsten2
Associate II
Posted on May 09, 2015 at 20:12

It seems that my SPI implementation has a problem and some bytes get lost. So the observed sequence above is not correct.

Posted on May 11, 2015 at 12:18

Hi Torsten,

about SPI doc you can see the doc UM1755 section

5) SPI interface.

At the following link:

http://www.st.com/web/catalog/tools/FM147/SC1870/PF261967?s_searchtype=partnumber

#

you can download the DK 1.7.0 that contains some example projects that show how to use the BlueNRG device.

Regards,

GM

torsten2
Associate II
Posted on May 11, 2015 at 12:40

Hello Graziella,

thank you very much for taking the time to look into this!

about SPI doc you can see the doc UM1755 section 

5) SPI interface.

I've read that chapter several times to see if I'm missing something. The problem was not in implementing that protocol, but with my low level SPI implementation. I've asked in the STM32 forum, what was wrong with it. Maybe you have some time to look at it and to shed some light on it.

Unfortunately, I can download that sdk, but it's an self extracting windows archive and I do not work on windows. I ''fixed'' my SPI implementation and now I'm able to communicate with the BlueNRG.

kind regards,

Torsten
Posted on May 11, 2015 at 12:50

Hi Torsen,

in attach a zip with the main files of DK.

Regards,

GM

________________

Attachments :

BlueNRG_DK_1.7.0.7z : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Ht2m&d=%2Fa%2F0X0000000aJE%2FAwFD2pf7mziitEbYyW6j9xaj4OiuQhJBw8EIkKfyFGc&asPdf=false
torsten2
Associate II
Posted on May 11, 2015 at 13:00

Hello Graziella,

thank you very much!

cheers,

Torsten