Hello e2e folks-
I'm working on a simple I2C network with just two members, a Tiva C TM4C1294 launchpad and an arduino Uno. The Uno is acting as a slave and when prompted should return 4 2-byte variable values, and I think I have that working well enough.
So my problem is with the Tiva, I don't quite get how I2C works on this board, how to initialize it properly and request/receive values from slave devices.
I found this example code here-
#define ACCEL_SLAVE_ADDR 0x1D #define XOUT8 0x06 #define YOUT8 0x07 #define ZOUT8 0x08 uint8_t ReadAccel(uint8_t reg) { uint8_t accelData = I2CReceive(ACCEL_SLAVE_ADDR, reg); return accelData; } void main(void) { // Set the clocking to run directly from the external crystal/oscillator. SysCtlClockSet(SYSCTL_SYSDIV_1 | SYSCTL_USE_PLL | SYSCTL_OSC_INT | SYSCTL_XTAL_16MHZ); //initialize I2C module 0 InitI2C0(); uint8_t Ax, Ay, Az; Ax = ReadAccel(XOUT8); Ay = ReadAccel(YOUT8); Az = ReadAccel(ZOUT8); while(1){}; }
I see that it's setting XOUT8, YOUT8, and ZOUT8 to read values from I2C, and sending seemingly arbitrary numbers as the "reg" argument in the ReadAccel function. I don't understand how that correlates to requesting the data from those registers and what exactly accelData has as a value after reading in bytes. Is it the last value that the slave sent?
In case I'm making things more difficult for myself, I'm just trying to send 4 2-byte variables from the arduino slave to the tiva master, if there's an easy way to do this I'd love any suggestions you guys might have.
Thank you
Garrett