element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Test & Tools
  • Technologies
  • More
Test & Tools
Blog Programmable Electronic Load - UART
  • Blog
  • Forum
  • Documents
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Test & Tools to participate - click to join for free!
  • Share
  • More
  • Cancel
Group Actions
  • Group RSS
  • More
  • Cancel
Engagement
  • Author Author: Jan Cumps
  • Date Created: 10 Oct 2020 9:05 AM Date Created
  • Views 947 views
  • Likes 1 like
  • Comments 0 comments
  • uart
  • msp432
  • ti_rtos
  • launchpad
Related
Recommended

Programmable Electronic Load - UART

Jan Cumps
Jan Cumps
10 Oct 2020

This blog documents focuses on the UART approach for the electronic load that Robert Peter Oakes, jc2048 and Jan Cumps designed.

UART combined with SCPI are the programming interface for the instruments.

imageimage

 

UART

 

Info: initial design used UART1 as 2nd option. When switching to the Red MSP432 LaunchPad, this switched to UART6.

Where you see UART1, think UART6.

 

UART module if USB UART0

9600/8/1/N

 

UART module if TTL UART6

115200/8/1/N

 

The project uses uses the TI-RTOS UART driver.

Buffered output for transmit

Interrupt driven for receive, wake up RTOS task (with semaphore) whenever a character arrives on the Rx line.

 

void *threadUART(void *arg0)
{
    char        input;
    UART_Params uartParams;
    int iError;

    /* Call driver init functions */
//    GPIO_init();
    UART_init();

    /* Configure the LED pin */
    GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);

    /* Create a UART with data processing off. */
    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 = 9600;
    uartParams.readMode = UART_MODE_CALLBACK; // the uart uses a read interrupt
//    uartParams.readCallback = &UART00_IRQHandler; // function called when the uart interrupt fires

#ifdef SCPI_UART_0
    uartParams.baudRate = 9600;
    uartParams.readCallback = &UART00_IRQHandler; // function called when the uart interrupt fires
    uart = UART_open(Board_UART0, &uartParams);
#else
#ifdef SCPI_UART_6
    uartParams.baudRate = 115200;
    uartParams.readCallback = &UART00_IRQHandler; // function called when the uart interrupt fires
    uart = UART_open(Board_UART6, &uartParams);
#else
#error "define a valid UART"
#endif
#endif

    if (uart == NULL) {
        /* UART_open() failed */
        while (1);
    }

 

The interrupt is very simple. It posts a semaphore to flag our UART task that we have a character on the receive line.

 

void UART00_IRQHandler(UART_Handle handle, void *buffer, size_t num)
{
    sem_post(&SEM_uart_rx);
}

 

There are 2 touchpoints with the SCPI interpreter. UART module knows about SCPI lib. SCPI is UART-unaware.

  • initialises the SCPI lib (is that smart? *) with scpi_instrument_init() edit: moved to main().
  • each character received directly sent to SCPI lib with scpi_instrument_input().

 

    while (1) {
        UART_read(uart, &input, 1);
        iError = sem_wait(&SEM_uart_rx); // when a character is received via UART, the interrupt handler will release the binary semaphore
        while (iError) {
            // POSIX reported error with semaphore. Can't recover.
        }
        // in my case: I get an interrupt for a single character, no need to loop.
        GPIO_toggle(Board_GPIO_LED1); // LED B - visual clue that we've received a request over USB
        scpi_instrument_input((const char *)&input, 1);
        GPIO_toggle(Board_GPIO_LED1); // LED B - visual clue off
    }

 

  • SCPI lib uses SCPI_Write() to send info to UART (although the SCPI lib isn't aware of that. The linker resolves this dependency. The only thing that the SCPI lib requires is that "there is a function named SCPI_Write()" somewhere).

 

size_t SCPI_Write(scpi_t * context, const char * data, size_t len) {
    (void) context;
    GPIO_toggle(Board_GPIO_LED1); // LED B - visual clue that we send a reply over USB
    UART_write(uart, data, len);
    GPIO_toggle(Board_GPIO_LED1); // LED B - visual clue offB
    return len;
}

 

compile option to choose the UART:

SCPI_UART_0

SCPI_UART_6

 

Undefining SCPI_UART_6 and defining SCPI_UART_0 enables UART0 (USB debug port)

Undefining SCPI_UART_0 and defining SCPI_UART_6 enables UART6 (TTL 3V3)

It allows to select the port without code changes.

 

#ifdef SCPI_UART_0
    uart = UART_open(Board_UART0, &uartParams);
#else
#ifdef SCPI_UART_1
    uart = UART_open(Board_UART1, &uartParams);
#else
#error "define a valid UART"
#endif
#endif

 

 

image

 

 

image

  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube