TI中文支持网
TI专业的中文技术问题搜集分享网站

28035的I2C例程

有谁最近在调试28035的I2C程序吗,controlsuite里面的例程中read函数如下

Uint16 I2CA_ReadData(struct I2CMSG *msg)
{
// Wait until the STP bit is cleared from any previous master communication.
// Clearing of this bit by the module is delayed until after the SCD bit is
// set. If this bit is not checked prior to initiating a new message, the
// I2C could get confused.
if (I2caRegs.I2CMDR.bit.STP == 1)
{
return I2C_STP_NOT_READY_ERROR;
}

I2caRegs.I2CSAR = msg->SlaveAddress;

if(msg->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP)
{
// Check if bus busy
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
I2caRegs.I2CCNT = 2;
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;
I2caRegs.I2CMDR.all = 0x2620; // Send data to setup EEPROM address
}
else if(msg->MsgStatus == I2C_MSGSTAT_RESTART)
{
I2caRegs.I2CCNT = msg->NumOfBytes; // Setup how many bytes to expect
I2caRegs.I2CMDR.all = 0x2C20; // Send restart as master receiver
}

return I2C_SUCCESS;
}

我不明白为什么在写函数中要对I2CDXR寄存器赋地址值,而且是连续写入MemoryHighAddr和MemoryLowAddr,这要操作时MemoryHighAddr不就被覆盖了吗?

Emma Wang:

这个程序实现的功能是通过I2C发送字到EEPROM然后在回读。

这两个地址是EEPROM的地址:

Uint16 MemoryHighAddr; // EEPROM address of data associated with msg (high byte) Uint16 MemoryLowAddr; // EEPROM address of data associated with msg (low byte)

28035的I2C模块有一个4word 的FIFO,所以不会被覆盖。

详细资料参考I2C模块的手册:

http://www.ti.com/lit/ug/sprufz9d/sprufz9d.pdf

有谁最近在调试28035的I2C程序吗,controlsuite里面的例程中read函数如下

Uint16 I2CA_ReadData(struct I2CMSG *msg)
{
// Wait until the STP bit is cleared from any previous master communication.
// Clearing of this bit by the module is delayed until after the SCD bit is
// set. If this bit is not checked prior to initiating a new message, the
// I2C could get confused.
if (I2caRegs.I2CMDR.bit.STP == 1)
{
return I2C_STP_NOT_READY_ERROR;
}

I2caRegs.I2CSAR = msg->SlaveAddress;

if(msg->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP)
{
// Check if bus busy
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
I2caRegs.I2CCNT = 2;
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;
I2caRegs.I2CMDR.all = 0x2620; // Send data to setup EEPROM address
}
else if(msg->MsgStatus == I2C_MSGSTAT_RESTART)
{
I2caRegs.I2CCNT = msg->NumOfBytes; // Setup how many bytes to expect
I2caRegs.I2CMDR.all = 0x2C20; // Send restart as master receiver
}

return I2C_SUCCESS;
}

我不明白为什么在写函数中要对I2CDXR寄存器赋地址值,而且是连续写入MemoryHighAddr和MemoryLowAddr,这要操作时MemoryHighAddr不就被覆盖了吗?

ruiping zhao:

回复 Emma Wang:

王工,4word 的FIFO分别存放MemoryHighAddr,MemoryLowAddr和2字节的数据吗,如果要发送接受4个字节,是否还能用FIFO模式呢

有谁最近在调试28035的I2C程序吗,controlsuite里面的例程中read函数如下

Uint16 I2CA_ReadData(struct I2CMSG *msg)
{
// Wait until the STP bit is cleared from any previous master communication.
// Clearing of this bit by the module is delayed until after the SCD bit is
// set. If this bit is not checked prior to initiating a new message, the
// I2C could get confused.
if (I2caRegs.I2CMDR.bit.STP == 1)
{
return I2C_STP_NOT_READY_ERROR;
}

I2caRegs.I2CSAR = msg->SlaveAddress;

if(msg->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP)
{
// Check if bus busy
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
I2caRegs.I2CCNT = 2;
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;
I2caRegs.I2CMDR.all = 0x2620; // Send data to setup EEPROM address
}
else if(msg->MsgStatus == I2C_MSGSTAT_RESTART)
{
I2caRegs.I2CCNT = msg->NumOfBytes; // Setup how many bytes to expect
I2caRegs.I2CMDR.all = 0x2C20; // Send restart as master receiver
}

return I2C_SUCCESS;
}

我不明白为什么在写函数中要对I2CDXR寄存器赋地址值,而且是连续写入MemoryHighAddr和MemoryLowAddr,这要操作时MemoryHighAddr不就被覆盖了吗?

