打印
[DSP编程]

28335调试I2C问题

[复制链接]
2086|9
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
1831249703|  楼主 | 2015-4-20 19:10 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
在调试的过程中遇到一些问题,我程序写的是只发一帧,循环发。一旦写进数据寄存器我就产生开始条件,进行传输。等待到结束标志信号后,我就重新发。示波器显示的scl为9个时钟,但是无论我数据传的是什么,sda显示的都不变,不知道为什么啊。主机是DSP,从机的地址为0x90;
选的是七位地址模式(好像是利用七位地址模式不行)还有就是例程中在发送时,先往I2CDXR发送两字节地址,再接着发送四字节数据后才配置I2CMDR。个人理解是否应一个一个的发数据,在每一帧发送数据的时候找好对应的标志位,因为发送寄存器是只有一个的,一次写那么多,怎么发呢?我把我写的程序放上去,麻烦知道看看,不要说给你个官方,因为我看了例程,没看懂。




#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File


// Note: I2C Macros used in this example can be found in the
// DSP2833x_I2C_defines.h file


// Prototype statements for functions found within this file.
void   I2CA_Init(void);
void I2CA_WriteData(Uint16 data);//写数据


#define I2C_SLAVE_ADDR        0x91//从地址
#define I2C_NUMBYTES          4//传输字节数
#define I2C_EEPROM_HIGH_ADDR  0x00//高位地址
#define I2C_EEPROM_LOW_ADDR   0x30//低位地址


void main(void)
{
   
   Uint16 i;




// Step 1. Initialize System Control:
// PLL, WatchDog, enable Peripheral Clocks
// This example function is found in the DSP2833x_SysCtrl.c file.
   InitSysCtrl();




// Step 2. Initalize GPIO:
// This example function is found in the DSP2833x_Gpio.c file and
// illustrates how to set the GPIO to it's default state.
// InitGpio();
// Setup only the GP I/O only for I2C functionality
   InitI2CGpio();


// Step 3. Clear all interrupts and initialize PIE vector table:
// Disable CPU interrupts
   DINT;


// Initialize PIE control registers to their default state.
// The default state is all PIE interrupts disabled and flags
// are cleared.
// This function is found in the DSP2833x_PieCtrl.c file.
   InitPieCtrl();


// Disable CPU interrupts and clear all CPU interrupt flags:
   IER = 0x0000;
   IFR = 0x0000;


// Initialize the PIE vector table with pointers to the shell Interrupt
// Service Routines (ISR).
// This will populate the entire table, even if the interrupt
// is not used in this example.  This is useful for debug purposes.
// The shell ISR routines are found in DSP2833x_DefaultIsr.c.
// This function is found in DSP2833x_PieVect.c.
   InitPieVectTable();


// Interrupts that are used in this example are re-mapped to
// ISR functions found within this file.
   EALLOW;        // This is needed to write to EALLOW protected registers
  // PieVectTable.I2CINT1A = &i2c_int1a_isr;
   EDIS;   // This is needed to disable write to EALLOW protected registers


// Step 4. Initialize all the Device Peripherals:
// This function is found in DSP2833x_InitPeripherals.c
// InitPeripherals(); // Not required for this example
   I2CA_Init();






// Enable interrupts required for this example


// Enable I2C interrupt 1 in the PIE: Group 8 interrupt 1
   PieCtrlRegs.PIEIER8.bit.INTx1 = 1;


// Enable CPU INT8 which is connected to PIE group 8
//   IER |= M_INT8;
   EINT;   
         I2CA_WriteData(0x0000);     
}   // end of main


void I2CA_Init(void)
{
   // Initialize I2C
   I2caRegs.I2CMDR.bit.IRS = 0;
   I2caRegs.I2CSAR = 0x0090;                // Slave address - EEPROM control code


   #if (CPU_FRQ_150MHZ)             // Default - For 150MHz SYSCLKOUT
        I2caRegs.I2CPSC.all = 14;   // Prescaler - need 7-12 Mhz on module clk (150/15 = 10MHz)
   #endif
   #if (CPU_FRQ_100MHZ)             // For 100 MHz SYSCLKOUT
     I2caRegs.I2CPSC.all = 9;            // Prescaler - need 7-12 Mhz on module clk (100/10 = 10MHz)
   #endif


   I2caRegs.I2CCLKL = 45;                        // NOTE: must be non zero
   I2caRegs.I2CCLKH = 45;                        // NOTE: must be non zero
   I2caRegs.I2CIER.all = 0x24;                // Enable SCD & ARDY interrupts


   I2caRegs.I2CMDR.all = 0x0020;        // Take I2C out of reset

                                                                           // Stop I2C when suspended


//   I2caRegs.I2CSTR.bit.ARDY=1;
//   I2caRegs.I2CFFTX.all = 0x6000;        // Enable FIFO mode and TXFIFO
//   I2caRegs.I2CFFRX.all = 0x2040;        // Enable RXFIFO, clear RXFFINT,




}




