ASM 板


LINE

看板 ASM  RSS
目前用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专门收集资料 另外五个解五个仪器的资料 大致上是这样 感激不尽 >< --



※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 140.117.95.119
1F:推 deo2000:用贴code的网页吧,这样看太累 12/11 05:15
2F:→ lovecity:不好意思~我把CODE放到网页上了-> http://ppt.cc/9DAn 12/11 14:56
3F:推 mosquito520:你的UARTxIntHandler里面会不会做太多事情了? 12/12 23:33
4F:→ mosquito520:还有while等资料传完,那资料太多势必会影响到吧? 12/12 23:33
5F:→ lovecity:在while里等资料 小妹是照着范例程式做的说 >< 01/02 20:28







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:WOW站内搜寻

TOP