The CSR1011 is a single mode Bluetooth Smart chip and this tutorial show how to access its GPIOs and read the values of a ultrasonic sensor.
Step 1: Ultrasonic Sensor
The ultrasonic sensor used was the HC-SR04. To begin the measurement it is necessary to power the module and place the Trigger pin at high level for more than 10us. Thus the sensor will emit a sound wave that when finding an obstacle will rebound back towards the module, being that at this time of emission and reception of the signal the ECHO pin will be at high level. Thus the distance calculation can be done according to the time when the ECHO pin remained high after the Trigger pin has been placed high.
Step 2: Hardware Scheme
To connect the ultrasonic sensor in the CSR1011 was designed a hardware to power it, because the CSR1011 is powered with 3v3 and the component needs 5v to work. On CSR the pin 15 (GPIO 18) was used to connect the Trigger of the sensor and the pin 17 (GPIO 19) was used to connect the Echo of the sensor.
Step 3: Installing the CSR UEnergy SDK
To handle application on CSR1011 is used the Integrated Development Environment (xIDE) supplied with μEnergy Software Development Kits (SDKs). The software is provided on the CD-ROM but can also be downloaded from here.
Step 4: Software Architecture
On CSR1011 the application communicates with firmware using API calls that are implemented using firmware callbacks for various events in the application life cycle. When a project is created some functions are already implemented, this functions are used in the life cycle of the application:
- AppPowerOnReset(): Application function called just after a power-on reset;
- AppInit(): This function is called every boot and should contain application initialisation;
- AppProcessSystemEvent(): Function called by firmware to process system-level events, like Low battery and PIO level change;
- AppProcessLmEvent(): Function used to handles communication link-related events from firmware;
- Timers: Run on top of the hardware timer with microsecond accuracy.
Step 5: Code Example to Read the Values of Sensor Measurement
The code available demonstrates how to configure and get the values measured of the ultrasonic sensor plugged in the gpio of CSR1011. To handle the access of the gpios and timer measument were used functions availables on pio.h and timer.h libraries on group__PIO__B.html and group__TIME.html at uEnergy SDK. To see the sensor measuremet, use a serial program (E.g: PuTTy), the only configuration needed is set up the COM and set up the bound rate to 2400.