void I2CA_WriteData(Uint16 data)
{
  char Busy_flag;
   Busy_flag = I2caRegs.I2CSTR.bit.BB;//判断总线是否忙
   if(!Busy_flag)
   {   
          //  I2caRegs.I2CSAR = 0xF0;
            I2caRegs.I2CSAR = 0x90;
              I2caRegs.I2CCNT = 1;                    
        I2caRegs.I2CDXR = data;
      
      while(I2caRegs.I2CSTR.bit.XRDY==0)
       I2caRegs.I2CMDR.all = 0x6E20;     
      //  while(I2caRegs.I2CSTR.bit.XRDY==1)
      //    I2caRegs.I2CDXR = data;
         
             if(I2caRegs.I2CSTR.bit.SCD==0)
                        for(;;);
              if(I2caRegs.I2CSTR.bit.SCD==1)
            I2CA_WriteData(0x00);
}




}


相关帖子

沙发
海中水| | 2015-4-20 19:43 | 只看该作者
刚刚解释过了,我讲的不清楚吗?还有就是你最后一句为什么会写I2CA_WriteData(0x00),这也是例程上面的吗?
你前面写的三条语句并没有发送,只是暂时保存在了寄存器里面。然后你循环等待发送就绪,等待中你在不停的对I2C模块进行配置。

使用特权

评论回复
板凳
1831249703|  楼主 | 2015-4-27 12:44 | 只看该作者
海中水 发表于 2015-4-20 19:43
刚刚解释过了,我讲的不清楚吗?还有就是你最后一句为什么会写I2CA_WriteData(0x00),这也是例程上面的吗?
...

恩,您什么时候回上海?

使用特权

评论回复
地板
海中水| | 2015-4-27 15:51 | 只看该作者
1831249703 发表于 2015-4-27 12:44
恩,您什么时候回上海?

晚点时间吧!现在在深圳,也是处理和I2C有关的问题。

使用特权

评论回复
5
1831249703|  楼主 | 2015-5-13 17:22 | 只看该作者
海中水 发表于 2015-4-27 15:51
晚点时间吧!现在在深圳,也是处理和I2C有关的问题。

你好,i2c跟谁通讯呢?你做过跟ads1115通讯的吗?

使用特权

评论回复
6
海中水| | 2015-5-14 22:41 | 只看该作者
1831249703 发表于 2015-5-13 17:22
你好,i2c跟谁通讯呢?你做过跟ads1115通讯的吗?

没有和谁通讯,就是一般的基于I2C进行的向某地址发送数据就行了,我这刚从深圳回来,会马上搞定。我现在做的产品通讯协议就是基于I2C的。

使用特权

评论回复
7
1831249703|  楼主 | 2015-5-18 13:11 | 只看该作者
海中水 发表于 2015-5-14 22:41
没有和谁通讯,就是一般的基于I2C进行的向某地址发送数据就行了,我这刚从深圳回来,会马上搞定。我现在 ...

你做过跟ads1115通讯吗

使用特权

评论回复
8
海中水| | 2015-5-18 19:42 | 只看该作者
1831249703 发表于 2015-5-18 13:11
你做过跟ads1115通讯吗

没有,不过做过的有PCF8563,EEPROM等。应该都是雷同的,唉!一直说帮一个论坛朋友写程序也一直忘记,这两天赶紧写了吧!

使用特权

评论回复
9
XINGFUDEWUNAI| | 2015-5-18 20:18 | 只看该作者
楼主,请问你的I2C程序的问题解决了吗?我现在调试I2C也遇到你这样的问题,SDA一直不变,这是怎么回事?谢谢

使用特权

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

本版积分规则

19

主题

125

帖子

2

粉丝