※ 引述《lovecity (我要快乐)》之铭言:
: 目前用LM4F的MCU写 五个不同仪器的资料可以由五个UART(UART1、UART2、UART3、UART4
: 、UART5)的Rx接收
: 后送给UART0的Rx收然后传给电脑人机(BCB5)
: UART0的部分是使用udma写的
: 以下是我撷取的一部分芯片程式码
: // The number of SysTick ticks per second used for the SysTick interrupt.
: //*****************************************************************************
: #define SYSTICKS_PER_SECOND     100
: //*****************************************************************************
: // The size of the UART transmit and receive buffers.  They do not need to be
: // the same size.
: //*****************************************************************************
: #define UART_TXBUF_SIZE        16
: #define UART_RXBUF_SIZE        16
: //*****************************************************************************
: // The transmit and receive buffers used for the UART transfers.  There is one
: // transmit buffer and a pair of recieve ping-pong buffers.
: //*****************************************************************************
: //static unsigned char g_ucTxBuf[UART_TXBUF_SIZE];
: static unsigned char g_ucRxBuf1[UART_RXBUF_SIZE];
: static unsigned char g_ucRxBuf2[UART_RXBUF_SIZE];
: static unsigned char g_ucRxBuf3[UART_RXBUF_SIZE];
: static unsigned char g_ucRxBuf4[UART_RXBUF_SIZE];
: static unsigned char g_ucRxBuf5[UART_RXBUF_SIZE];
: static unsigned char g_ucRxBuf6[UART_RXBUF_SIZE];
: static unsigned char g_ucRxBuf7[UART_RXBUF_SIZE];
: //static unsigned char k=0;
: unsigned char uartTmpBuff[UART_RXBUF_SIZE+4+4];
: void
: UART1IntHandler(void)  //此中断是做收资料与传资料
: {
:     unsigned long ulStatus;
:     char header[]="###B"; //辨识符号
:     char tail[]="B%%%";
:         //get interrupt status
:         ulStatus = ROM_UARTIntStatus(UART1_BASE, true);
:         //clear the asserted interrupts
:         ROM_UARTIntClear(UART1_BASE, ulStatus);
:         //FIFO data transfer
:         if(ulStatus == UART_INT_RX)//接收中断标帜
:         {
:                 while(ROM_UARTCharsAvail(UART1_BASE)) //loop while there are chars
:             {
:                 g_ucRxBuf1[g_ulRxBuf1Count++] = ROM_UARTCharGetNonBlocking(UART1_BASE);
:                 if(g_ulRxBuf1Count >= UART_RXBUF_SIZE)
:                 {
:                         g_ulRxBuf1Count = 0;
:                         /*ROM_uDMAChannelTransferSet(UDMA_CHANNEL_UART0TX | UDMA_PRI_SELECT,
:                                                    UDMA_MODE_BASIC, header,
:                                                    (void *)(UART0_BASE + UART_O_DR),
:                                                    3);
:                         ROM_uDMAChannelEnable(UDMA_CHANNEL_UART0TX);*/
:                         memcpy(uartTmpBuff,header,sizeof(header));
:                         memcpy(uartTmpBuff+sizeof(header)-1,g_ucRxBuf1,sizeof(g_ucRxBuf1));
:                 memcpy(uartTmpBuff+sizeof(header)+sizeof(g_ucRxBuf1)-1,tail,sizeof(tail));
:                 //通道传输设置
:                         ROM_uDMAChannelTransferSet(UDMA_CHANNEL_UART0TX | UDMA_PRI_SELECT,
:                                                    UDMA_MODE_BASIC, uartTmpBuff,
:                                                    (void *)(UART0_BASE + UART_O_DR),
:                                                    sizeof(uartTmpBuff));
:                         ROM_uDMAChannelEnable(UDMA_CHANNEL_UART0TX);
:                 }
:             }
:         }
: }
: void
: UART2IntHandler(void) //此中断是做收资料与传资料
: {
:         unsigned long ulStatus;
:     char header[]="###C";
:     char tail[]="C%%%";
:         //get interrupt status
:         ulStatus = ROM_UARTIntStatus(UART2_BASE, true);
:         //clear the asserted interrupts
:         ROM_UARTIntClear(UART2_BASE, ulStatus);
:         //FIFO data transfer
:         if(ulStatus == UART_INT_RX)
:         {
:             while(ROM_UARTCharsAvail(UART2_BASE)) //loop while there are chars
:             {
:                 g_ucRxBuf2[g_ulRxBuf2Count++]= ROM_UARTCharGetNonBlocking(UART2_BASE);
:                 if(g_ulRxBuf2Count >= UART_RXBUF_SIZE)
:                 {
:                         g_ulRxBuf2Count = 0;
:                         memcpy(uartTmpBuff,header,sizeof(header));
:                         memcpy(uartTmpBuff+sizeof(header)-1,g_ucRxBuf2,sizeof(g_ucRxBuf2));
:                 memcpy(uartTmpBuff+sizeof(header)+sizeof(g_ucRxBuf2)-1,tail,sizeof(tail));
:                         ROM_uDMAChannelTransferSet(UDMA_CHANNEL_UART0TX | UDMA_PRI_SELECT,
:                                                                            UDMA_MODE_BASIC, uartTmpBuff,
:                                            (void *)(UART0_BASE + UART_O_DR),
:                                             sizeof(uartTmpBuff));
:                         ROM_uDMAChannelEnable(UDMA_CHANNEL_UART0TX);
:                 }
:             }
:         }
: }
: void
: InitUART0(void)
: {
:     // Enable the UART peripheral, and configure it to operate even if the CPU
:     // is in sleep.
:         ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
:     ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
:     ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART0);
:     ROM_GPIOPinConfigure(GPIO_PA0_U0RX);
:     ROM_GPIOPinConfigure(GPIO_PA1_U0TX);
:     ROM_GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);
:     // Configure the UART communication parameters.
:     ROM_UARTConfigSetExpClk(UART0_BASE, ROM_SysCtlClockGet(), 115200,
:                             UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
:                             UART_CONFIG_PAR_NONE);
:     // Set both the TX and RX trigger thresholds to 4.  This will be used by
:     // the uDMA controller to signal when more data should be transferred.
:  The
:     // uDMA TX and RX channels will be configured so that it can transfer 4
:     // bytes in a burst when the UART is ready to transfer more data.
:     ROM_UARTFIFOLevelSet(UART0_BASE, UART_FIFO_TX4_8, UART_FIFO_RX4_8);
:     // Enable the UART for operation, and enable the uDMA interface for RX
:     // channels.
:     ROM_UARTEnable(UART0_BASE);
:     ROM_UARTDMAEnable(UART0_BASE, UART_DMA_TX);
:     // Put the attributes in a known state for the uDMA UART0TX channel.
:  These
:     // should already be disabled by default.
:     // uDMA通道属性清除
:     ROM_uDMAChannelAttributeDisable(UDMA_CHANNEL_UART0TX,     //选择UART0 TX的
: DMA通道
:                                     UDMA_ATTR_ALTSELECT |     //设置为主控制结
: 构
:                                     UDMA_ATTR_HIGH_PRIORITY | //普通优先级
:                                     UDMA_ATTR_REQMASK);       //响应外设请求
:     // Set the USEBURST attribute for the uDMA UART TX channel.  This will
:     // force the controller to always use a burst when transferring data from
:     // the TX buffer to the UART.  This is somewhat more effecient bus usage
:     // than the default which allows single or burst transfers.
:     //uDMA通道属性始能
:     ROM_uDMAChannelAttributeEnable(UDMA_CHANNEL_UART0TX, UDMA_ATTR_USEBURST);
: //选择UART0 TX的DMA通道;设置触发方式只有脉冲触发有效
:     // Configure the control parameters for the UART TX.  The uDMA UART TX
:     // channel is used to transfer a block of data from a buffer to the UART.
:     // The data size is 8 bits.  The source address increment is 8-bit bytes
:     // since the data is coming from a buffer.  The destination increment is
:     // none since the data is to be written to the UART data register.  The
:     // arbitration size is set to 4, which matches the UART TX FIFO trigger
:     // threshold.
:     //uDMA通道控制设置
:     ROM_uDMAChannelControlSet(UDMA_CHANNEL_UART0TX | UDMA_PRI_SELECT,
:                               UDMA_SIZE_8 | UDMA_SRC_INC_8 |
: UDMA_DST_INC_NONE |
:                               UDMA_ARB_4);
: }
: void
: InitUARTs(void)
: {
:     // Enable the UART1 peripheral, and configure it to operate even if the
: CPU is in sleep.
:         ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOC);
:     ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UART1);
:     ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UART1);
:     ROM_GPIOPinConfigure(GPIO_PC4_U1RX);
:     ROM_GPIOPinConfigure(GPIO_PC5_U1TX);
:     ROM_GPIOPinTypeUART(GPIO_PORTC_BASE, GPIO_PIN_4 | GPIO_PIN_5);
:     ROM_UARTConfigSetExpClk(UART1_BASE, ROM_SysCtlClockGet(), 9600,
: UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE | UART_CONFIG_PAR_NONE);
:     ROM_UARTFIFOLevelSet(UART1_BASE, UART_FIFO_TX2_8, UART_FIFO_RX2_8);
:     ROM_UARTEnable(UART1_BASE);
:     ROM_IntEnable(INT_UART1);
:     ROM_UARTIntEnable(UART1_BASE, UART_INT_RX | UART_INT_RT);
: }
: int
: main(void)
: {
:     static unsigned long ulPrevSeconds;
:     volatile unsigned long ulLoop;
:     // Enable lazy stacking for interrupt handlers.
:     ROM_FPULazyStackingEnable();
:     //clock 80M
:     SysCtlClockSet(SYSCTL_SYSDIV_2_5 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN |
: SYSCTL_XTAL_16MHZ);
:     ROM_SysCtlPeripheralClockGating(true);
:     // Enable the GPIO port that is used for the on-board LED.
:     ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
:     ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_1);
:     ROM_GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
:     // Configure SysTick to occur 100 times per second, to use as a time
:     // reference.  Enable SysTick to generate interrupts.
:     ROM_SysTickPeriodSet(ROM_SysCtlClockGet() / SYSTICKS_PER_SECOND);
:     ROM_SysTickIntEnable();
:     ROM_SysTickEnable();
:     // Initialize the CPU usage measurement routine.
:     //CPUUsageInit(ROM_SysCtlClockGet(), SYSTICKS_PER_SECOND, 2);
:     // Enable the uDMA controller at the system level.  Enable it to continue
:     // to run while the processor is in sleep.
:     ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_UDMA);
:     ROM_SysCtlPeripheralSleepEnable(SYSCTL_PERIPH_UDMA);
:     // Enable the uDMA controller error interrupt.  This interrupt will occur
:     // if there is a bus error during a transfer.
:     ROM_IntEnable(INT_UDMAERR);
:     // Enable the uDMA controller.
:     ROM_uDMAEnable();
:     // Point at the control table to use for channel control structures.
:     ROM_uDMAControlBaseSet(ucControlTable);
:     // Initialize the uDMA memory to memory transfers.
:     //InitSWTransfer();
:     // Initialize the uDMA UART transfers.
:     ROM_IntMasterEnable();
:     InitUART0();
:     InitUARTs();
:     UARTStdioInit(0);
:     UARTprintf("\nStart\n");
:     // Remember the current SysTick seconds count.
:     ulPrevSeconds = g_ulSeconds;
:     GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0);
:     // Loop until the button is pressed.  The processor is put to sleep
:     // in this loop so that CPU utilization can be measured.
:     while(1)
:     {
:         // Check to see if one second has elapsed.  If so, the make some
: updates.
:         if(g_ulSeconds != ulPrevSeconds)
:         {
:             // Turn on the LED as a heartbeat
:             GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
:             SysCtlDelay(SysCtlClockGet() / 3 /5);
:             // Turn off the LED.
:             GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
:             SysCtlDelay(SysCtlClockGet() / 3 /5);
:         }
:         // Put the processor to sleep if there is nothing to do.  This allows
:         // the CPU usage routine to measure the number of free CPU cycles.
:         // If the processor is sleeping a lot, it can be hard to connect to
:         // the target with the debugger.
:         ROM_SysCtlSleep();
:         // See if we have run long enough and exit the loop if so.
:         if(g_ulSeconds >= 10)
:         {
:             break;
:         }
:     }
:     // Indicate on the display that the example is stopped.
:     UARTprintf("\nStopped\n");
:     // Loop forever with the CPU not sleeping, so the debugger can connect.
:     while(1)
:     {
:         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, GPIO_PIN_1);
:         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);
:         SysCtlDelay(SysCtlClockGet() / 3 /5);
:         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_1, 0);
:         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
:         SysCtlDelay(SysCtlClockGet() / 3 /5);
:     }
: }
: 跟电脑人机连接的UART0鲍率是设定115200
: 其他五个UART的鲍率是19200
: 五个仪器会同时传资料进芯片
: 芯片再传给人机
: 我用BCB5写人机接口
: 但是如果送进去芯片的资料量大一点
: 人机接口收到所解出来的资料就会错很多
: 除错除了快一个月了
: 无法确定是芯片的问题还是BCB5的问题
: 请问有高手可以指教吗???
: 芯片这样写如果五组资料同时传会不会造成资料错乱呢?
: BCB5收资料的部分我是用到六个timer去写
: 一个timer专门收集资料
: 另外五个解五个仪器的资料
: 大致上是这样
: 感激不尽 ><
  当五个仪器得资料进来时,所对应的MCU的UART有设定优先权吗?
  假设MCU UART0 接收资料时在中断停留太久,其他的UART中断来不及处理
  就会有可能会掉资料.
  你可以试看看量测UART进入中断到出中断时间,推算是否会超过接收资料得时间.
  当传输资料量变大时,有可能在某一中断接收与传送资料太久导致其他中断
  无法接收完全的资料
  以上就参考看看