打印

求助,DSP28027的I2C读写程序。

[复制链接]
4035|7
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
chuxuer|  楼主 | 2013-7-7 21:27 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 chuxuer 于 2013-7-7 21:30 编辑

求助,DSP28027的I2C读写程序。
下面是我自己根据LMP9100还有TI给的例程自己写的程序,TI提供的例程用到了中断,我的没有用中断方式读写。帮我看下有错误没有,因为读出来的数据和写进去的数据不一致。
void LMP91000_Init(void)
{
   // Initialize I2C
   I2caRegs.I2CSAR = 0x0048;        // LMP9100 Slave address
   // I2CCLK = SYSCLK/(I2CPSC+1)

     I2caRegs.I2CPSC.all = 6;       // Prescaler - need 7-12 Mhz on module clk

   I2caRegs.I2CCLKL = 55;           // NOTE: must be non zero
   I2caRegs.I2CCLKH = 35;            // NOTE: must be non zero
   I2caRegs.I2CMDR.all = 0x0020;    // Take I2C out of reset                              
      // Stop I2C when suspended
   I2caRegs.I2CFFTX.all = 0x6000;   // Enable FIFO mode and TXFIFO
   I2caRegs.I2CFFRX.all = 0x2040;   // Enable RXFIFO, clear RXFFINT,
   return;
}
void LMP91000_Write(Uint16 address,Uint16 data)
{
TXByteCtr=2;         //发送多少位
   // Wait until the STP bit is cleared from any previous master communication.
   // Clearing of this bit by the module is delayed until after the SCD bit is
   // set. If this bit is not checked prior to initiating a new message, the
   // I2C could get confused.
   while (I2caRegs.I2CMDR.bit.STP == 1)
    I2caRegs.I2CSAR = 0x0048;
   while (I2caRegs.I2CSTR.bit.BB == 1);
I2caRegs.I2CCNT=TXByteCtr;
I2CBufferArray[1] = address;                 //先存储发送LMP91000需要写数据的寄存器地址到中间数组
I2CBufferArray[0] = data;      //再存储发送LMP91000需要到寄存器地址的数据到中间数组
I2caRegs.I2CDXR = I2CBufferArray[1];
I2caRegs.I2CDXR = I2CBufferArray[0];
    I2caRegs.I2CMDR.all = 0x6e20;      //使能I2C,主模式写,7位地址,internal data counter of the I2C module counts down to 0产生STOP
    return;
}
Uint16 LMP91000_Read(Uint16 address)
{
   // Wait until the STP bit is cleared from any previous master communication.
   // Clearing of this bit by the module is delayed until after the SCD bit is
   // set. If this bit is not checked prior to initiating a new message, the
   // I2C could get confused.
    while (I2caRegs.I2CMDR.bit.STP == 1);
    I2caRegs.I2CSAR = 0x0048;
       I2caRegs.I2CCNT = 1;
       I2caRegs.I2CDXR = address;
    I2caRegs.I2CMDR.all = 0x6e20;   //发送start位,主模式写,internal data counter of the I2C module counts down to 0产生STOP
     while (I2caRegs.I2CSTR.bit.BB == 1);  //总线是否忙
     I2caRegs.I2CSAR = 0x0048;
       I2caRegs.I2CCNT = 1;
       I2caRegs.I2CMDR.all = 0x6c20;  //发送start位,主模式读,不产生stop
       if(I2caRegs.I2CSTR.bit.NACKSNT == 1) //如果I2C模块是否发送发送NACK
       {
        I2caRegs.I2CMDR.bit.STP =1;    //stop位置1
        I2caRegs.I2CSTR.bit.NACKSNT=1;清除NACK标志位
     I2CBuffer = I2caRegs.I2CDRR;
       }
  return I2CBuffer;         //返回接收到的值
}

相关帖子

沙发
51xlf| | 2013-7-7 22:09 | 只看该作者
建议你自己用io写个模拟。

使用特权

评论回复
板凳
liuming759| | 2013-7-22 11:49 | 只看该作者
LZ,你现在的IIC模块搞定了吗?可以共享一下吗?

使用特权

评论回复
地板
1831249703| | 2015-4-17 15:43 | 只看该作者
liuming759 发表于 2013-7-22 11:49
LZ,你现在的IIC模块搞定了吗?可以共享一下吗?

你好,你写的有吗

使用特权

评论回复
5
1831249703| | 2015-4-17 15:44 | 只看该作者
您好,最近在用i2c,你有调好的程序吗?头疼啊,出不来

使用特权

评论回复
6
m098m098| | 2015-12-15 11:11 | 只看该作者
读出来的数据是FF吗

使用特权

评论回复
7
毁灭2012| | 2015-12-15 14:44 | 只看该作者
      if(I2caRegs.I2CSTR.bit.NACKSNT == 1) //如果I2C模块是否发送发送NACK

使用特权

评论回复
8
handleMessage| | 2015-12-15 14:57 | 只看该作者
是给发送多少位的数据啊????

使用特权

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

本版积分规则

1

主题

1

帖子

1

粉丝