-
Notifications
You must be signed in to change notification settings - Fork 0
Cpp Lab Tutorial
Goal: This tutorial is for the students of the C/C++ Lab at TU Darmstadt. In this tutorial you will install the ABLE app on an Android smartphone and connect it via Bluetooth Low Energy (BLE) to the evaluatoin board of the C/C++ Lab.
- Download the latest ABLE APK here and install it on your Android smartphone.
- You may need to allow for installing external apk files (see here for detailed instructions in German)
- Install and run the Cypress Serial Port Viewer from here.
- Connect BLE module to your microcontroller.
- Open the Cpp Lab template in winIDEA (see
exercises/templates/
).
The Cpp Lab microcontroller uses a BLE module which is connected via a 10 pin connection to the microcontroller. The data are exchanged between FM4 microcontroller and BLE module via the serial interface (UART). In the following, you will implement a small application that shows all input You are going to implement a communication between the micrcontroller and your computer via UART USB. As a result your final program will print everything you write on your pc keyboard on the Cpp Lab board.
Your PC is connected via USB to the FM4 microcontroller and the USB port of the FM4 microcontroller has the option to be controlled via UART. The C/C++ Lab library provides you with two convenient functions to initialize and start the UART interface.
- Include the header
lib\uart_usb.h
into themain.c
file of your project. - After the usual invocation of
initBoard()
, insert an invocation of the functionUART_USB_Init()
to initialize theUART0
port of the microcontroller, which is responsible for the connection to your PC. - Next, add a call to
UART_USB(void)
, which continuously displays all characters received via UART0. Your code should look like this.
#include "init.h"
#include "uart_usb.h"
int main(){
initBoard();
UART_USB_Init();
UART_USB();
return 0;
}
- Flash your code to the FM4 microcontroller.
- Open the
Cypress Serial Port Viewer
, set the baud rate to115200
, and click on the buttonDisconnected
. If the connection was successful you should be able to write text in the Serial Port Viewer window and the see the same text on your PC screen and on the touchscreen LCD of the C/C++ board.
In this part, your will set up the UART connection between the FM4 microcontroller and the BLE module.
The BLE module is connected to the multicon interface of the FM4 microcontroller.
To write data to the BLE module, you need to use UART3
on the FM 4 microcontroller as follows.
- Start with a fresh
main
function. - Insert the usual invocation of
initBoard()
(headerinit.h
). - Include the library
lib\uart_multicon.h
in yourmain.c
and use the functioninitUART3()
to initialize UART3. - With the function
void uartMulticonWrite(uint8_t data)
, you can send 8 bits to the BLE module. Create a variableuint8_t testData = 188;
and pass it touartMulticonWrite
. Your final code should look like this.
#include "init.h"
#include "uart_multicon.h"
int main(){
initBoard();
initUART3();
uint8_t testData = 188;
while(1) {
uartMulticonWrite(testData);
}
return 0;
}
- Compile your code and flash it on the microcontroller.
- Start the ABLE app on your smartphone and activate Bluetooth & location services.
- Start the scan and wait for it to complete.
- Connect to your microcontroller. It should have the name
Cppp #[ID]
(e.g.,CPPP #4
). - Now you should be able to read the value you have set in
testData
on your smartphone. If the value changes permanently inside thewhile
loop, enable notifications in the app.
Based on your knowledge of the C/C++ evaluation board, you can now extend your current FM4 code, e.g., to send the current X and Y value of the joysticks or the X, Y, and Z value of the current touch point of the touchscreen LCD.