Xupeng(FAA) He:

回复 ruiping zhao:

这样修改结构体就可以发送四个字节数据,分别是十六进制数11、22、33、44。注意结构体的第三个成员是4,代表字节数

struct I2CMSG I2cMsgOut1={I2C_MSGSTAT_SEND_WITHSTOP, I2C_SLAVE_ADDR, 4, I2C_EEPROM_HIGH_ADDR, I2C_EEPROM_LOW_ADDR, 0x11, // Msg Byte 1 0x22, // Msg Byte 2 0x33, // Msg Byte 3 0x44}; // Msg Byte 4

有谁最近在调试28035的I2C程序吗,controlsuite里面的例程中read函数如下

Uint16 I2CA_ReadData(struct I2CMSG *msg)
{
// Wait until the STP bit is cleared from any previous master communication.
// Clearing of this bit by the module is delayed until after the SCD bit is
// set. If this bit is not checked prior to initiating a new message, the
// I2C could get confused.
if (I2caRegs.I2CMDR.bit.STP == 1)
{
return I2C_STP_NOT_READY_ERROR;
}

I2caRegs.I2CSAR = msg->SlaveAddress;

if(msg->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP)
{
// Check if bus busy
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
I2caRegs.I2CCNT = 2;
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;
I2caRegs.I2CMDR.all = 0x2620; // Send data to setup EEPROM address
}
else if(msg->MsgStatus == I2C_MSGSTAT_RESTART)
{
I2caRegs.I2CCNT = msg->NumOfBytes; // Setup how many bytes to expect
I2caRegs.I2CMDR.all = 0x2C20; // Send restart as master receiver
}

return I2C_SUCCESS;
}

我不明白为什么在写函数中要对I2CDXR寄存器赋地址值,而且是连续写入MemoryHighAddr和MemoryLowAddr,这要操作时MemoryHighAddr不就被覆盖了吗?

Emma Wang:

回复 ruiping zhao:

FIFO最多支持8bytes的缓存:

MemoryHighAddr和MemoryLowAddr已经占用了4个bytes,还能发送和接受最多4个bytes,在这个位置修改:

更改I2C_NUMBYTES为4,在后面增加两个数据。

Emma

有谁最近在调试28035的I2C程序吗,controlsuite里面的例程中read函数如下

Uint16 I2CA_ReadData(struct I2CMSG *msg)
{
// Wait until the STP bit is cleared from any previous master communication.
// Clearing of this bit by the module is delayed until after the SCD bit is
// set. If this bit is not checked prior to initiating a new message, the
// I2C could get confused.
if (I2caRegs.I2CMDR.bit.STP == 1)
{
return I2C_STP_NOT_READY_ERROR;
}

I2caRegs.I2CSAR = msg->SlaveAddress;

if(msg->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP)
{
// Check if bus busy
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
I2caRegs.I2CCNT = 2;
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;
I2caRegs.I2CMDR.all = 0x2620; // Send data to setup EEPROM address
}
else if(msg->MsgStatus == I2C_MSGSTAT_RESTART)
{
I2caRegs.I2CCNT = msg->NumOfBytes; // Setup how many bytes to expect
I2caRegs.I2CMDR.all = 0x2C20; // Send restart as master receiver
}

return I2C_SUCCESS;
}

我不明白为什么在写函数中要对I2CDXR寄存器赋地址值,而且是连续写入MemoryHighAddr和MemoryLowAddr,这要操作时MemoryHighAddr不就被覆盖了吗?

ruiping zhao:

回复 Emma Wang:

王工,感谢你的回复,我试过将程序改为I2C_NUMBYTES=4,并增加两个字节,但是实际运行时发送了4个,I2cMsgIn1.MsgBuffe却是[0,0,0,0],程序没有执行中断函数;另外这里的I2C_EEPROM_HIGH_ADDR和I2C_EEPROM_LOW_ADDR指什么地址,我理解是两个字节在EEPROM中的地址但为什么不随着字节增加而递增?换句话说,如果写入8个字节这里的I2C_EEPROM_HIGH_ADDR和I2C_EEPROM_LOW_ADDR也保持不变吗

#define I2C_SLAVE_ADDR        0x50

#define I2C_NUMBYTES          4

#define I2C_EEPROM_HIGH_ADDR  0x00

#define I2C_EEPROM_LOW_ADDR   0x30

 

// 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_NUMBYTES,

                          I2C_EEPROM_HIGH_ADDR,

                          I2C_EEPROM_LOW_ADDR,

                          0x12,                   // Msg Byte 1

                          0x13,

                          0x14,

                          0x15};                  // Msg Byte 2

