Board logo

标题: 请教关于I2C的问题 [打印本页]

作者: zhaoxp    时间: 2008-6-18 10:14     标题: 请教关于I2C的问题

使用的是S08DZ60,硬件连接是不是直接把SDA,SCL分别接起来就可以了?

void configureI2C(unsigned char selfAddress){

IICF = 0x8D; /* Set IIC frequency */
IICC1_IICEN = 1; /* Enable IIC */
IICA = selfAddress; /* IIC Address */
I2C_STEP = IIC_READY_STATUS;
IICC1_IICIE = 1; /* Enable IIC interrupts */



}

void WriteBytesI2C (unsigned char slaveAddress,unsigned char numberOfBytes){



unsigned char Temp;






slaveAddress &= 0xFE; /* Format the Address to fit in the IICA register and place a 0 on the R/W bit.*/



IICC1_IICEN = 0;
IICC1_MST = 0;
IICS_SRW = 0;
IICC1_TX = 1; /* Select Transmit Mode */
IICC1_MST = 1; /* Select Master Mode (Send Start Bit) */
IICC1_IICEN = 1;



Temp = IICS; /* Clear any pending interrupt */
IICS_IICIF=1;



for(Temp=0;Temp<10;Temp++); /* Small delay */



IICD = slaveAddress; /* Send selected slave address */ 不知道为什么,IICD的值总是0,一直不变


}

void main(void) {

MCU_init();



configureI2C(0x50);
I2C_DATA[0]='A'; /* test data */



EnableInterrupts; /* enable interrupts */




WriteBytesI2C(0x52,1); //对一个I2C写入




/* Application is based on interrupts so just stay here forever. */
for(;;) {
__RESET_WATCHDOG(); /* feeds the dog */
} /* loop forever */
/* please make sure that you never leave this function */
}

[此贴子已经被作者于2008-6-18 10:25:51编辑过]


作者: strongchen    时间: 2008-6-18 14:58

需要外接上拉电阻。




欢迎光临 电子技术论坛_中国专业的电子工程师学习交流社区-中电网技术论坛 (http://bbs.eccn.com/) Powered by Discuz! 7.0.0