Tool/software: TI-RTOS
I've trying to get either EUSCI_A1or EUSCI_A3 operational in order to talk to a device that has a UART interface. I've been starting with attempting to get either UART to work in external loopback mode without success. I have been using the TI-RTOS project "uartecho_MSP_EXP430FR5994_TI" as a starting point. I've made the following additions in attempt to get the UARTs operational:
In Board.h I added the following defines:
#define Board_UART1 MSP_EXP430FR5994_UARTA1 #define Board_UART2 MSP_EXP430FR5994_UARTA2 #define Board_UART3 MSP_EXP430FR5994_UARTA3
In MSP_EXP430FR5994.h I added some definitions and changed the definition of the UART init as follows:
/*!
* @def MSP_EXP430FR5994_UARTName
* @brief Enum of UART names on the MSP_EXP430FR5994 dev board
*/
typedef enum MSP_EXP430FR5994_UARTName {
MSP_EXP430FR5994_UARTA0 = 0,
MSP_EXP430FR5994_UARTA1 = 1,
MSP_EXP430FR5994_UARTA2 = 2,
MSP_EXP430FR5994_UARTA3 = 3,
MSP_EXP430FR5994_UARTCOUNT
} MSP_EXP430FR5994_UARTName;
/*!
* @def MSP_EXP430FR5994_UARTEnable
* @brief Enum of UARTs to init GPIO for UART mode
*/
typedef enum MSP_EXP430FR5994_UARTEnable {
MSP_EXP430FR5994_UART0_ENABLE = (1u << 0),
MSP_EXP430FR5994_UART1_ENABLE = (1u << 1),
MSP_EXP430FR5994_UART2_ENABLE = (1u << 2),
MSP_EXP430FR5994_UART3_ENABLE = (1u << 3)
} MSP_EXP430FR5994_UARTEnable;
...
extern void MSP_EXP430FR5994_initUART(unsigned int uartEnable);
And in MSP_EXP430FR5994.c I updated the init as follows:
const UARTEUSCIA_HWAttrs uartEUSCIAHWAttrs[MSP_EXP430FR5994_UARTCOUNT] = {
{
.baseAddr = EUSCI_A0_BASE,
.clockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK,
.bitOrder = EUSCI_A_UART_LSB_FIRST,
.numBaudrateEntries = sizeof(uartEUSCIABaudrates)/sizeof(UARTEUSCIA_BaudrateConfig),
.baudrateLUT = uartEUSCIABaudrates
},
{
.baseAddr = EUSCI_A1_BASE,
.clockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK,
.bitOrder = EUSCI_A_UART_LSB_FIRST,
.numBaudrateEntries = sizeof(uartEUSCIABaudrates)/sizeof(UARTEUSCIA_BaudrateConfig),
.baudrateLUT = uartEUSCIABaudrates
},
{
.baseAddr = EUSCI_A2_BASE,
.clockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK,
.bitOrder = EUSCI_A_UART_LSB_FIRST,
.numBaudrateEntries = sizeof(uartEUSCIABaudrates)/sizeof(UARTEUSCIA_BaudrateConfig),
.baudrateLUT = uartEUSCIABaudrates
},
{
.baseAddr = EUSCI_A3_BASE,
.clockSource = EUSCI_A_UART_CLOCKSOURCE_SMCLK,
.bitOrder = EUSCI_A_UART_LSB_FIRST,
.numBaudrateEntries = sizeof(uartEUSCIABaudrates)/sizeof(UARTEUSCIA_BaudrateConfig),
.baudrateLUT = uartEUSCIABaudrates
}
};
const UART_Config UART_config[] = {
{
.fxnTablePtr = &UARTEUSCIA_fxnTable,
.object = &uartEUSCIAObjects[0],
.hwAttrs = &uartEUSCIAHWAttrs[0]
},
{
.fxnTablePtr = &UARTEUSCIA_fxnTable,
.object = &uartEUSCIAObjects[1],
.hwAttrs = &uartEUSCIAHWAttrs[1]
},
{
.fxnTablePtr = &UARTEUSCIA_fxnTable,
.object = &uartEUSCIAObjects[2],
.hwAttrs = &uartEUSCIAHWAttrs[2]
},
{
.fxnTablePtr = &UARTEUSCIA_fxnTable,
.object = &uartEUSCIAObjects[3],
.hwAttrs = &uartEUSCIAHWAttrs[3]
},
{NULL, NULL, NULL}
};
/*
* ======== MSP_EXP430FR5994_initUART ========
*/
void MSP_EXP430FR5994_initUART(unsigned int uartEnable)
{
if(uartEnable & MSP_EXP430FR5994_UART0_ENABLE)
{
/* P2.0,1 = EUSCI_A0 TXD/RXD */
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,
GPIO_PIN0, GPIO_SECONDARY_MODULE_FUNCTION);
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2,
GPIO_PIN1, GPIO_SECONDARY_MODULE_FUNCTION);
}
if(uartEnable & MSP_EXP430FR5994_UART1_ENABLE)
{
/* P2.5,6 = EUSCI_A1 TXD/RXD */
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P2,
GPIO_PIN5, GPIO_SECONDARY_MODULE_FUNCTION);
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P2,
GPIO_PIN6, GPIO_SECONDARY_MODULE_FUNCTION);
}
if(uartEnable & MSP_EXP430FR5994_UART2_ENABLE)
{
/* P5.4,5 = EUSCI_A2 TXD/RXD */
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P5,
GPIO_PIN4, GPIO_PRIMARY_MODULE_FUNCTION);
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P5,
GPIO_PIN5, GPIO_PRIMARY_MODULE_FUNCTION);
}
if(uartEnable & MSP_EXP430FR5994_UART3_ENABLE)
{
/* P6.0,1 = EUSCI_A3 TXD/RXD */
GPIO_setAsPeripheralModuleFunctionOutputPin(GPIO_PORT_P6,
GPIO_PIN0, GPIO_PRIMARY_MODULE_FUNCTION);
GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6,
GPIO_PIN1, GPIO_PRIMARY_MODULE_FUNCTION);
}
/* Initialize the UART driver */
UART_init();
}
I set it up this way so I can pick and choose which UARTs to enable and disable. I've tried each individually and I have verified to the best of my knowledge that the GPIOs are properly setup for each UART. I then added the following to the TI-RTOS XCD config file:
halHwi.create(24, "&UARTEUSCIA_hwiIntFxn", hwiParams); // UARTA3 halHwi.create(43, "&UARTEUSCIA_hwiIntFxn", hwiParams); // UARTA1
to establish the ISRs for each UART. I then changed the echoFxn task as follows:
Void echoFxn(UArg arg0, UArg arg1)
{
UART_Handle uartLog;
UART_Handle uartLoopback;
UART_Params uartParams;
/* 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;
uartLog = UART_open(Board_UART0, &uartParams);
/* 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;
uartLoopback = UART_open(Board_UART3, &uartParams);
if((uartLog != NULL) && (uartLoopback != NULL))
{
while(1)
{
char c;
char data = 'k';
UART_write(uartLoopback, &data, 1);
UART_read(uartLoopback, &c, 1);
UART_write(uartLog, &c, 1);
}
}
else
{
/* Close either UART if they are open */
if(uartLog != NULL)
{
UART_close(uartLog);
}
if(uartLoopback != NULL)
{
UART_close(uartLoopback);
}
}
}
In this case I am testing loopback on UART3. I have P6.0 and P6.1 jumpered together on the MSP-EXP430FR5994 board. The above code successfully calls UART_write to the loopback UART but will then block indefinitely on UART_read. I've also tried this with UART1, in which case I jumpered P2.5 and P2.6 together on the MSP-EXP430FR5994 board. In either case, I can't transmit out UART1 or UART3 and then read what was sent. What am I missing in my setup for UART1 and UART3?