While I developed the beacon project, and the toggle led project modifications, I was debugging using a single LED to represent whether a line of code was reached, or whether a return code was zero. I decided to take a day to learn how to wire up a proper serial console for "println" debugging.
- All parts from programming.md - The BLE board, CC Debugger, Bluegiga Tools, License Key.
- A USB to serial adapter. I'm using the FTDI Friend from adafruit
- Four male to male jumper cables to connect your BLE board to the adapter
- A serial terminal. I'm using RealTerm
- The official [FTDI VCP driver] (http://www.ftdichip.com/Drivers/VCP.htm) - The automatically installed Windows Update one is not the correct driver. Remember to right-click, Run as Administrator on the extracted driver.
- Peripheral Pinout from the BLE112 datasheet, Page 8. Under Data Sheets, once you log in using the gear in the top-right corner. Here is an older, public datasheet with the same info, less clearly laid out: old BLE112 datasheet, Page 9.
Here is the BLE Breakout Pinout, with the 6 CC Debugger Pin numbers outlined in green, and the 4 Serial Pins outlined in purple:
This configuration is USART Channel 1 Alternate 1, shown on Page 8 of the datasheet.
BLE Pin | BLE Name | FTDI Name | FTDI Color | Notes |
---|---|---|---|---|
P0_2 | CT | RTS | Green | |
P0_3 | RT | CTS | Brown | |
P0_4 | TX | RX | Yellow | |
P0_5 | RX | TX | Orange | |
GND | GND | Black | Optional | |
VCC | Red | N/C |
Each pin on the BLE side is matched to its corresponding pin on the FTDI (computer) side, so transmit on the device is matched to receive on the FTDI.
I have consolidated bits of helpful code and advice from a few different sources:
- Advice and bluegiga sample project: http://www.ambientsensors.com/bluetooth-low-energy-projects/
- Additional information http://www.sureshjoshi.com/development/ble112-uart-watermarks-example/
In project.xml
, the usart hardware configuration is defined:
<usart channel="1" alternate="1" baud="115200" endpoint="none" />
Refer to the "Bluetooth Smart Configuration Guide", Page 19, which can be found in the bluegiga documents section. The first two settings are relevant to the pins you use on the board, and the endpoint constant you use in BGScript. The rest of the options are relevant for setting up RealTerm.
- Channel: 1
- Alternate: 1
- Baud: 115200
- Hardware flow control: true (default), means CTS/RTS lines are connected and enabled
- Stop bits: 1 (default)
- Data bits: 8 (cannot be changed)
- Parity: none (cannot be changed)
In serial_debug.bgs
, the correct endpoint is set:
endpoint = system_endpoint_uart1
And the string is sent over the wire:
call system_endpoint_tx(endpoint, 11, "\n\rBooted!\n\r")(result)
Note that you need to indicate the length of the value you are sending over the wire! Any string manipulation will have to be done manually on the buffer. I included a few lines of gross int-to-string conversion code, since I expect that to be useful for future projects.
Once you hook up the serial lines, and program the device using the bgbuild.exe
on the project.xml
file in this directory, you should see a counter that increments every second:
Take a look at the RealTerm settings I have in the screenshot if you are having trouble. My FTDI Friend registered as COM3, which is why my port is set to 3. You can find your COM port under Device Manager in Windows if you expand the "Ports (COM & LPT)" section.