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

Unable to Read or write MMA8652 registers using TWI

[https://drive.google.com/open?id=0ByjgT_Zt3YyJS2tKQko3cW10SlU]

hi i am working on MMA8652 i am working on mma7660 twi example in sdk11 for nrf52. i have changed the registers as the same way the MMA8652 need. here is my read and write functions

to read data:-

#define MMA8652_I2C_ADDR				(0x1D)

uint8_t	W_reg = MMA8652_REG_WHO_AM_I;

	err_code=nrf_drv_twi_tx(&m_twi_mma_8652, MMA8652_I2C_ADDR, &W_reg, sizeof(W_reg), false);

	APP_ERROR_CHECK(err_code);

	nrf_delay_ms(5);

	err_code = nrf_drv_twi_rx(&m_twi_mma_8652, MMA8652_I2C_ADDR, &W_reg, sizeof(W_reg));

	APP_ERROR_CHECK(err_code);

when i am going to run this the application is going to stuck.

and also i have one doubt. in sdk twi example there is one function for reading, in that example in twi handler directly reading from device address. and the result is going to structure instance with x,y,x,tilt.

here is that function

typedef struct

{

    elem_t  x;

    elem_t  y;

    elem_t  z;

    uint8_t tilt;


} sample;

err_code = nrf_drv_twi_rx(&m_twi_mma_8652, MMA8652_I2C_ADDR, (uint8_t*)&sample, sizeof(sample));

how it is possible to read directly from MMA8652_I2C_ADDR(0X1D)

if i am using same procedure i am getting x value is always 0 and y, z values are varying. is this procedure is correct to read x,y,z data from the accelerometer.

EDIT:-------

void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context) { ret_code_t err_code; static sample_t m_sample;

switch(p_event->type)
{
case NRF_DRV_TWI_EVT_DONE:
	//string_send("1twirxsuc\r\n");
	if ((p_event->type == NRF_DRV_TWI_EVT_DONE) &&
			(p_event->xfer_desc.type == NRF_DRV_TWI_XFER_TX))
	{
		if(m_set_mode_done != true)
		{
			m_set_mode_done  = true;
			return;
		}
		m_xfer_done = false;
		err_code = nrf_drv_twi_rx(&m_twi_mma_8652, 0X1D, (uint8_t*)&m_sample, sizeof(m_sample));
		if(err_code == NRF_SUCCESS){
			string_send("rx Done\r\n");
		}
		else
			string_send("rxfail\r\n");

		APP_ERROR_CHECK(err_code);
		if(err_code == NRF_SUCCESS){
			//string_send("2twi rx suc\r\n");
		}
	}
	else
	{
		//string_send("elsetwirx\r\n");
		read_data(&m_sample);
		m_xfer_done = true;

	}
	break;
default:
	break;
}

}

Parents
  • i have one doubt if i want to read data from register i need to TX register address and Then i need to read. here my MMA8652_I2C_ADDR is 0X1D but in the mma8652 documentation, it is saying that use 0X3A for tx and 0X3B for rx operation. but i am unable to get register data even if done both methods. and also i am getting NRF_SUCCESS return code. i s there any simple application to just read and write from MMA8652FC. thank you. and also did i need to put the MMA8652 in standby and Active for both tx and rx operations.

Reply
  • i have one doubt if i want to read data from register i need to TX register address and Then i need to read. here my MMA8652_I2C_ADDR is 0X1D but in the mma8652 documentation, it is saying that use 0X3A for tx and 0X3B for rx operation. but i am unable to get register data even if done both methods. and also i am getting NRF_SUCCESS return code. i s there any simple application to just read and write from MMA8652FC. thank you. and also did i need to put the MMA8652 in standby and Active for both tx and rx operations.

Children
No Data
Related