This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

nRF52832 twi_master_transfer

Hey guys, I have a little problem on a new board comunicating with a MPU9250 sensor.

  • Chip version is nrf52832-QFAA-BA
  • GPIO PINS Used P0.20 (SDA) and P0.21 (SCL)
  • I can read the sensor WHO_AM_I register correctly (it returns 0x71).
  • I can't write on register, function twi_master_transfer returns always false.

Here my TWI macro functions to read and to write:

bool readI2cData(unsigned char address, unsigned char reg, unsigned char len, unsigned char * data)
{		

    // Write: register address we want to start reading from
if (twi_master_transfer(address<<1, &reg, 1, TWI_DONT_ISSUE_STOP))
{
	  // Read: the number of bytes requested.
	if (twi_master_transfer(address<<1 | TWI_READ_BIT, data, len, TWI_ISSUE_STOP))
	{			
	  // Read succeeded.
		return true;
	}
}

// read or write failed.
return false;
}
uint8_t readI2cReg(uint8_t address, uint8_t reg){
unsigned char data;

if (readI2cData(address, reg,1, &data)) 
{
	return data;
}
return 0; 
}




bool writeI2cReg(unsigned char address, unsigned char reg, unsigned char len, const unsigned char   value)

{
uint8_t data[2];
data[0] = reg;
data[1] = value;

// Write: register protocol
if (twi_master_transfer(address << 1 , data, len,1))
{
	return true;    
}

// read or write failed.
return false;
 }

And here is what I try to write:

unsigned char data[6];

/* Reset device. */
data[0] = BIT_RESET; //equal to 0x80
if (i2c_write(st.hw->addr, st.reg->pwr_mgmt_1, 1, data))
    return -1;
delay_ms(100);

/* Wake up chip. */
data[0] = 0x00;
if (i2c_write(st.hw->addr, st.reg->pwr_mgmt_1, 1, data))
    return -1;

Where am I wrong? Probably missing something?

Thanks.

Parents Reply Children
No Data
Related