I am trying to build an I2C device using a teensy 3.1 as the slave device. As I am figuring this out, the master is just the I2C-tools on a linux machine.
I have a simple skeleton copied from the sample, so I can try to figure out how to create the I2C device. It looks like this:
I can detect the device at the correct address using
i2cdetect -y -r 2
when I attempt to dump the register with
i2xdump -y 2 0x29 I get all of the same values
0x00 lots of them. I think I should get the 16 byte array;
I know from the print statement that the teensy is sending them.
I should probably mention I have the same setup, that I used to be sure that I could talk to the device, as I used for an adafruit I2C amplifier.
Am I doing something wrong?
I have a simple skeleton copied from the sample, so I can try to figure out how to create the I2C device. It looks like this:
Code:
#include <Wire.h>
#define REG_MAP_SIZE 16
#define DEVICE_ADDRESS 0x29
byte registerMap[REG_MAP_SIZE];
void setup()
{
Wire.begin(DEVICE_ADDRESS); // join i2c bus with address #4
Wire.onRequest(requestEvent); // register event
Wire.onReceive(receiveEvent); // register event
//Serial.begin(9600); // start serial for output
//while (!Serial){
//}
//Serial.println("Foo: ");
}
void loop()
{
delay(100);
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void requestEvent(){
Serial.println("Request: ");
for (int c = 0; c < (REG_MAP_SIZE-1); c++) {
Serial.print("C: ");Serial.println(c);
registerMap[c] = (byte)c; //registerMapTemp[c];
}
Wire.send(registerMap, REG_MAP_SIZE);
Serial.println("Sent: ");
}
// function that executes whenever data is received from master
// this function is registered as an event, see setup()
void receiveEvent(int howMany)
{
while(1 < Wire.available()) // loop through all but the last
{
char c = Wire.read(); // receive byte as a character
//Serial.print(c); // print the character
}
int x = Wire.read(); // receive byte as an integer
//Serial.println(x); // print the integer
}
i2cdetect -y -r 2
when I attempt to dump the register with
i2xdump -y 2 0x29 I get all of the same values
0x00 lots of them. I think I should get the 16 byte array;
I know from the print statement that the teensy is sending them.
I should probably mention I have the same setup, that I used to be sure that I could talk to the device, as I used for an adafruit I2C amplifier.
Am I doing something wrong?
Last edited: