I took my prompt from the XDK test app which uses this module to create master and slave for testing, here is the code I used:
Code: Select all
#include <xs1.h>
#include <i2c.h>
#include <xscope.h>
#include <print.h>
....
struct r_i2c i2c_slave = { XS1_PORT_1E, XS1_PORT_1F };
struct r_i2c i2c_master = { XS1_PORT_1G, XS1_PORT_1H };
struct i2c_data_info i2c_slave_data, i2c_master_data;
....
int main(void) {
....
printstrln("Starting");
i2c_master_init(i2c_master); // not actually needed
par {
i2c_rx();
i2c_tx();
}
printstrln("exit");
return 0;
}
static void i2c_tx(){
unsigned int ret_ms;
i2c_master_data.data_len = 5;
i2c_master_data.data[0] = 0x81;
i2c_master_data.data[1] = 0x40;
i2c_master_data.data[2] = 0x81;
i2c_master_data.data[3] = 0xA1;
i2c_master_data.data[4] = 0x55;
i2c_master_data.clock_mul = 1;
ret_ms = i2c_master_tx(0x10, 0x06,i2c_master_data,i2c_master);
printstr("Master return = ");
printhex(ret_ms);
printchar('\n');
}
static void i2c_rx(){
unsigned int ret_sl;
ret_sl = i2c_slave_rx(0x10,i2c_slave_data,i2c_slave);
printstr("Slave return = ");
printhex(ret_sl);
printchar('\n');
if(ret_sl) {
printstr("Data Len = ");
printint(i2c_slave_data.data_len);
printchar('\n');
printstr("Data = ");
for(int i=0; i < i2c_slave_data.data_len; i++ ) {
printchar(',');
printhex(i2c_slave_data.data[i]);
}
printchar('\n');
}
}
When I run this I get (what I presume are) ACK failures:
Code: Select all
awood@Al:~/xcorelibs/winder$ xrun --xscope-io-only bin/Winder.xe Starting
Slave return = 0
Master return = 0
exit
It may be I am missing something, I have little I2C slave experience , any ideas?
I am wondering if this module is actually up to date as I also found this I2C tutorial which has this rather ominous comment at the bottom:
I also seem to remember something about the I2C_Module being deprecated into separate Master/Slave modules.Known issues
This project was made during my spare time as a submission for the XCore github challenge
Only seems to work with 10.4.2 tools, this is to do with the sc_i2c package which also fails to run under 11.2 and higher (or at least in my attempts it did). I have submitted a bug report for this.
Thus I would like to know if the I2C_module is no longer supported or is it planned to be fixed.
Is there an alternate Slave implementation that does work
And can we get the sc_I2C library sorted out, it's as confusing as hell to me
Any help appreciated....
regards
Al