发新帖我要提问
12
返回列表
打印

请问28335的I2C模块,在与从器件连接时,会从SCL引脚输出时钟信号么?

[复制链接]
楼主: thelust
手机看帖
扫描二维码
随时随地手机跟帖
21
zhangmangui| | 2015-4-18 17:55 | 只看该作者 回帖奖励 |倒序浏览
1831249703 发表于 2015-4-17 16:07
版主你好,我最近在调i2c的程序,但是一直调试不通,一直没有波形,你手头有调好的程序吗 ...

你先看看这个分享  
http://dl.21ic.com/download/tms320f28335-rar-ic-108192.html

使用特权

评论回复
22
lovecat2015| | 2015-4-19 09:12 | 只看该作者
你是啥时候测的呢,一般在读写的时候才会有时钟信号的

使用特权

评论回复
23
1831249703| | 2015-4-20 12:36 | 只看该作者
lovecat2015 发表于 2015-4-19 09:12
你是啥时候测的呢,一般在读写的时候才会有时钟信号的

最近这两天有波形了,但是波形对应的不对,我只发一帧,从开始到停止应该有八个周期的scl,但是有九个,我把我的程序传给你,麻烦您看看吧

#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 = 10;                        // NOTE: must be non zero
   I2caRegs.I2CCLKH = 5;                        // 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 = 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);
}


}

使用特权

评论回复
24
XINGFUDEWUNAI| | 2015-5-18 21:27 | 只看该作者
wangch_sh 发表于 2014-9-9 11:19
应该会的,肯定哪儿出问题了

大神,请问下,我的I2C程序发送,但是SDA引脚上测的波形一直不变。寄存器I2caRegs.I2CDXR的值在程序运行过程中是我赋值的值,但SDA与它对不上,而且改变发送数据,SDA的也不变,这是怎么回事?谢谢!

使用特权

评论回复
25
可可球| | 2015-5-18 21:31 | 只看该作者
循环读写,就能看到波形

谢谢分享经验

使用特权

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

本版积分规则