This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC1312R: Generating UART callback per 1byte receiving on CC1312R

Guru 16800 points

Part Number: CC1312R

Hello,

Is there any way to generate UART callback per 1byte receiving on CC1312R?

In case of receiving, we could find the triggers of the UART callback are "Receive" and "Receive time-out".
(We're referring 21.4.5 and 21.4.6 in TRM)
And, FIFO has 32-entry and the minimum interrupt trigger level is 1 / 8.
So, we couldn't set the UART module to generate callback per 1byte receiving.
Do you know any idea to solve this requirement?

Best Regards,
Nomo

  • Hi Nomi, 

    Yes, just set read size to 1 and it'll trigger a callback per 1 byte received. Refer to the UART documentation for more information. 

    Thanks, 
    Elin

  • Hi Elin-san,

    Thank you for your reply.
    However, we've already set the read size to 1.
    UART_read(uart, input_data, 1);

    Do you have any idea for this?
    We don't use TI-RTOS.

    Best Regards,
    Nomo

  • Hi Nomo, 

    Okay, so after how many bytes does it trigger a callback? 

    Thanks, 
    Elin

  • Hi Elin-san,

    It seems that 4-byte input triggers a callback.
    Ring Buffer Size = 32
    RX Interrupt FIFO Threshold = 1/8
    Also, in case some bytes remain in FIFO, timeout triggers a callback.

    Best Regards,
    Nomo

  • Hi Nomo, 

    Thanks for sharing. 

    Can you share which example you are using and the minimal code changes required to reproduce this issue? Then I'll try and reproduce this issue on my side. 

    Thanks, 
    Elin

  • Hi Elin-san,

    Thank you for your reply.
    The base example code is uartecho (nortos) in SDK v4.2.
    Could you replace the uartecho.c of the base example code with the attached file?
    We measure the time by observing the input uart signal and the GPIO blink in the Callback function with oscilloscope.

    /*
     * Copyright (c) 2015-2019, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     */
    
    /*
     *  ======== uartecho.c ========
     */
    #include <stdint.h>
    #include <stddef.h>
    
    /* Driver Header files */
    #include <ti/drivers/GPIO.h>
    #include <ti/drivers/UART.h>
    
    /* Driver configuration */
    #include "ti_drivers_config.h"
    
    uint32_t wantedRxBytes = 1;            // Number of bytes received so far
    //uint8_t rxBuf[512];   // Receive buffer
    uint8_t rxBuf[1];   // Receive buffer
    uint8_t txBuf[1];
    uint8_t count = 0;
    
    
    // Read callback function
    void readCallback(UART_Handle handle, void *rxBuf, size_t size)
    {
       size_t i;
       // Make sure we received all expected bytes
       if (size == wantedRxBytes)
       {
           GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
           txBuf[0] = ((uint8_t*)rxBuf)[0];
    
          // Echo the bytes received back to transmitter
    //      UART_write(handle, txBuf, size);
    
          // Start another read, with size the same as it was during first call to
          GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_OFF);
       }
       else {
           // Handle error or call to UART_readCancel()
       }
       UART_read(handle, rxBuf, wantedRxBytes);
    }
    
    
    /*
     *  ======== mainThread ========
     */
    void *mainThread(void *arg0)
    {
        char        input;
        const char  echoPrompt[] = "Echoing characters:\r\n";
        UART_Handle uart;
        UART_Params uartParams;
    
        int i;
    
        rxBuf[0] = 0;
    	txBuf[0] = 0;
    
        /* Call driver init functions */
        GPIO_init();
        UART_init();
    
        /* Configure the LED pin */
        GPIO_setConfig(CONFIG_GPIO_LED_0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    
        /* Turn on user LED */
    //    GPIO_write(CONFIG_GPIO_LED_0, CONFIG_GPIO_LED_ON);
    
        /* Create a UART with data processing off. */
        UART_Params_init(&uartParams);
        uartParams.readMode = UART_MODE_CALLBACK;
        uartParams.readCallback = readCallback;
        uartParams.writeDataMode = UART_DATA_BINARY;
        uartParams.readDataMode = UART_DATA_BINARY;
        uartParams.readReturnMode = UART_RETURN_FULL;
        uartParams.readEcho = UART_ECHO_OFF;
        uartParams.baudRate = 9600;
    
        uart = UART_open(CONFIG_UART_0, &uartParams);
    
        if (uart == NULL) {
            /* UART_open() failed */
            while (1);
        }
    
        UART_write(uart, echoPrompt, sizeof(echoPrompt));
    
        UART_read(uart, rxBuf, 1);
    
        /* Loop forever echoing */
        while (1)
        {
            // UART_read(uart, &input, 1);
            // UART_write(uart, &input, 1);
        }
    }
    

    Best Regards,
    Nomo

  • Hi Nomo, 

    Thanks for the file.

    I don't have access to HW today but I will test tomorrow. 

    In the meantime, can you upgrade to v4.30 SDK and test if you can reproduce the issue? 

    Thanks, 
    Elin

  • Hi Elin-san,

    Thank you for your cooperation.
    We tested this after updating to v4.30 SDK; however, we could reproduce the issue.

    Best Regards,
    Nomo

  • Hi Nomo, 

    Thanks for sharing. 

    I tried to reproduce your issue by importing the CC1312R uartecho example and replacing the uartecho.c file that you attached, but I don't get to the callback function. Can you verify that you are actually reaching the callback function? On my side, the application spinns around in the mainThread while loop that doesn't contain any code. 

    Thank,
    Elin

  • Hello,

    Could you confirm the attached project?
    CCS version: v10.1.0
    CC1312R SDK version: v.4.30

    Of course, you need to send UART signals from the host PC.

    uartecho_CC1312R1_LAUNCHXL_nortos_ccs.zip

    Best Regards,
    Nomo

  • Hi Nomo, 

    Yeah, sorry my mistake. I forgot to change the baudrate on the serial terminal. 

    When debbuging the project now with the correct baudrate, it seems like the project works as expected and a callback is triggered for every character. Do you see something else when debugging? 

    Thanks, 
    Elin

  • Hi Elen-san,

    Thank you for your reply.

    The issue is that the time between the end of uart and the start of callback function is very long (about 3.3 ms).
    We think the the trigger of callback is "Receive time-out"; however, our expectation is that callback is executed immediately after recieving uart .
    So, we want to know the way to shorten the time to callback.

    In the following figure, channel 1 is uart and channel 2 is gpio toggling in the callback function.

    Best Regards,
    Nomo

  • Hi Nomo, 

    The reason why you have to wait for the callback is probably that you are waiting for a read timeout which most likely is caused by the fifo thresholds. How's the fifo configured in your project? 

    Thanks,
    Elin

  • Hi Elin-san,

    Could you confirm the project we've attached previously?

    "Ring Buffer Size" is 32 and "RX interrupt FIFO Threshold" is 1/8.
    Therefore, the interrupt will be generated every 4 bytes receiving.
    Although we set "Ring Buffer Size" to 8, this issue is reproduced.
    We want to know the way to generate interrupt every 1 byte receiving.

    Best Regards,
    Nomo

  • Hi Nomo, 

    Yes, I saw the project you attached in your previous post. 

    If you set the fifo level to the number of bytes, then you'll go directly to the interrupt. If not, it will be some kind of delay before going into the callback function. 

    Thanks, 
    Elin

  • Hi Elin-san,

    Thank you for you reply.
    If we had additional questions, we'll create another post.

    Best Regards,
    Nomo

**Attention** This is a public forum