Hi,
I wish to exchange the sensor form mma7660 to hmc5883l, so I simply replace it with my own function just like mma7660 did. Those function are
define HMC5883L_ADDR (0x1E)
define HMC5883L_REG_CONF_A (0x00) define HMC5883L_REG_CONF_B (0x01) define HMC5883L_REG_MODE (0x02) define HMC5883L_REG_X_MSB (0x03) define HMC5883L_REG_X_LSB (0x04) ...
static const nrf_drv_twi_t m_twi_hmc_5883l = NRF_DRV_TWI_INSTANCE(0);
void twi_hmc_5883l_init (void) { ret_code_t err_code;
const nrf_drv_twi_config_t twi_hmc_5883l_config = {
.scl = ARDUINO_SCL_PIN,
.sda = ARDUINO_SDA_PIN,
.frequency = NRF_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH
};
err_code = nrf_drv_twi_init(&m_twi_hmc_5883l, &twi_hmc_5883l_config, twi_hmc_5883l_handler, NULL);
APP_ERROR_CHECK(err_code);
nrf_drv_twi_enable(&m_twi_hmc_5883l);
}
void HMC5883L_set_mode(void) { ret_code_t err_code;
uint8_t reg[3] = {0x3C, HMC5883L_REG_CONF_A, 0x70};
uint8_t reg1[3] = {0x3C, HMC5883L_REG_CONF_B, 0xA0};
uint8_t reg2[3] = {0x3C, HMC5883L_REG_MODE, 0x00};
err_code = nrf_drv_twi_tx(&m_twi_hmc_5883l, HMC5883L_ADDR, reg, sizeof(reg), false);
APP_ERROR_CHECK(err_code);
nrf_delay_ms(100);
err_code = nrf_drv_twi_tx(&m_twi_hmc_5883l, HMC5883L_ADDR, reg1, sizeof(reg), false);
APP_ERROR_CHECK(err_code);
nrf_delay_ms(100);
err_code = nrf_drv_twi_tx(&m_twi_hmc_5883l, HMC5883L_ADDR, reg2, sizeof(reg), false);
APP_ERROR_CHECK(err_code);
while(m_set_mode_done == false);
}
and I can get callback NRF_DRV_TWI_EVT_DONE,
-
Why the mma7660 address use (0x98U >> 1) in define, I will not get NRF_DRV_TWI_EVT_DONE if I define hmc5883l as (0x1EU >> 1)?
-
the other question is: After I get callback and I wish to print my data,but it's all zero!!!
That confuse me....
I need help thx a lot.