打印
[51单片机]

C8051F340单片机I2C通信,SMBus进入不了中断怎么回事?

[复制链接]
1141|1
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Dresky|  楼主 | 2017-3-21 22:31 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
下面是main主函数,用keil调试发现进入不了SMBus中断,大神们给看看为什么?

void main (void)
{
   /* volatile  */unsigned char dat;   // Test counter
   unsigned char i;                    // Dummy variable counters
   PCA0MD &= ~0x40;                    // WDTE = 0 (watchdog timer enable bit)
   OSCICN |= 0x03;                     // Set internal oscillator to highest
                                       // setting of 12000000
   // If slave is holding SDA low because of an improper SMBus reset or error
   while(!SDA)
   {
      // Provide clock pulses to allow the slave to advance out
      // of its current state. This will allow it to release SDA.
      XBR1 = 0x40;                     // Enable Crossbar
      SCL = 0;                         // Drive the clock low
      for(i = 0; i < 255; i++);        // Hold the clock low
      SCL = 1;                         // Release the clock
      while(!SCL);                     // Wait for open-drain
                                       // clock output to rise
      for(i = 0; i < 10; i++);         // Hold the clock high
      XBR1 = 0x00;                     // Disable Crossbar
   }
   Port_Init ();                       // Initialize Crossbar and GPIO
       
   Timer1_Init ();                     // Configure Timer1 for use as SMBus
                                       // clock source
   Timer3_Init ();                     // Configure Timer3 for use with SMBus
                                       // low timeout detect
   SMBus_Init ();                      // Configure and enable SMBus
         P2=0x1f;
   EIE1 |= 0x01;                       // Enable the SMBus interrupt
   EA = 1;   
         // Global interrupt enable
// TEST CODE-------------------------------------------------------------------
   dat = 0x55;                         // Output data counter
   NUM_ERRORS = 0;                     // Error counter
   while (1)
   {
      // SMBus Write Sequence
      SMB_DATA_OUT = dat;              // Define next outgoing byte
      TARGET = SLAVE_ADDR;             // Target the F3xx/Si8250 Slave for next
                                       // SMBus transfer
      SMB_Write();                     // Initiate SMBus write
      // SMBus Read Sequence
      TARGET = SLAVE_ADDR;             // Target the F3xx/Si8250 Slave for next
                                       // SMBus transfer
                 
      SMB_Read();           // Check transfer data
                  if(SMB_DATA_IN != SMB_DATA_OUT)   
                                 {
                                        NUM_ERRORS++;                        
                                        LED1 = (!LED1);                    // 接收到错误LED1灯亮
                                 }
                                 else {};                                                                                 
      // Run to here to view the SMB_DATA_IN and SMB_DATA_OUT variables
     // dat++;
      T0_Wait_ms (1);                  // Wait 1 ms until the next cycle
   }
// END TEST CODE---------------------------------------------------------------
}

相关帖子

沙发
Dresky|  楼主 | 2017-3-22 13:16 | 只看该作者
有做I2C通信的吗?交流下

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

4

主题

19

帖子

0

粉丝