Atmega 1284A-AU on a custom board, Adafruits MMA8451 accelerometer breakout board
AVR studio 6.2
c/c++
Fleurys i2cmaster code
Adafruits I2c example on how to read the WhoAMI register.
I'm trying to port Adafruits example to read a register to use Fleurys C code, It seems pretty simple.
I am using his code to talk to an LED controller just fine.
In the init() function I call readRegister8()
* i2c_start_wait returns OK
* i2C_write(reg) fails, with a 0x48, no ack recieved
Am I missing something obvious??
TIA
Init
bool MMA8451_Init() { /* Check connection */ uint8_t deviceid = readRegister8(MMA8451_REG_WHOAMI); if (deviceid != 0x1A) { /* No MMA8451 detected ... return false */ //Serial.println(deviceid, HEX); return false; } }
The original Arduino code
uint8_t Adafruit_MMA8451::readRegister8(uint8_t reg) { Wire.beginTransmission(_i2caddr); i2cwrite(reg); Wire.endTransmission(false); // MMA8451 + friends uses repeated start!! Wire.requestFrom(_i2caddr, 1); if (! Wire.available()) return -1; return (i2cread()); }
My version
uint8_t MMA8451_readRegister8(uint8_t reg) { uint8_t resp = 0; if(i2c_start_wait(MMA8451_ADDR)) //0x1C or 0x1D { if(i2c_write(reg)==0) { if(i2c_rep_start(MMA8451_ADDR + )) { resp = i2c_readNak(); } } } i2c_stop(); return resp; }