S5PV210_UM_REV1.1.pdf
sec
tion 08_connectivity_storage
2 IIC-BUS INTERFACE
相关引脚
相关配置流程
S5PV210_UM_REV1.1.pdf
section 08_connectivity_storage
2 IIC-BUS INTERFACE
2.3.8 FLOWCHARTS OF OPERATIONS IN EACH MODE
有详细的流程图,如下所示
相关寄存器
2) OK210 硬件相关
3)代码如下
void i2cint()
{
GPD1_CON =0x22;
GPD1_PUD =0x06;
I2CCON0 |=0xEF;
I2CSTAT0 =0x10;
}
void i2c_write(int slave_addr, int addr, int data)
{
I2CDS0 = slave_addr;
// 主机发送AT24LC01地址
I2CSTAT0 = 0xf0;
while ((I2CCON0 & 0x10) == 0); // 等待数据发逿
while ((I2CSTAT0 & 0x1)); // 等待从机发来ACK
// 发地址和数捿
I2CDS0 = addr;
I2CCON0 &= ~(1<<4);
while ((I2CCON0 & 0x10) == 0);
while ((I2CSTAT0 & 0x1));
I2CDS0 = (data & 0x00FF);
I2CCON0 &= ~(1<<4);
while ((I2CCON0 & 0x10) == 0);
while ((I2CSTAT0 & 0x1));
I2CSTAT0 = 0xD0; // 主机发stop使能tx/rx
I2CCON0 &= ~(1<<4);
return;
}
int i2c_read(int slave_addr, int addr)
{
int data;
I2CDS0 = slave_addr;
// 主机发送AT24LC01地址
I2CSTAT0 = 0xf0;
while ((I2CCON0 & 0x10) == 0); // 等待数据发逿
while ((I2CSTAT0 & 0x1)); // 等待从机发来ACK
// 发地址和读数据
I2CDS0 = addr;
I2CCON0 &= ~(1<<4);
while ((I2CCON0 & 0x10) == 0);
while ((I2CSTAT0 & 0x1));
data=I2CDS0 ;//读数捿
I2CSTAT0 = 0xd0; // 主机发stop使能tx/rx
I2CCON0 &= ~(1<<4);
return data;
}
void main(void)
{
int i;
GPD0CON &= ~(0xF << 0);
MP0_4CON = (MP0_4CON & ~0xFFFF0000) | 0x11110000;
MP0_4PUD=(0x55<<16)&MP0_4PUD;
MP0_4DAT |= 0xF0;
clock_init();
uart_init();
i2cint();
for(i=0;i<8;i++)
{
i2c_write(0xa0,i, 0);
Delay(10);
}
for(i=0;i<8;i++)
{
UTXH3= i2c_read(0xa1, i);
Delay(10);
}
return;
}