[ݳXȲέp


[求助] 關於dsp 28335的I2C的使用方式

非8051系列的單晶片軟硬體請在此區討論(CPU介面周邊,或MICRO CHIP等....)

版主: charlesliao

[求助] 關於dsp 28335的I2C的使用方式

文章chineseameri 發表於 週二 6月 17, 2014 11:03 pm

目前小弟是使用TM的DPS TMS320F28335 接收ADXL345上的訊號
目前電路設定正確無誤,也有使用其他版子測試過ADXL345抓取訊號,也可以有值輸出。
但因為需要做比較複雜的數學計算,所以使用DSP
此程式是參考TI所提供的I2C EEPROM範例改寫而成,但不知道為什麼在I2C讀取上,始終進不去ARDY的中斷
跪求各位先進指點 ORZ !!

代碼: 選擇全部
#include "DSP28x_Project.h"
void I2C_Init(void);
void I2C_Write(void);
void I2C_Read(void);
interrupt void i2c_int1a_isr(void);

#define SLAVE_ADDR             0x53 //ADXL345
#define W_HI_ADD              0xA0
#define R_HI_ADD              0xA0
#define W_LO_ADD              0x06
#define R_LO_ADD              0x07
#define Register_2D           0x2D
#define Register_X0           0x32
#define Register_X1           0x33
#define Register_Y0           0x34
#define Register_Y1           0x35
#define Register_Z0           0x36
#define Register_Z1           0x37

#define i2c_msg_wACT          0
#define i2c_msg_wBusy         1

#define i2c_msg_rACT          3
#define i2c_msg_rWBusy        4
#define i2c_msg_rREST         5
#define i2c_msg_rRBusy        6

Uint16 DATA[2];
Uint16 i2cStatus = 0;
Uint16 interrupt_SCD = 0;
Uint16 interrupt_ARDY = 0;

void main(void)

{
   Uint16 i;
   InitSysCtrl();
   InitI2CGpio();
   DINT;
   InitPieCtrl();

// Disable CPU interrupts and clear all CPU interrupt flags:

   IER = 0x0000;
   IFR = 0x0000;

   InitPieVectTable();

   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
   
   I2C_Init();
   for(i=0;i<2;i++)
   {
       DATA[i]=0x0000;
   }
   // 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;

   I2C_Write();

   for(;;)
   {
      I2C_Read();
   }   // end of for(;;)

}   // end of main


void I2C_Init(void)
{
   // Initialize I2C
   I2caRegs.I2CSAR = SLAVE_ADDR;// Slave address - EEPROM control code

   //I2caRegs.I2COAR = 0x19;         // Master address

   #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.I2CMDR.all = 0000 0010 0000 0000

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

   i2cStatus=i2c_msg_wACT;

   return;
}

void I2C_Write(void)
{
   if(i2cStatus==i2c_msg_wACT)
   {
      I2caRegs.I2CCNT = 2;
      I2caRegs.I2CSAR = SLAVE_ADDR;          //Select POWER_CTL register in sensor
      //I2caRegs.I2CDXR = HIGH_ADDR;
      I2caRegs.I2CDXR = Register_2D;
      I2caRegs.I2CDXR = 0x0A;
      I2caRegs.I2CMDR.all = 0x6E20;           //Generate start and stop, master transmitter
      i2cStatus=i2c_msg_wBusy;
   }
   while(1)    // wait for STOP condition
   {
      if(i2cStatus==i2c_msg_rACT)
      {
         break;
      }
   }
}

void I2C_Read(void)
{
   if(i2cStatus == i2c_msg_rACT)
   {
      I2caRegs.I2CSAR = SLAVE_ADDR;
      //I2caRegs.I2CDXR = Register_Y0;
      I2caRegs.I2CDXR = Register_Y1;
      //I2caRegs.I2CCNT = 2;
      I2caRegs.I2CCNT = 1;
      I2caRegs.I2CMDR.all = 0x2620; //0110 0110 0010 0000
      i2cStatus = i2c_msg_rWBusy;
      while(1)    // wait for STOP condition
      {
         if(i2cStatus==i2c_msg_rREST)
         {
            break;
         }
      }
   }

   else if(i2cStatus == i2c_msg_rREST)
   {
      i2cStatus = 2;
      I2caRegs.I2CCNT = 1;   // Setup how many bytes to expect
       I2caRegs.I2CMDR.all = 0x2C20; //0010 1100 0010 0000 Send restart as master receive
       i2cStatus=i2c_msg_rRBusy;
      while(1)    // wait for STOP condition
      {
         if(i2cStatus==i2c_msg_rACT)
         {
            break;
         }
      }

   }

}

interrupt void i2c_int1a_isr(void)     // I2C-A
{
   // Read interrupt source
   Uint16 IntSource;
   IntSource = I2caRegs.I2CISRC.all;
   // Interrupt source = Register Access Ready
   // This interrupt is used to determine when the EEPROM address setup portion of the
   // read data communication is complete. Since no stop bit is commanded, this flag
   // tells us when the message has been sent instead of the SCD flag. If a NACK is
   // received, clear the NACK bit and command a stop. Otherwise, move on to the read
   // data portion of the communication.
   if(IntSource == I2C_SCD_ISRC)
   {
      if(i2cStatus==i2c_msg_wBusy)
      {
         i2cStatus=i2c_msg_rACT;
         interrupt_SCD++;
      }
      else if(i2cStatus==i2c_msg_rRBusy)
      {
         DATA[1]=I2caRegs.I2CDRR;
         i2cStatus=i2c_msg_rACT;
      }

   }
   else if(IntSource == I2C_ARDY_ISRC)
   {

      if(I2caRegs.I2CSTR.bit.NACK == 1)
      {
         I2caRegs.I2CMDR.bit.STP = 1;
         I2caRegs.I2CSTR.all = I2C_CLR_NACK_BIT;
         interrupt_ARDY++;
      }
      else if(i2cStatus==i2c_msg_rWBusy)
      {
         i2cStatus=i2c_msg_rREST;
      }
   }  // end of register access ready

   /*else
   {
      // Generate some error due to invalid interrupt source
      asm("   ESTOP0");
   }*/

   // Enable future I2C (PIE Group 8) interrupts
   PieCtrlRegs.PIEACK.all = PIEACK_GROUP8;
}

//==================== =======================================================

// No more.

//===========================================================================
chineseameri
 
文章: 1
註冊時間: 週一 8月 01, 2011 2:55 pm

回到 其他類單晶片--相關的軟硬體討論區

誰在線上

正在瀏覽這個版面的使用者:沒有註冊會員 和 2 位訪客

cron