我用5509的I2C读写时钟芯片ISL12026。
程序如下:
#define WriteAddress 0xDE
#define ReadAddress 0xDF
以上是设备读写地址
/* This next struct shows how to use the I2C API */
/* Create and initialize an I2C initialization structure */
I2C_Setup I2Cinit = {
0, /* 7 bit address mode */
0, /* own address - don't care if master */
12, /* clkout value (Mhz) */
50, /* a number between 10 and 400*/
0, /* number of bits/byte to be received or transmitted (8)*/
0, /* DLB mode on*/
1 /* FREE mode of operation on*/
};
/*I2C is undet reset*/
I2C_RSET(I2CMDR,0);
/*设置预分频寄存器,I2C的mode clock is 10MHz*/
delay(100);
I2C_RSET(I2CSAR,0x001A);
I2C_RSET(I2CMDR,0x0620);
I2C_FSET(I2CSTR,BB,0x1); /* Writing a 1 to BB Bus busy bit is supposed to clear it*/
I2C_setup(&I2Cinit);
//myI2C_setup(&I2Cinit);
/*设置I2C的Mater clock*/
I2C_RSET(I2CCLKL,100);
I2C_RSET(I2CCLKH,100);
I2C_getConfig(&testI2C);
以上是初始化。
buffer1[0]=0x00; //高位地址
buffer1[1]=0x3f; //地位地址
buffer1[2]=0x02; //数据
i2c_status = I2C_write( buffer1, //pointer to data array
3, //length of data to be transmitted
1, //master or slaver
WriteAddress, //slave address to transmit to
1, //transfer mode of operation
30000 //time out for bus busy
);
以上是写数据。用观察窗口看 i2c_status的值是3.
手册上说是没收到应答位。
请高手指教,哪儿有问题?谢谢!
|