12
返回列表 发新帖

[DSP编程] DSP28335 I2C 程序

[复制链接]
楼主: pandabin
| 2015-4-20 19:55 | 显示全部楼层
1831249703 发表于 2015-4-20 19:30
这些位的设置我知道,版主不好意思,让你看的是我写的,不是例程,下边的是例程就是例程中在发送时,先往 ...

哦!是这样啊!这是因为他在初始化的时候初始化为了FIFO模式。
| 2015-4-20 20:09 | 显示全部楼层
海中水 发表于 2015-4-20 19:55
哦!是这样啊!这是因为他在初始化的时候初始化为了FIFO模式。



#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(0xcc);     
}   // 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)
{
Uint16 i;

   // 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.
  
  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 = 0x6F20;     


}版主这是我又写的函数,如果我想发送两帧数据,循环发,该怎么设置,麻烦版主在我的基础上添加代码就好,感激,我搞了一个星期了,例程我也看了,就是没把握住重点,我只看看版主怎么改的,通过改我能判断我哪里理解错了,如果只是让我参考例程,我还是不会改,因为我看不懂例程。
| 2015-4-21 10:08 | 显示全部楼层
1831249703 发表于 2015-4-20 20:09
#include "DSP28x_Project.h"     // Device Headerfile and Examples Include File

// Note: I2C Mac ...

你就是想循环不停的发送两针数据吗?地址需要改变吗?
| 2015-4-21 14:56 | 显示全部楼层
海中水 发表于 2015-4-21 10:08
你就是想循环不停的发送两针数据吗?地址需要改变吗?

地址不变,每次只发送两帧数据,循环发
| 2015-4-24 20:13 | 显示全部楼层
1831249703 发表于 2015-4-21 14:56
地址不变,每次只发送两帧数据,循环发

不好意思,这两天在深圳遇见电麻烦事,等回上海后在给你调试程序,望见谅。
| 2017-5-10 17:03 | 显示全部楼层
学习一下,做个标记
| 2018-6-15 00:23 | 显示全部楼层

哎,遇到i2C锁死情况,虽然是用的是和楼主一个的实例程序,我的slaveaddress=0x51;本来就是七位的,也就是没有右移位,可是还是会出现总线处于BB状态。
只要读过一次EEPROM后必定会出现,总线锁死,长期处于BB状态。
| 2018-6-15 00:24 | 显示全部楼层
其实我没有看懂,楼主怎么跳出的BB状态的手法。
有一些参考资料,CDN上的
扫描二维码,随时随地手机跟帖
您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复

您需要登录后才可以回帖
登录 | 注册
高级模式
我要创建版块 申请成为版主

论坛热帖

关闭

热门推荐上一条 /4 下一条

快速回复 返回顶部 返回列表