Hi, Im working on an I2C communication with MS5803-01BA pressure sensor using TMS320F28335 prossesor.
I constructed a code with some examples, and I did not received coefficient values from the sensor...
I think I did something wrong with the code, but I can't find what the problem is.
here is the code.
If anyone knows the problem, reply for me please:)
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
#include "DSP2833x_I2c_defines.h" // useful defines for I2C initialization
interrupt void I2cInt1a_Isr(void);
void I2CA_Write(int16);
void I2CA_Read(int16);
void I2CA_Wait(void);
#define slave_addr_w 0xEE //238//
#define slave_addr_r 0xEF //239//
Uint16 i,j;
Uint16 PROM_cmd;
Uint16 Loop_cnt;
Uint16 I2cIsrTicker;
Uint16 InData[3]={0,0,0};
Uint16 coefficient[8]={0,0,0,0,0,0,0,0};
Uint16 I2cIndex;
Uint16 I2cIntSource;
int32 I2cDelay;
Uint32 I2cResetDelay;
// main start
void main(void)
{
DINT;
InitSysCtrl();
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.I2CINT1A = &I2cInt1a_Isr;
EDIS;
// I2C setup
EALLOW;
GpioCtrlRegs.GPBMUX1.bit.GPIO32 = 1; // Configure GPIO32 for SDAA operation
GpioCtrlRegs.GPBMUX1.bit.GPIO33 = 1; // Configure GPIO33 for SCLA operation
EDIS;
// I2C initialization
I2caRegs.I2CSAR = 0xEE;
I2caRegs.I2COAR = 0xE0;
I2caRegs.I2CPSC.all = 14;//Mhz on module clk
I2caRegs.I2CCLKL = 10;
I2caRegs.I2CCLKH = 5;
I2caRegs.I2CIER.all = 0x28;
I2caRegs.I2CMDR.bit.IRS = 1; // Take I2C out of reset
I2caRegs.I2CMDR.bit.STT=1;
I2caRegs.I2CMDR.bit.STP=1;
I2caRegs.I2CFFTX.all = 0x6000; // Enable FIFO mode and TXFIFO
I2caRegs.I2CFFRX.all = 0x2040; // Enable RXFIFO, clear RXFFINT,
PieCtrlRegs.PIEIER8.bit.INTx1 = 1;
IER |= M_INT8;
// LED
EALLOW;
GpioCtrlRegs.GPADIR.bit.GPIO20 = 1;
GpioCtrlRegs.GPADIR.bit.GPIO21 = 1;
EDIS;
Loop_cnt = 0;
I2cIsrTicker = 0;
I2cIndex = 0;
I2cDelay = 50;
I2cResetDelay = 0;
EINT; // Enable Global interrupt INTM
ERTM; // Enable Global realtime interrupt DBGM
// MS5803 reset
I2caRegs.I2CCNT = 1; // 1 Byte being tranferred
I2caRegs.I2CDXR = 30; //0x1E; // Send Register to be updated
I2caRegs.I2CMDR.bit.FREE=1;
I2caRegs.I2CMDR.bit.STT=1;
I2caRegs.I2CMDR.bit.STP=1;
I2caRegs.I2CMDR.bit.MST=1;
I2caRegs.I2CMDR.bit.TRX=1;
I2caRegs.I2CMDR.bit.IRS=1;
// I2C wait
I2CA_Wait();
// LED Toggling and wait for Reset
GpioDataRegs.GPATOGGLE.bit.GPIO20 = 1; // Toggle the pin
DELAY_US(300000);
// Read sensor coefficients
for(i=0;i<8;i++){
PROM_cmd=64+i*2;
I2caRegs.I2CSAR = slave_addr_w;
I2caRegs.I2CCNT = 1; // 1 Additional Byte being tranferred
I2caRegs.I2CDXR = PROM_cmd; // Send Register to be updated
I2caRegs.I2CMDR.bit.FREE=1;
I2caRegs.I2CMDR.bit.STT=1;
I2caRegs.I2CMDR.bit.STP=1;
I2caRegs.I2CMDR.bit.MST=1;
I2caRegs.I2CMDR.bit.TRX=1;
I2caRegs.I2CMDR.bit.IRS=1;
DELAY_US(I2cDelay);
I2caRegs.I2CSAR = slave_addr_r;
I2caRegs.I2CCNT = 2; // Set up receive of 2 bytes
I2caRegs.I2CMDR.bit.FREE=1;
I2caRegs.I2CMDR.bit.STT=1;
I2caRegs.I2CMDR.bit.STP=1;
I2caRegs.I2CMDR.bit.MST=1;
I2caRegs.I2CMDR.bit.TRX=0;
I2caRegs.I2CMDR.bit.IRS=1;
I2CA_Wait(); // Wait for I2C bus to clear
coefficient[i] = (InData[0]<<8) + InData[1];
}
}
// end of the main
//============================================================================================
void I2CA_Wait(void)
{
I2cResetDelay = 0;
while (I2caRegs.I2CMDR.bit.STP == 1) // Wait for Stop condition bit to be zero.
{
I2cResetDelay++;
if(I2cResetDelay >= 1E6)
{
I2cResetDelay = 0;
I2caRegs.I2CMDR.bit.IRS = 0;
I2caRegs.I2CMDR.bit.IRS = 1;
break;
}
}
while (I2caRegs.I2CSTR.bit.BB == 1) // Wait for Bus Busy to be zero.
{
I2cResetDelay++;
if(I2cResetDelay >= 1E6)
{
I2cResetDelay = 0;
I2caRegs.I2CMDR.bit.IRS = 0;
I2caRegs.I2CMDR.bit.IRS = 1;
break;
}
}
}
//============================================================================================
//============================================================================================
// Interrupt service routine
//--------------------------------------------------------------------------------------------
__interrupt void I2cInt1a_Isr(void)
{
I2cIsrTicker++;
// Read interrupt source
I2cIntSource = I2caRegs.I2CISRC.bit.INTCODE & 0x7;
switch(I2cIntSource)
{
case I2C_NO_ISRC: // =0
{
break;
}
case I2C_ARB_ISRC: // =1
{
break;
}
case I2C_NACK_ISRC: // =2
{
break;
}
case I2C_ARDY_ISRC: // =3
{
break;
}
case I2C_RX_ISRC: // =4
{
InData[I2cIndex++] = I2caRegs.I2CDRR;
break;
}
case I2C_TX_ISRC: // =5
{
break;
}
case I2C_SCD_ISRC: // =6
{
break;
}
case I2C_AAS_ISRC: // =7
{
break;
}
default:
{
asm(" NOP"); // No operation on invalid number
}
}
// Enable future I2C (PIE Group 8) interrupts
PieCtrlRegs.PIEACK.bit.ACK8 = 1;
}
//============================================================================================