调试28335I2C和ADS1115的串口通信,程序如下,调试不出结果来,可以麻烦各位帮忙看一下问题在哪儿吗?
#include "DSP2833x_Device.h" // DSP2833x Headerfile Include File
#include "DSP2833x_Examples.h" // DSP2833x Examples Include File
// Prototype statements for functions found within this file.
void I2CA_Init(void);
Uint16 I2CA_WriteData(struct I2CMSG *msg);
Uint16 I2CA_ReadData(struct I2CMSG *msg);
interrupt void i2c_int1a_isr(void);
void InitEPwm1Example(void);
#define I2C_SLAVE_ADDR 0x48 //如果要用第二组AD 通道【5、6、7、8】 需要把此处改为0x49
#define I2C_NUMBYTES1 3
#define I2C_NUMBYTES2 1
#define I2C_NUMBYTES3 2
#define I2C_EEPROM_HIGH_ADDR 0x00 //数据的写入地址高位
#define I2C_EEPROM_LOW_ADDR 0x00 //数据的写入地址低位
// Global variables
// Two bytes will be used for the outgoing address,
// thus only setup 14 bytes maximum
//------------------------------------------------------------------------------------------------------------------------------
struct I2CMSG I2cMsgOut1 = { I2C_MSGSTAT_SEND_WITHSTOP, //发送带停止位数据:这是为写数据而设的状态,写入地址和数据之后发个停止位告诉存储器数据写入完毕。
I2C_SLAVE_ADDR,
I2C_NUMBYTES1,
I2C_EEPROM_HIGH_ADDR,
I2C_EEPROM_LOW_ADDR,
0x01, // 配置寄存器地址Msg Byte 1
0x40, // 控制字 单端输入 Msg Byte 2 [把0x40改成0x50 外部电源接5和6 对应通道2 把0x40改成0x60,就是通道3 把0x40改成0x70,就是通道4]
0xe3, // 转换模式为连续模式 Msg Byte 3
};//发送数据1
//I2cMsgOut1.NumOfBytes=3;
struct I2CMSG I2cMsgOut2 = { I2C_MSGSTAT_SEND_WITHSTOP,
I2C_SLAVE_ADDR,
I2C_NUMBYTES2,
I2C_EEPROM_HIGH_ADDR,
I2C_EEPROM_LOW_ADDR,
0x00, // 写转换寄存器地址 Msg Byte 1
};
//I2cMsgOut2.NumOfBytes=1;
struct I2CMSG I2cMsgIn1 = { I2C_MSGSTAT_SEND_NOSTOP,
I2C_SLAVE_ADDR,
I2C_NUMBYTES3,
I2C_EEPROM_HIGH_ADDR,
I2C_EEPROM_LOW_ADDR };
//------------------------------------------------------------------------------------------------------------------------------
struct I2CMSG *CurrentMsgPtr; // Used in interrupts
Uint16 Count;
float result_0;
float result_1;
Uint16 CH;
//Uint16 FailCount;
void main(void) {
Uint16 Error;
Uint16 i;
CurrentMsgPtr = &I2cMsgOut1;
InitSysCtrl();
InitEPwm1Gpio();
// InitEPwm2Gpio();
// InitEPwm3Gpio();
// InitEPwm4Gpio();
InitI2CGpio();
InitEPwm1Example();
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
I2CA_Init();
Count = 0;
for (i = 0; i < I2C_MAX_BUFFER_SIZE; i++) {
I2cMsgIn1.MsgBuffer[i] = 0x0000;
} //clearing incoming message buffer
// 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;
for (;;) {
//--------------------------------------------------------------------------
if (I2cMsgOut1.MsgStatus == I2C_MSGSTAT_SEND_WITHSTOP)
{
Error = I2CA_WriteData(&I2cMsgOut1);
if (Error == I2C_SUCCESS)
{
CurrentMsgPtr = &I2cMsgOut1;
I2cMsgOut1.MsgStatus = I2C_MSGSTAT_WRITE_BUSY;
}
} //end of write section
if (I2cMsgOut1.MsgStatus == I2C_MSGSTAT_INACTIVE)
{
if (I2cMsgOut2.MsgStatus == I2C_MSGSTAT_SEND_WITHSTOP)
{
Error = I2CA_WriteData(&I2cMsgOut2);
if (Error == I2C_SUCCESS)
{
CurrentMsgPtr = &I2cMsgOut2;
I2cMsgOut2.MsgStatus = I2C_MSGSTAT_WRITE_BUSY;
}
}
}
if (I2cMsgOut1.MsgStatus == I2C_MSGSTAT_INACTIVE) //#define I2C_MSGSTAT_INACTIVE 0x0000
{
// Check incoming message status.
if (I2cMsgIn1.MsgStatus == I2C_MSGSTAT_SEND_NOSTOP) //#define I2C_MSGSTAT_SEND_NOSTOP 0x0020
{
// EEPROM address setup portion
while (I2CA_ReadData(&I2cMsgIn1) != I2C_SUCCESS) // #define I2C_SUCCESS 0x0000
{
CH = 0x0001;
}
// Update current message pointer and message status
CurrentMsgPtr = &I2cMsgIn1;
I2cMsgIn1.MsgStatus = I2C_MSGSTAT_SEND_NOSTOP_BUSY; //#define I2C_MSGSTAT_SEND_NOSTOP_BUSY 0x0021
}
else if (I2cMsgIn1.MsgStatus == I2C_MSGSTAT_RESTART)
{
while (I2CA_ReadData(&I2cMsgIn1) != I2C_SUCCESS)
{
}
CurrentMsgPtr = &I2cMsgIn1;
I2cMsgIn1.MsgStatus = I2C_MSGSTAT_READ_BUSY;
}
}
}
}
|