xCORE-200USB Audio 2.0 I2c problem
Posted: 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. After delay a long time it respond. 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. ----------------------------------------------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;
}
}
}
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. After delay a long time it respond. 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. ----------------------------------------------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;
}
}
}