搜索
bottom↓
回复: 6

单步调试串口输出正常,全速运行就只能输出17个字符,是...

[复制链接]

出0入0汤圆

发表于 2013-8-31 17:12:07 | 显示全部楼层 |阅读模式
  1. #include "inc/hw_ints.h"
  2. #include "inc/hw_memmap.h"
  3. #include "inc/hw_types.h"

  4. #include "driverlib/gpio.h"
  5. #include "driverlib/interrupt.h"
  6. #include "driverlib/sysctl.h"
  7. #include "driverlib/timer.h"
  8. #include "driverlib/uart.h"

  9. unsigned char str_receive[10];
  10. unsigned char pr=0,flag_valid_data=0,flag_complete_data=0;
  11. void
  12. UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
  13. {
  14.     //
  15.     // Loop while there are more characters to send.
  16.     //
  17.     while(ulCount--)
  18.     {       
  19.         //
  20.         // Write the next character to the UART.
  21.         //
  22.         UARTCharPutNonBlocking(UART0_BASE, *pucBuffer++);
  23.     }
  24. }

  25. void
  26. UARTIntHandler(void)
  27. {

  28.     unsigned long ulStatus;
  29.        
  30.     //
  31.     // Get the interrrupt status.
  32.     //
  33.     ulStatus = UARTIntStatus(UART0_BASE, true);

  34.     //
  35.     // Clear the asserted interrupts.
  36.     //
  37.     UARTIntClear(UART0_BASE, ulStatus);

  38.     //
  39.     // Loop while there are characters in the receive FIFO.
  40.     //
  41.         str_receive[pr]=UARTCharGetNonBlocking(UART0_BASE);
  42.         if((str_receive[pr]==0xcf)&&(flag_valid_data==0))
  43.         {
  44.                 flag_valid_data=1;
  45.         }
  46.         if(flag_valid_data)
  47.         {
  48.                 if(str_receive[pr]==0xfc)
  49.                 {
  50.                         pr=0;flag_complete_data=1;flag_valid_data=0;
  51.                 }
  52.                 else pr++;
  53.         }
  54.         else pr=0;
  55.         if(flag_complete_data==1)
  56.         {
  57.                 UARTSend(str_receive,3);
  58.                 flag_complete_data=0;
  59.         }
  60. /*        if(str_receive[0]=='a')
  61.         {
  62.                 GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, GPIO_PIN_2);       
  63.         }
  64.         else if(str_receive[0]=='b')
  65.         {
  66.                 GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
  67.         }  */
  68. }                                         
  69. void
  70. Timer0IntHandler(void)
  71. {
  72.         TimerIntClear(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
  73.         IntMasterDisable();
  74.         UARTSend((unsigned char *)"This is Time interrup!\n",sizeof("This is Time interrup!\n"));
  75.         IntMasterEnable();
  76. }
  77.                                 
  78. int                                           
  79. main(void)
  80. {
  81.     //
  82.     // Set the clocking to run directly from the crystal.
  83.     //
  84.     SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_OSC | SYSCTL_OSC_MAIN |
  85.                    SYSCTL_XTAL_8MHZ);

  86.     //
  87.     // Enable the peripherals used by this example.
  88.     //
  89.     SysCtlPeripheralEnable(SYSCTL_PERIPH_UART0);
  90.     SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOA);
  91.         SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOF);
  92.     //
  93.     // Enable processor interrupts.
  94.     //
  95.    
  96.         GPIOPinTypeGPIOOutput(GPIO_PORTF_BASE, GPIO_PIN_2);
  97.         GPIOPinWrite(GPIO_PORTF_BASE, GPIO_PIN_2, 0);
  98.     //
  99.     // Set GPIO A0 and A1 as UART pins.
  100.     //
  101.         GPIOPinConfigure(GPIO_PA0_U0RX);
  102.         GPIOPinConfigure(GPIO_PA1_U0TX);
  103.     GPIOPinTypeUART(GPIO_PORTA_BASE, GPIO_PIN_0 | GPIO_PIN_1);

  104.     //
  105.     // Configure the UART for 115,200, 8-N-1 operation.
  106.     //
  107.     UARTConfigSetExpClk(UART0_BASE, SysCtlClockGet(), 115200,
  108.                         (UART_CONFIG_WLEN_8 | UART_CONFIG_STOP_ONE |
  109.                          UART_CONFIG_PAR_NONE));

  110.     //
  111.     // Enable the UART interrupt.
  112.     //
  113.     IntEnable(INT_UART0);
  114.     UARTIntEnable(UART0_BASE, UART_INT_RX | UART_INT_RT);


  115.         SysCtlPeripheralEnable(SYSCTL_PERIPH_TIMER0);
  116.         TimerConfigure(TIMER0_BASE, TIMER_CFG_32_BIT_PER);
  117.         TimerLoadSet(TIMER0_BASE, TIMER_A, SysCtlClockGet());
  118.         IntEnable(INT_TIMER0A);
  119.         TimerIntEnable(TIMER0_BASE, TIMER_TIMA_TIMEOUT);
  120.         TimerEnable(TIMER0_BASE, TIMER_A);
  121.         IntMasterEnable();
  122.     //
  123.     // Prompt for text to be entered.
  124.     //
  125.     UARTSend((unsigned char *)"It is start!\n", sizeof("It is start!\n"));
  126.     //
  127.     // Loop forever echoing data through the UART.
  128.     //
  129.     while(1)
  130.     {                  
  131.     }
  132. }
