⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 se2pd.c

📁 DSP28X通訊程式
💻 C
字号:
/* ==============================================================================

System Name :   Serial EEPROM demo

File Name   :   SE2PD

Description :   This file contains the code to demonstrate the I2CSE2P_IO module.
   
Originator:     Settu D.
                Digital control systems Group
                Texas Instruments
LOOP-BACK SETUP
===============
                
                 ___________                          _________
                |           | SCL                SCL |         |
                |           |----------------------->|         |
                |           |                        |         |
                |           |                        |  I2C    |
                | TI C2000  | SDA                SDA | SEEPROM |
                |    DSP    |<---------------------->|         |
                |           |                        |         |
                |           |                        |         |
                |___________|                        |_________|


Note:  I/O pins for I2C signals viz., SCL & SDA can seleceted arbitrarily by 
       editing I2CMPIN.H and rebuiling the library.

Default I/O pin: SCL -----> PORTE, BIT1 
                 SDA -----> PORTE, BIT2
                 
This code sets-up the Timer interrupt to invoke the Serial EEPROM driver tick in 
20KHz ISR loop. In the background loop, 10 element write buffer (writeBuf) 
is written to the serial EEPROM and read back (to readBuf) from serial EEPROM.

If the driver works, the writeData buffer and readData buffer 
should have same data.
         
*/
#include "DSP28_Device.h"
#include <i2cse2p.h>

#define CPU_FREQ 	150E6
#define PWM_FREQ 	250E3
#define PWM_PRD 	CPU_FREQ/PWM_FREQ


interrupt void timer2_intr(void);

/* Instance the I2C bus serial EEPROM driver                    */  
I2CSE2P_IO se2p=I2CSE2P_IO_DEFAULTS;                                  

/* Instance serial EEPROm data transfer structure               */
I2CSE2P_DATA    writeData, readData;

unsigned int i,enable;
unsigned int writeBuf[10],readBuf[10];
      
void main()
{    


// Step 1. Initialize System Control registers, PLL, WatchDog, 
   InitSysCtrl();

// Step 2: Initialize I2C serial EEPROM driver     
    se2p.init(&se2p); 
           
    for(i=0;i<10;i++)       /* Initialise Write buff                    */
    writeBuf[i]=i;
    
    writeData.dataPtr=writeBuf;
    writeData.nrData=10;
    writeData.addr=0x00; 
    writeData.Did_Blknr=0x00;
                              
    readData.dataPtr=readBuf;
    readData.nrData=10;
    readData.addr=0x00; 
    readData.Did_Blknr=0x00;

// Step 3: Initialize Event Manager
	InitEv();
    EvaRegs.T1PR = PWM_PRD;                // Setup period register    
    EvaRegs.T1CMPR = PWM_PRD;              // Setup T1 compare value for 0% duty cycle
 
// Step 4: Initialize PIE module 
 	InitPieCtrl();
	EALLOW;				// This is needed to write to EALLOW protected registers
	PieVectTable.T1PINT = &timer2_intr;
	EDIS;   			// This is needed to disable write to EALLOW protected registers


// Step 5: Enable core interrupt
	IER |= M_INT2;		// EV Interrupt


	EINT;   // Enable Global interrupt INTM
	ERTM;	// Enable Global realtime interrupt DBGM    
	
 
// Step 6: Program the I2C serial EEPROM
    enable=1;
    
    while(1)
    {   

   
    if(enable==1)
        { 
          while(!i2cSe2pFree(&se2p));
          i2cSe2pWrite(&se2p, &writeData);
                                            
          while(!i2cSe2pFree(&se2p));
          i2cSe2pRead(&se2p, &readData);
          
          while(!i2cSe2pFree(&se2p));
          
          enable=0;         /* Put breakpoint here and observe that
                               write and read buffer are same   */  
          
        } 
    }       
        
}  /* End: main() */



interrupt void timer2_intr(void)
{   
// Note: To be safe, use a mask value to write to the entire
// EVAIFRA register.  Writing to one bit will cause a read-modify-write
// operation that may have the result of writing 1's to clear 
// bits other then those intended.
    se2p.tick(&se2p); 

// Note: To be safe, use a mask value to write to the entire
// EVAIFRA register.  Writing to one bit will cause a read-modify-write
// operation that may have the result of writing 1's to clear 
// bits other then those intended. 
    EvaRegs.EVAIFRA.all = BIT7;
	
// Acknowledge interrupt to recieve more interrupts from PIE group 2
	PieCtrlRegs.PIEACK.all = PIEACK_GROUP2;
}

      

  
       

     

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -