Go Down

Topic: BGLib Arduino library for Bluegiga BLE112 Bluetooth Low Energy module (Read 14 times) previous topic - next topic

Jeff Rowberg

Hey everyone,

I just posted the first release of an Arduino implementation of BGLib, the binary protocol used to interface with the Bluegiga BLE112 Bluetooth Low Energy module. I also sell a breakout board for this module if you're interested in prototyping with it.

BGLib is a typical event-driven protocol; it has commands, responses, and events. All of these are documented in detail (though short on examples) in Bluegiga's API reference manual, and Bluegiga even provides a sample ANSI C implementation of BGLib. However, it is a little bit more complicated to use than I prefer, so rather than porting everything, I wrote this one to be more consistent with how I like to write libraries. It's still not commented very well, but it's pretty basic and the currently included demo sketch makes for a decent quick-start guide. Here's a basic synopsis:

Commands are pre-defined in the library. They take individual parameters according to the API docs. (I did keep the exact command names and parameter structures the same so that the Bluegiga API docs would still apply.)

Responses are defined as function pointers with no default implementation. They don't need to be defined, but you can supply your own handlers if you want. Responses typically come back right after commands are issued, but there is some tiny delay sometimes, so for ultimate efficiency they had to be implemented as callbacks (or ignored). Response callbacks left undefined are ignored whenever they occur.

Events are also defined as function pointers with no default implementation. Event function pointers which are not set to real functions are simply ignored whenever they occur. Events may happen at any time based on module configuration.

You can see the demo BGLib_scanner.ino sketch here to see this architecture in action. This demo is built for the Arduino Uno, set to have the PC connected to the hardware serial port and the BLE112 connected to a SoftwareSerial port running at 9600 baud on pins 2 and 3.

TheBarrelShifter

Hi Jeff,

Thanks for that, really useful.
I've been experimenting a bit, I'm using USART 0 rather than one on pins P1_4 & P1_5. According to the spec, there is a special 'packet' mode that can be defined in the hardware.xml for using BGApi over a serial port without flow control. It just requires adding a length byte to the start of the command - I added this to your code and it seems to work fine.
I'm wondering about using BGApi over SPI, as the docs suggest this is possible, however it's not clear to me how this would be achieved in terms of which end is master and which end is slave, and how the slave end sends data when the master end isn't clocking any across.

Toby

TheBarrelShifter

Just heard back from BlueGiga support:

"Hello,

BGAPI is not supported over SPI at the moment, you can use this over UART and USB at this time. SPI can support things like sensors and displays for now.

Best regards,

Sam Pullen"

It would help if the BlueGiga docs were consistent - Various diagrams etc show BGAPI being connected to a microcontroller via SPI.


Jeff Rowberg

I haven't tried that method (BGAPI over SPI) personally yet, though from a hardware standpoint, the CC2540 should technically be able to do it. Maybe the BLE112's custom stack just doesn't support it. Where in the docs have you seen the diagram that suggests otherwise?

Keano16

Hi Jeff,

I was wondering what kind of "hardware flow control issues" you are having with the BLE112? I am working with this device on the MSP430 and I am also seeing some hardware flow control problems. Specifically the BLE does not ever assert the CTS line to throttle the MSP430 and the buffer overflows almost immediately. I am transmitting at 115200 baud. Also I have seen DMA recommended for the CC2540 at these baud rates, but there does not appear to be any way to explicitly enable this using the Bluegiga API (unless it occurs automatically in the Bluegiga SW for this setting).

With regard to SPI connectivity, I also tried to implement this based on the documentation from Bluegiga, but got very odd responses on the scope. I eventually contacted Bluegiga and received the same response as TheBarrelShifter, above i.e. it is not implemented yet. The diagrams in the API_53 guide (pg 8), BLE_Stack_API_reference_v1.3 (also pg 8.), BLE_getting_started_v1.3 (pg 15), etc all show an SPI interface between the host and the BGAPI protocol.

Go Up