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.

MSP432P401R: UART_read() not working when called from GPIO Button ISR.

Part Number: MSP432P401R

Hello There,

I have set up UART with following settings

writeDataMode = UART_DATA_TEXT;
readDataMode = UART_DATA_TEXT;
readReturnMode = UART_RETURN_NEWLINE;
readEcho = UART_ECHO_OFF;
baudRate = 115200;
readTimeout = 200;
writeTimeout = 400;

I'm facing issue when I'm trying to read some uart data from GPIO Button ISR.

When there is no data available to be read and whenever UART_read(uartA2Handle, input, sizeof(input)) from Button ISR tries to read, it's returning the size of input buffer and every index of buffer is holding the '0X0E'. Rather it should return zero.

It's working perfectly when called from a TASK .

See the below code for details.

 *  ======== gpioButtonFxn0 ========
 *  Callback function for the GPIO interrupt on Board_GPIO_BUTTON0.
 */
void gpioButtonFxn0(uint_least8_t index)
{
    char input[100];
    int rxlen = 0;

    memset(input, 0, sizeof(input));

    /* Clear the GPIO interrupt and toggle an LED */
    GPIO_toggle(Board_GPIO_LED0);

    rxlen = UART_read(uartA2Handle, input, sizeof(input));  //here rxlen comes to 100 still when there is no data available to read.
    while(1);
}

/*
 *  ======== mainThread ========
 */
void *mainThread(void *arg0)
{
    /* Call driver init functions */
    GPIO_init();
    UART_init();

    uartA2Params.writeDataMode = UART_DATA_TEXT;
    uartA2Params.readDataMode = UART_DATA_TEXT;
    uartA2Params.readReturnMode = UART_RETURN_NEWLINE;
    uartA2Params.readEcho = UART_ECHO_OFF;
    uartA2Params.baudRate = 115200;
    uartA2Params.readTimeout = 200;
    uartA2Params.writeTimeout = 400;

    uartA2Handle = UART_open(Board_UART1, &uartA2Params);
    if (uartA2Handle == NULL)
    {
        /* UART_open() failed */
        while(1);
    }

    /* Configure the LED and button pins */
    GPIO_setConfig(Board_GPIO_LED0, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    GPIO_setConfig(Board_GPIO_LED1, GPIO_CFG_OUT_STD | GPIO_CFG_OUT_LOW);
    GPIO_setConfig(Board_GPIO_BUTTON0, GPIO_CFG_IN_PU | GPIO_CFG_IN_INT_FALLING);

    /* Turn on user LED */
    GPIO_write(Board_GPIO_LED0, Board_GPIO_LED_ON);

    /* install Button callback */
    GPIO_setCallback(Board_GPIO_BUTTON0, gpioButtonFxn0);

    /* Enable interrupts */
    GPIO_enableInt(Board_GPIO_BUTTON0);


    sleep(2);

    char input[100];
    int rxlen = 0;
    memset(input, 0, sizeof(input));

    /* Clear the GPIO interrupt and toggle an LED */
    GPIO_toggle(Board_GPIO_LED0);

    rxlen = UART_read(uartA2Handle, input, sizeof(input));  //here rxlen comes to zero after UART_read() when there is no data to read.
    while(1);

    return (NULL);
}

Regards,

Keshav Aggarwal

**Attention** This is a public forum