xCORE-200USB Audio 2.0 I2c problem

Technical discussions around xCORE processors (e.g. General Purpose (L/G), xCORE-USB, xCORE-Analog, xCORE-XA).
sunny123456
New User
Posts: 2
Joined: Thu Oct 19, 2017 2:48 am

xCORE-200USB Audio 2.0 I2c problem

Postby sunny123456 » Wed Dec 06, 2017 3:47 am

Hi all
I come across with I2C problems.I use the sw_usb_audio-[sw]_6.15.2rc1 for development.In the software package, it contains module_i2c_single_port
Create a new task to handle several tasks to access to I2C bus. But when I try to read/write to a chip(sorry i can't mention it, because of NDA), it behave strange.
At first,it has no respond at all, when I change the default I2C SCK 100kHz to 50KHZ. It works.
Then, some operation still fail.
scope_7.png
(34.38 KiB) Not downloaded yet
scope_7.png
(34.38 KiB) Not downloaded yet

After delay a long time it respond.
scope_8.png
(37.48 KiB) Not downloaded yet
scope_8.png
(37.48 KiB) Not downloaded yet

is it the chip's problem?
FYI i use some fly wires to connect.

the last operation suppose to be read, on my scope it turns to write.
scope_11.png
(50.47 KiB) Not downloaded yet
scope_11.png
(50.47 KiB) Not downloaded yet

----------------------------------------------i2c_accesss.h------------------------------------

#ifndef I2C_ACCESS
#define I2C_ACCESS


interface i2c_com_interface{
void write_reg(int device,int reg_addr,unsigned char data[], int nbytes);
void read_reg(int device,int reg_addr,unsigned char data[], int nbytes);
void read(int device,unsigned char data[],int nbytes);
void write_reg_wait_ack(int device,int reg_addr,unsigned char data[], int nbytes);
};


void app_i2c_com(interface i2c_com_interface server interI2C);
void wait_us(int microseconds);

#endif
----------------------------------------------i2c_accesss.xe------------------------------------
#include "i2c_accesss.h"
#include <string.h>
#include "i2c_shared.h"
#include <xs1.h>
#include <assert.h>
#include "devicedefines.h"
#include <platform.h>

//timer t;

void wait_us(int microseconds)
{
timer t;
unsigned time;

t :> time;
t when timerafter(time + (microseconds * 100)) :> void;
}

on tile [0] : struct r_i2c r_i2c = {XS1_PORT_4A};


void app_i2c_com(interface i2c_com_interface server interI2C)
{
i2c_shared_master_init(r_i2c);
char temp[256];
while(1)
{
select
{
case interI2C.write_reg(int device,int reg_addr,unsigned char data[], int nbytes):
if(nbytes<256)
{
memcpy(temp,data,nbytes);
i2c_shared_master_write_reg(r_i2c,device,reg_addr,temp,1);
}


break;
case interI2C.read_reg(int device,int reg_addr,unsigned char data[], int nbytes):
if(nbytes<256)
{

i2c_shared_master_read_reg(r_i2c,device,reg_addr,temp,1);
memcpy(data,temp,nbytes);
}

break;
case interI2C.read(int device,unsigned char data[],int nbytes):
if(nbytes<256)
{
i2c_shared_master_rx(r_i2c,device,temp,nbytes);
memcpy(data,temp,nbytes);
}
break;
case interI2C.write_reg_wait_ack(int device,int reg_addr,unsigned char data[], int nbytes):
if(nbytes<256)
{
memcpy(temp,data,nbytes);
i2c_shared_master_write_reg_wait_ack(r_i2c,device,reg_addr,temp,1);
// i2c_master_write_reg_wait_ack(device,reg_addr,temp,1,r_i2c);
}


break;
}
}

}
User avatar
mon2
XCore Expert
Posts: 781
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Postby mon2 » Wed Dec 06, 2017 1:56 pm

Hi sunny123456.

1) Check with the mfr of the I2C slave device on the max I2C bus speed.

2) It is possible that the I2C slave is supporting of I2C clock stretching:

https://stackoverflow.com/questions/248 ... stretching

This is where the I2C slave will pull down the I2C clock line to effectively slow down the I2C master's traffic as the I2C slave requires additional time to digest or process the request(s). This is common on some I2C slaves we have seen in the past.

3) Not sure but do check if the XMOS I2C IP supports I2C clock stretching feature.

4) You could swap out this specific I2C slave device and replace with another that does not have this feature to test the speed @ 100 khz. For example, read an I2C eeprom in a loop @ 100 khz. Check if the I2C clock is pulled down or not. This should validate if the length of the fly wires are an issue or not.
peter
XCore Addict
Posts: 224
Joined: Wed Mar 10, 2010 12:46 pm

Postby peter » Wed Dec 06, 2017 2:06 pm

Thanks for sharing that. We are aware of a number of timing issues with this code. Would you be able to test with the new version we are in the process of developing? Version 5.0.0 which is currently on my fork: https://github.com/pthedinger/lib_i2c

Return to “Processors”

Who is online

Users browsing this forum: No registered users and 13 guests