首页 | 新闻 | 新品 | 文库 | 方案 | 视频 | 下载 | 商城 | 开发板 | 数据中心 | 座谈新版 | 培训 | 工具 | 博客 | 论坛 | 百科 | GEC | 活动 | 主题月 | 电子展
返回列表 回复 发帖

S08难以理解的IIC程序

S08难以理解的IIC程序

byte IIC_read_byte(word addr)
{
Address = addr;
temp = (Addr_H & 0x07) << 1;
IIC1C_TXAK = 0; // RX/TX = 1; MS/SL = 1; TXAK = 0;
IIC1C |= 0x30; // And generate START condition;
IIC1D = IIC_SLAVE | temp; // Address the slave and set up for master transmit;
while (!IIC1S_IICIF); // wait until IBIF;
IIC1S_IICIF=1; // clear the interrupt event flag;
while(IIC1S_RXAK); // check for RXAK;
//-----Slave ACK occurred------------
IIC1D = Addr_L; // Send low byte of word address;
while (!IIC1S_IICIF); // wait until IBIF;
IIC1S_IICIF=1; // clear the interrupt event flag;
while(IIC1S_RXAK); // check for RXAK;
//-----Slave ACK occurred------------
IIC1C_RSTA = 1; // set up repeated start;
IIC1D = IIC_SLAVE | temp | 1; // (slave_address) | (RW = 1);
while (!IIC1S_IICIF); // wait until IBIF;
IIC Software Routines for MCUs
How to Use IIC Module on M68HC08, HCS08, and HCS12 MCUs, Rev. 2
Freescale Semiconductor 11
IIC1S_IICIF=1; // clear the interrupt event flag;
while (IIC1S_RXAK); // check for RXAK;
//-----Slave ACK occurred------------
IIC1C_TX = 0; // set up to receive;
IIC1C_TXAK = 1; // acknowledge disable;
RD_data = IIC1D; // dummy read;
while (!IIC1S_IICIF); // wait until IBIF;
IIC1S_IICIF=1; // clear the interrupt event flag;
IIC1C_MST = 0; // generate stop signal;
RD_data = IIC1D; // read right data;

return RD_data;
}
上面程序是官方示例程序,发现红色两行代码顺序颠倒后就无法读IIC器件了。
为什么读寄存器是在停止信号之后?按理说发生了中断表明传输完成了,读寄存器应该在停止信号前才对啊。
请高手不吝赐教 !
返回列表