am13e23019-uart-console.ino

BeagleConnect QuadESC: 4-Channel BLDC Controller · File : am13e23019-uart-console.ino · Language : C · Use case : Mettre en place une console série pour le débogage et l'envoi de commandes.

Implementation of an interactive serial interface for real-time diagnostics of motors and sensors.

Uses the UART driver from the SDK. Connect a USB-TTL adapter to the Torque module's UART pins. Set the terminal to 115200 baud. Allows querying the status of DRV8323S drivers.

am13e23019-uart-console.ino

#include <ti/drv/uart/UART.h>
#include <ti/drv/uart/UART_stdio.h>
#include <string.h>

#define BUFFER_SIZE 64
char rxBuffer[BUFFER_SIZE];

void uart_console_task(void) {
    UART_Handle uart;
    UART_Params uartParams;

    UART_Params_init(&uartParams);
    uartParams.writeDataMode = UART_DATA_BINARY;
    uartParams.readDataMode = UART_DATA_BINARY;
    uartParams.readReturnMode = UART_RETURN_FULL;
    uartParams.readEcho = UART_ECHO_OFF;
    uartParams.baudRate = 115200;

    uart = UART_open(UART_INSTANCE_0, &uartParams);
    if (uart == NULL) {
        while (1);
    }

    UART_stdioInit(UART_INSTANCE_0);
    UART_printf("Console prête. Tapez une commande:\n");

    while (1) {
        int bytesRead = UART_read(uart, rxBuffer, BUFFER_SIZE);
        if (bytesRead > 0) {
            rxBuffer[bytesRead] = '\0';
            if (strcmp(rxBuffer, "status") == 0) {
                UART_printf("Système OK\n");
            } else {
                UART_printf("Commande inconnue: %s\n", rxBuffer);
            }
        }
    }
}

← Back to the board