有谁最近在调试28035的I2C程序吗,controlsuite里面的例程中read函数如下

Uint16 I2CA_ReadData(struct I2CMSG *msg)
{
// Wait until the STP bit is cleared from any previous master communication.
// Clearing of this bit by the module is delayed until after the SCD bit is
// set. If this bit is not checked prior to initiating a new message, the
// I2C could get confused.
if (I2caRegs.I2CMDR.bit.STP == 1)
{
return I2C_STP_NOT_READY_ERROR;
}

I2caRegs.I2CSAR = msg->SlaveAddress;

if(msg->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP)
{
// Check if bus busy
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
I2caRegs.I2CCNT = 2;
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;
I2caRegs.I2CMDR.all = 0x2620; // Send data to setup EEPROM address
}
else if(msg->MsgStatus == I2C_MSGSTAT_RESTART)
{
I2caRegs.I2CCNT = msg->NumOfBytes; // Setup how many bytes to expect
I2caRegs.I2CMDR.all = 0x2C20; // Send restart as master receiver
}

return I2C_SUCCESS;
}

我不明白为什么在写函数中要对I2CDXR寄存器赋地址值,而且是连续写入MemoryHighAddr和MemoryLowAddr,这要操作时MemoryHighAddr不就被覆盖了吗?

Xupeng(FAA) He:

回复 ruiping zhao:

我会在未来一些天尽量找个板子来试试,然后再回复你。

有谁最近在调试28035的I2C程序吗,controlsuite里面的例程中read函数如下

Uint16 I2CA_ReadData(struct I2CMSG *msg)
{
// Wait until the STP bit is cleared from any previous master communication.
// Clearing of this bit by the module is delayed until after the SCD bit is
// set. If this bit is not checked prior to initiating a new message, the
// I2C could get confused.
if (I2caRegs.I2CMDR.bit.STP == 1)
{
return I2C_STP_NOT_READY_ERROR;
}

I2caRegs.I2CSAR = msg->SlaveAddress;

if(msg->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP)
{
// Check if bus busy
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
I2caRegs.I2CCNT = 2;
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;
I2caRegs.I2CMDR.all = 0x2620; // Send data to setup EEPROM address
}
else if(msg->MsgStatus == I2C_MSGSTAT_RESTART)
{
I2caRegs.I2CCNT = msg->NumOfBytes; // Setup how many bytes to expect
I2caRegs.I2CMDR.all = 0x2C20; // Send restart as master receiver
}

return I2C_SUCCESS;
}

我不明白为什么在写函数中要对I2CDXR寄存器赋地址值,而且是连续写入MemoryHighAddr和MemoryLowAddr,这要操作时MemoryHighAddr不就被覆盖了吗?

user5078094:

回复 ruiping zhao:

因为28035的IIC中FIFIO的深度最高只有4 level

有谁最近在调试28035的I2C程序吗,controlsuite里面的例程中read函数如下

Uint16 I2CA_ReadData(struct I2CMSG *msg)
{
// Wait until the STP bit is cleared from any previous master communication.
// Clearing of this bit by the module is delayed until after the SCD bit is
// set. If this bit is not checked prior to initiating a new message, the
// I2C could get confused.
if (I2caRegs.I2CMDR.bit.STP == 1)
{
return I2C_STP_NOT_READY_ERROR;
}

I2caRegs.I2CSAR = msg->SlaveAddress;

if(msg->MsgStatus == I2C_MSGSTAT_SEND_NOSTOP)
{
// Check if bus busy
if (I2caRegs.I2CSTR.bit.BB == 1)
{
return I2C_BUS_BUSY_ERROR;
}
I2caRegs.I2CCNT = 2;
I2caRegs.I2CDXR = msg->MemoryHighAddr;
I2caRegs.I2CDXR = msg->MemoryLowAddr;
I2caRegs.I2CMDR.all = 0x2620; // Send data to setup EEPROM address
}
else if(msg->MsgStatus == I2C_MSGSTAT_RESTART)
{
I2caRegs.I2CCNT = msg->NumOfBytes; // Setup how many bytes to expect
I2caRegs.I2CMDR.all = 0x2C20; // Send restart as master receiver
}

return I2C_SUCCESS;
}

我不明白为什么在写函数中要对I2CDXR寄存器赋地址值,而且是连续写入MemoryHighAddr和MemoryLowAddr,这要操作时MemoryHighAddr不就被覆盖了吗?

user5296544:大神我刚学I2C,想知道历程中“return I2C_STP_NOT_READY_ERROR”是什么意思,它是需要在其它子程序中进行处理还是DSP自己处理?

赞(0)
未经允许不得转载:TI中文支持网 » 28035的I2C例程
分享到: 更多 (0)