各位高手大家好,小妹我用此板子的UART出了一點問題,大家可以幫幫我嗎? 感激不盡
問題是這樣的,我開啟了八個UART,為了使輸入資料可以做辨識,個別在UART4跟UART5的地方
加了三個#字號跟一個通道編號
例如:UART4是 ###E data 這樣
在我還沒有加這些符號前不管我傳多少個bytes都能正確從UART0傳送出正確數值
但加了辨識符號後最多卻只能傳送23個bytes
我花了好多時間找原因,一直找不出來,可以請大家幫幫我嗎?
謝謝
/* This source has been formatted by an unregistered SourceFormatX */
/* If you want to remove this info, please register this shareware */
/* Please visit http://www.textrush.com to get more information */
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "inc/hw_gpio.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/rom.h"
#include "driverlib/sysctl.h"
#include "driverlib/uart.h"
int c;
int b;
unsigned int aa,bb,cc;
unsigned int COMS[8] = {
UART0_BASE, UART1_BASE, UART2_BASE, UART3_BASE, UART4_BASE, UART5_BASE,
UART6_BASE, UART7_BASE,
};
#ifdef DEBUG
void __error__(char *pcFilename, unsigned long ulLine){}
#endif
//*****************************************************************************
//
// The UART interrupt handler.
//
//*****************************************************************************
void UARTIntHandler(void){
unsigned long ulStatus0;
unsigned long ulStatus1;
unsigned long ulStatus2;
unsigned long ulStatus3;
unsigned long ulStatus4;
unsigned long ulStatus5;
unsigned long ulStatus6;
unsigned long ulStatus7;
char flag = 0;
static unsigned char commBuff[250] = {
0
}; //傳送命令的長度
static int commN = 0; //計算命令的長度
//
// Get the interrrupt status.
//
ulStatus0 = ROM_UARTIntStatus(UART0_BASE, true);
ulStatus1 = ROM_UARTIntStatus(UART1_BASE, true);
ulStatus2 = ROM_UARTIntStatus(UART2_BASE, true);
ulStatus3 = ROM_UARTIntStatus(UART3_BASE, true);
ulStatus4 = ROM_UARTIntStatus(UART4_BASE, true);
ulStatus5 = ROM_UARTIntStatus(UART5_BASE, true);
ulStatus6 = ROM_UARTIntStatus(UART6_BASE, true);
ulStatus7 = ROM_UARTIntStatus(UART7_BASE, true);
//
// Clear the asserted interrupts.
//
ROM_UARTIntClear(UART0_BASE, ulStatus0);
ROM_UARTIntClear(UART1_BASE, ulStatus1);
ROM_UARTIntClear(UART2_BASE, ulStatus2);
ROM_UARTIntClear(UART3_BASE, ulStatus3);
ROM_UARTIntClear(UART4_BASE, ulStatus4);
ROM_UARTIntClear(UART5_BASE, ulStatus5);
ROM_UARTIntClear(UART6_BASE, ulStatus6);
ROM_UARTIntClear(UART7_BASE, ulStatus7);
//
// Loop while there are characters in the receive FIFO.
while (ROM_UARTCharsAvail(UART0_BASE)){
int i = 2; // ex. #、1 扣除前兩個字
commBuff[commN] = ROM_UARTCharGetNonBlocking(UART0_BASE);
commN++;
if (commBuff[commN - 1] == '%'){
//檢查命令最後一個字元是否為%
unsigned char com = commBuff[1]; //第幾個com
if (commBuff[2] == 'C' && commBuff[3] == 'O' && commBuff[4] == 'M'){
unsigned int baud = 0;
i = 5;
while (i < commN - 2){
baud = baud * 10+commBuff - '0';
i++;
}
ROM_UARTConfigSetExpClk(COMS[com - '0'], ROM_SysCtlClockGet(),
baud, (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
UART_CONFIG_PAR_NONE));
}
else{
while (i < commN - 2){
//從第三位開始算
ROM_UARTCharPutNonBlocking(COMS[com-'0'], commBuff);
i++;
}
}
for(i=0;i = 0;
commN = 0;
}
}
///資料從各個UART傳送至UART0
/************************UART1*****************************/
while (ROM_UARTCharsAvail(UART1_BASE)){
ROM_UARTCharPutNonBlocking(UART0_BASE, ROM_UARTCharGetNonBlocking
(UART1_BASE));
}
/************************UART2*****************************/
while (ROM_UARTCharsAvail(UART2_BASE)){
ROM_UARTCharPutNonBlocking(UART0_BASE, ROM_UARTCharGetNonBlocking
(UART2_BASE));
}
/************************UART3*****************************/
while (ROM_UARTCharsAvail(UART3_BASE)){
ROM_UARTCharPutNonBlocking(UART0_BASE, ROM_UARTCharGetNonBlocking
(UART3_BASE));
}
/************************UART4*****************************/
if (ROM_UARTCharsAvail(UART4_BASE) != 0){
flag = 1;
ROM_UARTCharPutNonBlocking(UART0_BASE, '#');//資料前面加三個#跟E
ROM_UARTCharPutNonBlocking(UART0_BASE, '#');
ROM_UARTCharPutNonBlocking(UART0_BASE, '#');
//ROM_UARTCharPutNonBlocking(UART0_BASE, 0x23);
ROM_UARTCharPutNonBlocking(UART0_BASE,'E');
//ROM_UARTCharPutNonBlocking(UART0_BASE, '#');
//ROM_UARTCharPutNonBlocking(UART0_BASE, '#');
// ROM_UARTCharPutNonBlocking(UART0_BASE, 0x55);
//ROM_UARTCharPutNonBlocking(UART0_BASE, 'E');
}
///int ptr=ROM_UARTCharsAvail(UART0_BASE);
//int *ptr=(UART4_BASE);
//kk=ROM_UARTCharsAvail(UART4_BASE);
// unsigned int *p = (unsigned int*)0x40010000;
// aa=*p;
// bb=*(p+1);
// cc=*(p+2);
// b=1;
while (ROM_UARTCharsAvail(UART4_BASE)){
ROM_UARTCharPutNonBlocking(UART0_BASE, ROM_UARTCharGetNonBlocking
(UART4_BASE));
}
if (ROM_UARTCharsAvail(UART4_BASE) == 0 && flag == 1){
flag = 0;
// ROM_UARTCharPutNonBlocking(UART0_BASE, '4');
// ROM_UARTCharPutNonBlocking(UART0_BASE, '%');
}
/************************UART5*****************************/
if (ROM_UARTCharsAvail(UART5_BASE) != 0){
flag = 1;
ROM_UARTCharPutNonBlocking(UART0_BASE, '#');//資料前面加3個#跟F
ROM_UARTCharPutNonBlocking(UART0_BASE, '#');
ROM_UARTCharPutNonBlocking(UART0_BASE, '#');
ROM_UARTCharPutNonBlocking(UART0_BASE, 'F');
}
while (ROM_UARTCharsAvail(UART5_BASE)){
ROM_UARTCharPutNonBlocking(UART0_BASE, ROM_UARTCharGetNonBlocking
(UART5_BASE));
}
if (ROM_UARTCharsAvail(UART5_BASE) == 0 && flag == 1){
flag = 0;
//ROM_UARTCharPutNonBlocking(UART0_BASE, '5');
//ROM_UARTCharPutNonBlocking(UART0_BASE, '%');
}
/************************UART6*****************************/
while (ROM_UARTCharsAvail(UART6_BASE)){
ROM_UARTCharPutNonBlocking(UART0_BASE, ROM_UARTCharGetNonBlocking
(UART6_BASE));
}
/************************UART7*****************************/
while (ROM_UARTCharsAvail(UART7_BASE)){
ROM_UARTCharPutNonBlocking(UART0_BASE, ROM_UARTCharGetNonBlocking
(UART7_BASE));
}
}
//*****************************************************************************
//
// Send a string to the UART.
//
//*****************************************************************************
void UARTSend(const unsigned char *pucBuffer, unsigned long ulCount){
while (ulCount--){
ROM_UARTCharPutNonBlocking(UART0_BASE, *pucBuffer++);
ROM_UARTCharPutNonBlocking(UART1_BASE, *pucBuffer++);
ROM_UARTCharPutNonBlocking(UART2_BASE, *pucBuffer++);
ROM_UARTCharPutNonBlocking(UART3_BASE, *pucBuffer++);
ROM_UARTCharPutNonBlocking(UART4_BASE, *pucBuffer++);
ROM_UARTCharPutNonBlocking(UART5_BASE, *pucBuffer++);
ROM_UARTCharPutNonBlocking(UART6_BASE, *pucBuffer++);
ROM_UARTCharPutNonBlocking(UART7_BASE, *pucBuffer++);
}
}
//*****************************************************************************
//
// This example demonstrates how to send a string of data to the UART.
//
//*****************************************************************************
int main(void){
//
// Enable lazy stacking for interrupt handlers. This allows floating-point
// instructions to be used within interrupt handlers, but at the expense of
// extra stack usage.
//
ROM_FPUEnable();
ROM_FPULazyStackingEnable();
//
// Set the clocking to run directly from the crystal.
//
ROM_SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
SYSCTL_XTAL_16MHZ);
//
// Enable the GPIO port that is used for the on-board LED.
//
//ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
//
// Enable the GPIO pins for the LED (PF2).
//
//ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
//
// Enable the peripherals used by this example.
//
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART2);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART3);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOJ);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART4);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART5);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART6);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOK);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART7);
//ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
//
// Enable processor interrupts.
//
ROM_IntMasterEnable();
//
// Set GPIO A0 and A1 as UART pins.
//
GPIOPinConfigure(GPIO_PA0_U0RX);
GPIOPinConfigure(GPIO_PC4_U1RX);
GPIOPinConfigure(GPIO_PD6_U2RX);
GPIOPinConfigure(GPIO_PC6_U3RX);
GPIOPinConfigure(GPIO_PJ0_U4RX);
GPIOPinConfigure(GPIO_PJ2_U5RX);
GPIOPinConfigure(GPIO_PJ4_U6RX);
GPIOPinConfigure(GPIO_PK4_U7RX);
HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_KEY_DD;
HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0xFF;
GPIOPinConfigure(GPIO_PA1_U0TX);
GPIOPinConfigure(GPIO_PC5_U1TX);
GPIOPinConfigure(GPIO_PD7_U2TX);
GPIOPinConfigure(GPIO_PC7_U3TX);
GPIOPinConfigure(GPIO_PJ1_U4TX);
GPIOPinConfigure(GPIO_PJ3_U5TX);
GPIOPinConfigure(GPIO_PJ5_U6TX);
GPIOPinConfigure(GPIO_PK5_U7TX);
HWREG(GPIO_PORTD_BASE + GPIO_O_CR) = 0x7F;
HWREG(GPIO_PORTD_BASE + GPIO_O_LOCK) = GPIO_LOCK_M;
ROM_GPIOPinTypeUART(GPIO_PORTD_BASE, GPIO_PIN_6 | GPIO_PIN_7);
ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5);
ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_1 | GPIO_PIN_0);
ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_6 | GPIO_PIN_7);
ROM_GPIOPinTypeUART(GPIO_PORTJ_BASE, GPIO_PIN_0 | GPIO_PIN_1);
ROM_GPIOPinTypeUART(GPIO_PORTJ_BASE, GPIO_PIN_2 | GPIO_PIN_3);
ROM_GPIOPinTypeUART(GPIO_PORTJ_BASE, GPIO_PIN_4 | GPIO_PIN_5);
ROM_GPIOPinTypeUART(GPIO_PORTK_BASE, GPIO_PIN_4 | GPIO_PIN_5);
//
// Configure the UART for 115,200, 8-N-1 operation.
//
ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
ROM_UARTConfigSetExpClk(UART2_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
ROM_UARTConfigSetExpClk(UART3_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
ROM_UARTConfigSetExpClk(UART4_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
ROM_UARTConfigSetExpClk(UART5_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
ROM_UARTConfigSetExpClk(UART6_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
ROM_UARTConfigSetExpClk(UART7_BASE, ROM_SysCtlClockGet(), 115200,
(UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE));
///設定FIFO trigger
ROM_UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8);
ROM_UARTFIFOLevelSet(UART4_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8);
//
// Enable the UART interrupt.
//
ROM_IntEnable(INT_UART0);
ROM_IntEnable(INT_UART1);
ROM_IntEnable(INT_UART2);
ROM_IntEnable(INT_UART3);
ROM_IntEnable(INT_UART4);
ROM_IntEnable(INT_UART5);
ROM_IntEnable(INT_UART6);
ROM_IntEnable(INT_UART7);
ROM_UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);
ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);
ROM_UARTIntEnable(UART2_BASE, UART_INT_RX | UART_INT_RT);
ROM_UARTIntEnable(UART3_BASE, UART_INT_RX | UART_INT_RT);
ROM_UARTIntEnable(UART4_BASE, UART_INT_RX | UART_INT_RT);
ROM_UARTIntEnable(UART5_BASE, UART_INT_RX | UART_INT_RT);
ROM_UARTIntEnable(UART6_BASE, UART_INT_RX | UART_INT_RT);
ROM_UARTIntEnable(UART7_BASE, UART_INT_RX | UART_INT_RT);
//
// Loop forever echoing data through the UART.
//
while (1){}
}