Example based on Ubuntu
Prerequisites: minicom terminal emulator If the program is missing, install it with: sudo apt-get install minicom
Connect the microcontroller to a USB-COM converter and check if it was detected by the system: dmesg | grep tty
the result could look like this:
[ 0.000000] console [tty0] enabled [ 3823.820524] usb 5-1: pl2303 converter now attached to ttyUSB0 [ 3937.382589] usb 5-2: FTDI USB Serial Device converter now attached to ttyUSB1 [ 4152.680434] pl2303 ttyUSB0: pl2303 converter now disconnected from ttyUSB0 [ 4159.873377] ftdi_sio ttyUSB1: FTDI USB Serial Device converter now disconnected from ttyUSB1 [ 4164.285887] usb 5-2: FTDI USB Serial Device converter now attached to ttyUSB0 [ 4215.343098] usb 5-1: pl2303 converter now attached to ttyUSB1 [ 4633.056395] pl2303 ttyUSB1: pl2303 converter now disconnected from ttyUSB1 [ 4659.016240] usb 5-1: pl2303 converter now attached to ttyUSB1
From this output you need to determine which port is assigned to the USB converter.
When the example code is loaded into the microcontroller, open minicom (preferably with root permissions): sudo minicom -s
First you need to configure the connection:
To set the port, press key A and set the connection, for example: /dev/ttyUSB1 and the port parameters Bps/Par/Bits, for example: 115200 8N1 Press ESC to exit.
After selecting Exit, minicom initializes the port connection.
The microcontroller must be connected to the computer's USB converter using a cross cable (also known as a 0-modem cable).
The program below responds to every symbol received on the UART port with a greeting and toggles the LED on the board.
If you want to see your own keypresses, enable local echo: CTRL+A E
#include <homelab/usart.h> #include <homelab/delay.h> #include <homelab/pin.h> usart port = USART(0); //COM connector pin led = PIN(B, 7); //red LED on controller board int main (void) { char c; pin_setup_output(led); //set led as output usart_init_async(port, //USART setup USART_DATABITS_8, USART_STOPBITS_ONE, USART_PARITY_NONE, USART_BAUDRATE_ASYNC(115200)); while (1) //infinite loop { //if char is sent to controller, read it into c if (usart_try_read_char(port, &c)) { //invert LED pin_toggle(led); // Write some greetings usart_send_string(port, "Tere volts!\r\n"); } } }