主题 : ADS单步调试和全速运行结果不一 复制链接 | 浏览器收藏 | 打印
级别: 新手上路
UID: 31331
精华: 0
发帖: 3
金钱: 15 两
威望: 3 点
综合积分: 6 分
注册时间: 2010-10-29
最后登录: 2011-08-09
楼主  发表于: 2010-12-28 20:27

 ADS单步调试和全速运行结果不一

小弟在mini2440上编了个裸机SPI程序,单步调试时结果正确,全速运行时,发现会丢失数据,这是为什么啊,江湖救急。。
主要程序如下,SPI0主机,查询方式,SPI1做从机,中断方式

复制代码
  1. void Main(void)
  2. {  
  3.   
  4.    Set_Clk();      
  5.    Uart_Init(0,115200);  
  6.    Uart_Select(0);  
  7.    MMU_Init();
  8.   
  9.    spi0_init();  
  10.    spi1_init();
  11.   
  12.   
  13.   
  14.   
  15.     
  16.       for(i=0;i<5;i++)
  17.       {
  18.         while(!(rSPSTA0&1));
  19.         rSPTDAT0=i;
  20.         //Uart_Printf("\nspi0 snd data:  %d !!\n",rSPTDAT0);
  21.       
  22.       
  23.         while(!(rSPSTA0&1));
  24.         r_data0=rSPRDAT0;
  25.        // Uart_Printf("spi0 has got the data:  %d !!\n",rSPRDAT0);
  26.       
  27.         rINTMSK&=~(1<<29);
  28.        }
  29.     
  30.   
  31.     
  32.     ClearPending(BIT_SPI1);
  33. }
  34. /************************************************
  35. SPI1发送函数
  36. ************************************************/
  37. void __irq spi1_sd(void)
  38. {
  39.   while(!(rSPSTA1&0x1));
  40.   r_data1=rSPRDAT1;
  41.   Uart_Printf("\nspi1 get data:  %d !!\n",r_data1);
  42.   rINTMSK|=(1<<29);
  43.   
  44.       while(!(rSPSTA1&0x1));
  45.       rSPTDAT1=i+5;
  46.       rSPTDAT0=0xff;      
  47.       Uart_Printf("spi1 has snd the data:  %d !!\n",rSPTDAT1);
  48.   
  49. rSRCPND|=(1<<29);
  50.   rINTPND|=(1<<29);
  51.   
  52.   
  53.   
  54. }
  55. /*************************************************
  56. SPI0初始化函数
  57. *************************************************/
  58. void spi0_init()
  59. {
  60.   rGPECON&=0xf03fffff;
  61.   rGPECON|=0x0a800000;  
  62.   rGPEUP = (rGPEUP & ~(7<<11)) | (1<<13);
  63.   rGPGUP|=0x4;             //什么时候禁止(允许,使能)上拉电阻?  
  64.   
  65.   
  66.   rGPGCON=((rGPGCON&0xffffffcf)|0x10); // MASTER设为(GPIO_Output)    
  67.   rGPGDAT|=0x4;
  68.   rGPGDAT&=0xfffb; // Activate nSS        
  69.   rSPCON0=(0<<5)|(1<<4)|(1<<3)|(0<<2)|(0<<1)|(0<<0);
  70.   //中断模式,时钟使能,主机,高态有效,A格式,普通模式
  71.   rSPPIN0=(0<<2)|(1<<1)|(0<<0);
  72.                                        //释放
  73.   rSPPRE0=0x18;                        //SPI时钟频率1M
  74. }
  75. /*************************************************
  76. SPI1初始化函数
  77. *************************************************/
  78. void spi1_init()
  79. {
  80.   rGPGCON|=0xc0;
  81.           
  82.   rSPCON1=(1<<5)|(0<<4)|(0<<3)|(0<<2)|(0<<1)|(0<<0);
  83.   
  84.   rSPPIN1=(0<<2)|(1<<1)|(0<<0);
  85.                                        //释放
  86.   
  87.   rGPGCON|=0xc0;      
  88.   pISR_SPI1=(U32)spi1_sd;  
  89.   rINTMOD&=~(1<<29);
  90.   rINTMSK|=(1<<29);      
  91. }



单步时,结果如下
spi1 get data:  0 !!
spi1 has snd the data:  5 !!
spi1 get data:  1 !!
spi1 has snd the data:  6 !!
spi1 get data:  2 !!
spi1 has snd the data:  7 !!
spi1 get data: 3 !!
spi1 has snd the data:  8!!
spi1 get data: 4!!
spi1 has snd the data:  9 !!

全速时,结果如下
spi1 get data:  0 !!
spi1 has snd the data:  6 !!
spi1 get data:  1 !!
spi1 has snd the data:  7 !!
spi1 get data:  2 !!
spi1 has snd the data:  8 !!
spi1 get data:  3 !!
spi1 has snd the data:  9 !!
spi1 get data:  4 !!
spi1 has snd the data:  10 !!
[ 此帖被seligor在2010-12-28 20:54重新编辑 ]