Hello to everyone,<br><br>I am new user of the Armadillo 500 embedded platform and I am very happy with this extremely powerful development board.<br>I am writing a small piece of code using the I2C interface and a problem occurs when I am trying to write and read with the ioctl_rdrw. My code is bellow.<br>
<br>int main(int argc, char **argv)<br>{<br> struct i2c_rdwr_ioctl_data rdwr_msg;<br> unsigned int i2fd;<br> unsigned short addr;<br> int ret;<br> <br> char output[] = {0x2, 0x1, 0x1};<br> char input[10] = {0};<br>
addr = 0x18;<br><br> fd = open("/dev/i2c-0", O_RDWR);<br> <br> if (!i2cfd) {<br> printf("Error on opening the device file\n");<br> return 0;<br> }<br> <br> rdwr_msg.nmsgs = 2;<br> <br> rdwr_msg.msgs = (struct i2c_msg*)malloc(rdwr_msg.nmsgs*sizeof(struct i2c_msg));<br>
if (!rdwr_msg.msgs) {<br> printf("Memory alloc error\n");<br> close(fd);<br> return 0;<br> }<br> <br> <br> (rdwr_msg.msgs[1]).len = 4;<br> (rdwr_msg.msgs[1]).addr = start_address;<br> (rdwr_msg.msgs[1]).flags = I2C_M_RD;<br>
(rdwr_msg.msgs[1]).buf = &input[0];<br> <br> rdwr_msg.msgs[0].len = 3;<br> (rdwr_msg.msgs[0]).addr = start_address;<br> (rdwr_msg.msgs[0]).flags = 0; <br> (rdwr_msg.msgs[0]).buf = &output[0];<br>
<br> ioctl(fd,I2C_TIMEOUT,3); /* set the timeout */<br> ioctl(fd,I2C_RETRIES,1); /* set the retries */<br> <br> ret = ioctl(fd,I2C_RDWR, &rdwr_msg);<br> <br> if ( ret < 0 ) {<br> printf("Error during I2C_RDWR ioctl with error code: %d\n",ret);<br>
}<br> <br> close(fd);<br><br> return;<br>}<br clear="all"><br>As you can see the code is quite simple. I can write but when a read transaction is called, a failure is caused.<br><br>I also used the SMSbus transactions since the i2c-dev driver supports these features.<br>
But the problem remains. I put some printk in the driver code (mxc_i2c.c) and an arbitration lost occurs.<br>To be more specific, I want to communicate with a device (in address 0x18) which receives a command like 0x2 0x1 0x1 and sends a response<br>
like 0x3 0x1 0x0 0x1. The problem is in master reception when the SDA remains high and the SCL is LOW. Form the I2C spec, the arbitration is lost.<br><br>Could you please help this situation? <br><br>Thank you for your time.<br>
<br>Take care<br><br>Dimitris <br>-- <br>Dpl Ing. Dimitris Tsiougkos<br><br>