|
接收数据8字节数据没有问题,接收字节头为0x01;正确后才开始接收后面的7个字节数据;当全部接收到后;把指定的8个字节数据发送出去,但是发送数据时有有问题
从示波器上看出,只能发送Tx_Data[7]的数据,前面的7个字节数据没有发出去。示波器图片如下
原程序如下:请大神帮助分析一下原因
#include "DSP28x_Project.h" // Device Headerfile and Examples Include File
void I2CA_Init(void);
interrupt void i2c_int1a_isr(void);
interrupt void i2c_int2a_isr(void);
void pass(void);
void fail(void);
void Delay(unsigned int x);
Uint16 PassCount;
Uint16 FailCount;
Uint16 buf[8];
int I2CWriteData();
int Tx_Data[8]={0x01,0x03,0x07,0x0f,0x1f,0x3f,0x7f,0x55};
int xx=0,ii=0;
void main(void)
{
InitSysCtrl(); //60Mhz
InitI2CGpio();
DINT;
InitPieCtrl();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
EALLOW;
PieVectTable.I2CINT1A = &i2c_int1a_isr; //basic I2C interrupts
EDIS;
I2CA_Init();
PieCtrlRegs.PIEIER8.bit.INTx1 = 1;
PieCtrlRegs.PIECTRL.bit.ENPIE = 1;
IER |= M_INT8;
EINT;
// Application loop
for(;;)
{
}
} // end of main
interrupt void i2c_int1a_isr(void)
{
Uint16 status;
unsigned int I2C_Count=0;
status = I2caRegs.I2CISRC.all;
if(status == 0x05) // 传输数据准备好
{
}
else if(status ==0x02) //无响应条件检测
{
}
else if(status ==0x04) // 接收数据准备好
{
buf[xx] = I2caRegs.I2CDRR;
//用I2C适配器调试,发现DSP只能设置为从接收才能接收到数据,改为主接收模式时,收不到数据,为什么?
if(buf[0]==0x01) xx=xx+1;
else xx=0;
if(xx>=8)
{
I2C_Count=0;
Delay(200);
I2CWriteData();
Delay(500);
I2caRegs.I2CMDR.bit.IRS = 0;
Delay(100);
I2caRegs.I2CMDR.all = 0x0020;
xx=0;
for(ii=0;ii<8;ii++)
{
buf[ii]=0;
}
}
}
PieCtrlRegs.PIEACK.bit.ACK8 = 1;
}
int I2CWriteData()
{
unsigned int Count=0;
if(I2caRegs.I2CMDR.bit.STP == 1) //停止状态
return 2;
I2caRegs.I2CSAR = 0x01; //存储被I2C主机发送到从机的从机地址
I2caRegs.I2CCNT = 8; //发送数据字节数
while(Count<8)
{
Delay(200);
I2caRegs.I2CDXR = Tx_Data[Count];
Count++;
}
I2caRegs.I2CMDR.all = 0x2620; //0b 0110 0110 1010 0000
return 0;
}
void I2CA_Init(void)
{
// Initialize I2C
I2caRegs.I2COAR = 0x01;
I2caRegs.I2CMDR.bit.IRS = 0;
I2caRegs.I2CPSC.all = 5; I2C输入时钟(SYSCLKOUT)/(IPSC+1)=60M/(5+1)=10M
I2caRegs.I2CCLKL = 120;
I2caRegs.I2CCLKH = 120; //Fscl = =40K
I2caRegs.I2CIER.bit.RRDY = 1;
I2caRegs.I2CIER.bit.NACK = 0;
I2caRegs.I2CIER.bit.XRDY = 1;
I2caRegs.I2CMDR.all = 0x0020;
}
|
|