我想同时使用MSP432E4的多个UART串口模块,希望您可以帮忙解答以下问题。
首先我查阅了手册中的引脚号,uart7对应的是PC4,PC5吗?
其次我基于TI DRIVER库函数修改了uart7,但是没有任何数据传输,不知道代码有什么问题?
库函数中使用串口UART0,1是可以正常收发数据的,排除硬件连接错误。
您能否提供除串口UART0,1,2外其他串口模块的例程?
代码附下:
#include <stdint.h>
#include <stdbool.h>
#include "ti/devices/msp432e4/driverlib/driverlib.h"
#ifdef DEBUG
void
__error__(char *pcFilename, uint32_t ui32Line)
{
}
#endif
void
UART7_IRQHandler(void)
{
uint32_t ui32Status;
//
// Get the interrrupt status.
//
ui32Status = MAP_UARTIntStatus(UART7_BASE, true);
//
// Clear the asserted interrupts.
//
MAP_UARTIntClear(UART7_BASE, ui32Status);
//
// Loop while there are characters in the receive FIFO.
//
while(MAP_UARTCharsAvail(UART7_BASE))
{
//
// Read the next character from the UART and write it back to the UART.
//
MAP_UARTCharPutNonBlocking(UART7_BASE,
MAP_UARTCharGetNonBlocking(UART7_BASE));
//
// Blink the LED to show a character transfer is occuring.
//
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, GPIO_PIN_0);
//
// Delay for 1 millisecond. Each SysCtlDelay is about 3 clocks.
//
SysCtlDelay(g_ui32SysClock / (1000 * 3));
//
// Turn off the LED
//
GPIOPinWrite(GPIO_PORTN_BASE, GPIO_PIN_0, 0);
}
}
void
UARTSend(const uint8_t *pui8Buffer, uint32_t ui32Count)
{
//
// Loop while there are more characters to send.
//
while(ui32Count--)
{
//
// Write the next character to the UART.
//
MAP_UARTCharPutNonBlocking(UART7_BASE, *pui8Buffer++);
}
}
int
main(void)
{
//
// Set the clocking to run directly from the crystal at 120MHz.
//
g_ui32SysClock = MAP_SysCtlClockFreqSet((SYSCTL_XTAL_25MHZ |
SYSCTL_OSC_MAIN |
SYSCTL_USE_PLL |
SYSCTL_CFG_VCO_480), 120000000);
//
// Enable the GPIO port that is used for the on-board LED.
//
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPION);
//
// Enable the GPIO pins for the LED (PN0).
//
MAP_GPIOPinTypeGPIOOutput(GPIO_PORTN_BASE, GPIO_PIN_0);
//
// Enable the peripherals used by this example.
//
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7);
MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
//
// Enable processor interrupts.
//
MAP_IntMasterEnable();
//
// Set GPIO A0 and A1 as UART pins.
//
GPIOPinConfigure(GPIO_PC4_U7RX);
GPIOPinConfigure(GPIO_PC5_U7TX);
MAP_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5);
//
// Configure the UART for 115,200, 8-N-1 operation.
//
MAP_UARTConfigSetExpClk(UART7_BASE, g_ui32SysClock, 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
//
// Enable the UART interrupt.
//
MAP_IntEnable(UART7_BASE);
MAP_UARTIntEnable(UART7_BASE, UART_INT_RX | UART_INT_RT);
//
// Prompt for text to be entered.
//
UARTSend((uint8_t *)"\033[2JEnter text: ", 16);
//
// Loop forever echoing data through the UART.
//
while(1)
{
}
}
不胜感激!