复制代码

阿莫论坛20周年了!感谢大家的支持与爱护!!

一只鸟敢站在脆弱的枝条上歇脚,它依仗的不是枝条不会断,而是自己有翅膀,会飞。

出0入0汤圆

 楼主| 发表于 2013-8-31 17:14:33 | 显示全部楼层
串口助手上显示的是
It is start!
This is Time inte

出0入442汤圆

发表于 2013-8-31 17:50:09 | 显示全部楼层
从现象分析,必然是MCU没做延时处理。

出0入0汤圆

 楼主| 发表于 2013-8-31 18:01:31 | 显示全部楼层
wye11083 发表于 2013-8-31 17:50
从现象分析,必然是MCU没做延时处理。

在哪个地方加延时

出0入442汤圆

发表于 2013-8-31 18:14:52 | 显示全部楼层
目测在这里面UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
{
    //
    // Loop while there are more characters to send.
    //
    while(ulCount--)
    {        
        //
        // Write the next character to the UART.
        //
        UARTCharPutNonBlocking(UART0_BASE, *pucBuffer++);
    }
}加个标志判断。

出0入0汤圆

发表于 2013-8-31 18:17:45 来自手机 | 显示全部楼层
NonBlocking...
buffer溢出了呗

出0入0汤圆

 楼主| 发表于 2013-8-31 19:27:48 | 显示全部楼层
wye11083 发表于 2013-8-31 18:14
目测在这里面UARTSend(const unsigned char *pucBuffer, unsigned long ulCount)
{
    //

什么标志位,什么用途的?

ulCount不就是发送的数据个数么?如果没有了就为0
回帖提示: 反政府言论将被立即封锁ID 在按“提交”前,请自问一下:我这样表达会给举报吗,会给自己惹麻烦吗? 另外:尽量不要使用Mark、顶等没有意义的回复。不得大量使用大字体和彩色字。【本论坛不允许直接上传手机拍摄图片,浪费大家下载带宽和论坛服务器空间,请压缩后(图片小于1兆)才上传。压缩方法可以在微信里面发给自己(不要勾选“原图),然后下载,就能得到压缩后的图片】。另外,手机版只能上传图片,要上传附件需要切换到电脑版(不需要使用电脑,手机上切换到电脑版就行,页面底部)。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

手机版|Archiver|amobbs.com 阿莫电子技术论坛 ( 粤ICP备2022115958号, 版权所有:东莞阿莫电子贸易商行 创办于2004年 (公安交互式论坛备案:44190002001997 ) )

GMT+8, 2024-5-14 02:34

© Since 2004 www.amobbs.com, 原www.ourdev.cn, 原www.ouravr.com

快速回复 返回顶部 返回列表