Hi,
I am using explorerKIT, xTIME 14.1.0 and i2c lib 3.1.4.
I hope to use a device (which have i2c master interface) to read a int value in my program (which have i2c slave interface).
so I almost copy the example from i2c lib 3.1.4 page.8 and page.9.
The code can compiler and run.
but I found the i2c slave code is no response when I use i2c master device to read the int value.
(i2c clock tried 10kHz to 400kHz)
I add debug_printf in every i2c_slave() select case to check the code/status activity, but no message had be printed.
I had checked the SCL/SDA signal by a scope and sure that i2c_master device have output correct SCL and SDA signal.
Would anyone please give me some direction to check this issue?
the following is my testing code: (removed some non-i2c related code that run on tilt0.)
#include <xs1.h>
#include <platform.h>
#include <stdio.h>
#include <xscope.h>
#include <i2c.h>
port i2c_sda = on tile[1]: XS1_PORT_1A; // X1D00 : SDA
port i2c_scl = on tile[1]: XS1_PORT_1B; // X1D01 : SCL //
void task3(interface PCMdataIF server C13,
interface PhaseDlyIF server C23,
server i2c_slave_callback_if i2c)
{
int PCMstring1[1024] ;
int i;
int i2c_angle=0;
while (1){
select{
case C13.fA(int Mic): //get PCM signal.
break;
case C23.fB(int final_angle): //get final_angle from other task.
i2c_angle = final_angle; //i2c_angle for i2c master to read.
break;
case i2c.start_read_request():
printf("\ni2c read request\n"); // I also add debug_printf in i2c lib : i2c_slave();
break;
case i2c.ack_read_request() -> i2c_slave_ack_t response:
response = I2C_SLAVE_ACK;
break;
case i2c.start_write_request():
break;
case i2c.ack_write_request() -> i2c_slave_ack_t response:
response = I2C_SLAVE_NACK;
break;
case i2c.start_master_write():
break;
case i2c.master_sent_data(uint8_t data) -> i2c_slave_ack_t response:
response = I2C_SLAVE_NACK;
break;
case i2c.start_master_read():
break;
case i2c.master_requires_data() -> uint8_t data:
data = i2c_angle; // store i2c_angle for i2c master reading.
break;
case i2c.stop_bit():
break;
} // select
} //while
} // task3
int main(void){
interface PCMdataIF C13;
interface PhaseDlyIF C23;
i2c_slave_callback_if i2c;
par {
on tile[1]:i2c_slave(i2c, i2c_scl, i2c_sda, 0x3b);
on tile[0]:{
par{
task3(C13,C23,i2c);
}
}
}
return (0) ;
}
i2c slave have no response on input scl/sda.
-
- Junior Member
- Posts: 5
- Joined: Tue Jan 26, 2016 8:54 am
-
- XCore Legend
- Posts: 1913
- Joined: Thu Jun 10, 2010 11:43 am
Hello Arlen. Being I2C interface, you are required to apply external pull-up resistors onto the SCL and also the SDA pins. The value is not so critical but 2.2k-10k are typical values used for the I2C bus. The resistor values will vary with the number of I2C devices and your cable length.
The reason for the resistors is that on I2C bus, the components can supply a logic LOW but not a logic HIGH. When producing a HIGH, the component is in HI-Z (open drain) so the external resistor is required to pull the floating output pin to a logic high.
https://learn.sparkfun.com/tutorials/i2 ... ware-level
The reason for the resistors is that on I2C bus, the components can supply a logic LOW but not a logic HIGH. When producing a HIGH, the component is in HI-Z (open drain) so the external resistor is required to pull the floating output pin to a logic high.
https://learn.sparkfun.com/tutorials/i2 ... ware-level
-
- Junior Member
- Posts: 5
- Joined: Tue Jan 26, 2016 8:54 am
Hi, mon2,mon2 wrote:Hello Arlen. Being I2C interface, you are required to apply external pull-up resistors onto the SCL and also the SDA pins. The value is not so critical but 2.2k-10k are typical values used for the I2C bus. The resistor values will vary with the number of I2C devices and your cable length.
The reason for the resistors is that on I2C bus, the components can supply a logic LOW but not a logic HIGH. When producing a HIGH, the component is in HI-Z (open drain) so the external resistor is required to pull the floating output pin to a logic high.
https://learn.sparkfun.com/tutorials/i2 ... ware-level
Thank you for the information.
I had add the pull up registers to SCL and SDA.
The added resisters value is 4.7k ohm, the same as the ExplorerKIT i2c pull up resisters R35 and R39 .
but the result is the same.
I add a printf at start_read_request() case, but it doesn't print anything.
case i2c.start_read_request():
printf("\ni2c read request\n");
break;
the measured signal is as following:
You do not have the required permissions to view the files attached to this post.
-
- Junior Member
- Posts: 5
- Joined: Tue Jan 26, 2016 8:54 am
I found the external i2c master test device for testing is default sending 10bits address that i2c lib didn't support. it become ok after modify the sending address setting.
-
- XCore Legend
- Posts: 1913
- Joined: Thu Jun 10, 2010 11:43 am
Excellent ! Thanks for posting your update.
As a suggestion, if you do not have one already, consider to source one of more of the following tools:
1) Total Phase Beagle for I2C / SPI bus analysis
2) Zeroplus logic analyzer for similar bus analysis for I2C, SPI, QSPI
3) Salae logic analyzer
We have each of the above and they are very useful to quickly debug such projects.
As a suggestion, if you do not have one already, consider to source one of more of the following tools:
1) Total Phase Beagle for I2C / SPI bus analysis
2) Zeroplus logic analyzer for similar bus analysis for I2C, SPI, QSPI
3) Salae logic analyzer
We have each of the above and they are very useful to quickly debug such projects.