Contributors
- Romain Delpoux, 2021.11.04
- Loic Queval, 2021.11.05
- Adrien Prévost, 2021.11.05
- Luiz Villa, 2021.11.07
- Antoine Boche, 2021.11.08
Tutorial Communication
The goal of this tutorial is to use the computer to control to turn the blinking of the LED of the O2 converter on and off. We will start from the Blinky led project. The parts that will be active are shown in the image below.
Required hardware
- O2
v_1_1_2
- STLinkV3
- PC (windows or linux)
- power supply (40 V, 2 A)
Create the project
- We will create the project by copying the blink led project in a new branch, that will be called buck. In the terminal,
- On the bottom menu, check that you are now in the communication branch.
- Check the libraries
In src/main.cpp
, check that we load the owntech.ini libraries and the OS drivers:
//-------------OWNTECH DRIVERS-------------------
#include "opalib_pid_voltage.h"
#include "opalib_quick_start.h"
#include "data_conversion.h"
#include "data_acquisition.h"
//------------ZEPHYR DRIVERS----------------------
#include "zephyr.h"
#include "string.h"
#include "drivers/gpio.h"
#include "sys/printk.h"
#include "console/console.h"
- Define the hardware by software !
In src/main.cpp
, you will find the setup_hardware()
function. Check that we load the version v_1_1_2
of the O2, and the led gpio definition.
opalib_quick_start_set_hardware_version(v_1_1_2);
// LED Initialization
gpio_pin_configure_dt(&led_pin_spec, GPIO_OUTPUT_ACTIVE);
- Define the communication task and the communication menu
In src/main.cpp
, in the function setup_communication_task()
, do not modify anything. This code will link your application task to a thread which will be executed automatically.
In src/main.cpp
, in the function loop_communication_task()
, add the following code to define the communication task. This task listens to the Serial port and changes the system mode depending on the character it has received.
void loop_communication_task(void *arg1, void *arg2, void *arg3)
{
while(1) {
menu();
received_serial_char = console_getchar();
switch (received_serial_char) {
case 'i':
printk("idle mode\n", received_serial_char, received_serial_char);
mode = IDLEMODE;
break;
case 'p':
printk("power mode\n", received_serial_char, received_serial_char);
mode = POWERMODE;
break;
default:
break;
}
}
}
On the top of src/main.cpp
, find the void menu()
function. All the following code to define the menu that will be shown to the user while the program is running.
void menu() {
printk(" _______________________________________\n");
printk("|\t Communication task Tutorial \t|\n");
printk("|\t ------- MENU --------- \t|\n");
printk("|\t press i : idle mode \t\t|\n");
printk("|\t press p : power mode \t\t|\n");
printk("|_______________________________________|\n\n");
}
- Define the application task
In src/main.cpp
, in the function setup_application_task()
, do not modify anything. This task will link your applicaiton task to a thread which will be executed automatically.
In src/main.cpp
, in the function loop_application_task()
, add the following code to define the application task. In this example, it will turn the LED on and off depending on the mode chosen by the user.
void loop_application_task(void *arg1, void *arg2, void *arg3)
{
while(1){
if(mode==IDLEMODE) {
// application loop in idle mode goes here
gpio_pin_set(led_pin_spec.port,led_pin_spec.pin,0);
}else if(mode==POWERMODE) {
// application loop in power mode goes here
gpio_pin_set(led_pin_spec.port,led_pin_spec.pin,1);
}
k_msleep(100);
}
}
- Do nothing for the control task
In src/main.cpp
, do not edit the setup_setup_task()
and loop_control_task()
functions. You will not need them for this example.
- Connect hardware
Now we will connect OwnTech’s O2 to the power supply and to the PC.
- Connect the pins Vhigh and GND of the O2 to the 40 V power supply (set the current limitation at 1 A).
- Connect the micro-JTAG connector of the O2 to the PC thanks to the STLinkV3. The leds PWR and COM should be ON.
- Switch on the power supply. The led2 of the O2 should be ON.
In the bottom menu, click on the Build icon . This will launch the compilation of the code. When the compilation is completed, you should see [SUCCESS] in the terminal.
On the bottom menu, click on the Upload icon . This will flash the compiled code on the microcontroller of the O2. When the process is completed, you should see [SUCCESS] in the terminal.
On the bottom menu, click on the Serial Monitor icon . Should print you a menu for you. Press the
p
button on your keyboard to turn the LED ON and thei
button to turn it OFF.
Expected outputs
- The led1 of the O2 should start as off.
- The led1 of the O2 should turn on when you press the
p
button. - The led1 of the O2 should turn off when you press the
i
button.
That’s it!