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.
Part Number: MSP432P401R
Tool/software: Code Composer Studio
I am wondering if my code for a UART RX interrupt is correct. I got to this point by scouring the UART.h file for info. The code works fine, it just seems weird that I must have the UART_read() function in the while loop for it to work properly. I have made sure that the UART_read() function doesn't block and the while(1) loop can continue. Please see my code below...
Thank you!
/* * 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> #include <unistd.h> /* Driver Header files */ #include <ti/drivers/GPIO.h> #include <ti/drivers/UART.h> /* Driver configuration */ #include "ti_drivers_config.h" static char response; void readCallback(UART_Handle uartHandle, void *response, size_t count) { GPIO_toggle(CONFIG_GPIO_LED_0); } /* * ======== mainThread ======== */ void *mainThread(void *arg0) { UART_Handle uart1; UART_Params uartParams1; /* 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(&uartParams1); uartParams1.readMode = UART_MODE_CALLBACK; uartParams1.writeMode = UART_MODE_BLOCKING; uartParams1.readTimeout = UART_WAIT_FOREVER; uartParams1.writeTimeout = UART_WAIT_FOREVER; uartParams1.readCallback = readCallback; uartParams1.writeCallback = NULL; uartParams1.readReturnMode = UART_RETURN_FULL; uartParams1.readDataMode = UART_DATA_BINARY; uartParams1.writeDataMode = UART_DATA_BINARY; uartParams1.readEcho = UART_ECHO_OFF; uartParams1.baudRate = 115200; uartParams1.dataLength = UART_LEN_8; uartParams1.stopBits = UART_STOP_ONE; uartParams1.parityType = UART_PAR_NONE; uart1 = UART_open(CONFIG_UART_1, &uartParams1); if (uart1 == NULL) { /* UART_open() failed */ while (1); } while (1) { UART_read(uart1, &response, 1); } }
You are right. You can refer to our code example.
UART.c will call the functions in this file:
at 432 line, you can find this code, which means create an interrupt.
object->hwi = HwiP_create(hwAttrs->intNum, UARTMSP432E4_hwiIntFxn,
¶msUnion.hwiParams);
If I understand correct, the TI-driver will handle the interrupt for you as well.
Hi Eason,
Thank you for your reply. Please excuse me, for I'm not sure what example code you were referring to or where to find the line 432. The examples for the MSP432E4 seem to be the same as the MSP432p401r. I do see that the code snippet you pasted shows an initialization of the UART peripheral as I have on line 92 of the code I pasted earlier.
From your first statement, I do understand that what I have is correct.
Much appreciated,
Mark
**Attention** This is a public forum