Hi, I'm using nRF52 DK (nRF52832), demo code <TWI sensor>. I'm using this slave sensor to communicate with Master nRF52 DK. My code gets stuck at sensor_set_mode() function. On PuTTY, it shows that the while loop never exits. The error is NRF_ERROR_INVALID_ADDR. Any help, pls?
/* Creating a TWI master driver instance. */
#define TWI_INSTANCE_ID 0
static const nrf_drv_twi_t m_twi = NRF_DRV_TWI_INSTANCE(TWI_INSTANCE_ID);
// address = 0x21 or 0x22 or 0x23 depends on the resistor valur at ADDR port
#define SENSOR_ADDR (0x22U >> 1)
// In order to set sensor as continuous mode, use register 0x3608
#define continuous_mode_command1 0x36U
#define continuous_mode_command2 0x08U
/* Indicates if operation on TWI has ended. */
static volatile bool m_xfer_done = false;
void sensor_set_mode(void)
{
ret_code_t err_code;
NRF_LOG_INFO("sensor_set_mode started\r\n");
// Writing CONTINUOUS_MODE = 0x3608U into SDP3x configuration register. Set SDP3x sensor in continuous mode.
uint8_t reg0 = continuous_mode_command1;
uint8_t reg1 = continuous_mode_command2;
uint16_t reg = ((reg0 << 8) | reg1);
NRF_LOG_INFO("reg16bit: %x\r\n",reg);
/* Function for sending data to a TWI slave.
* @param[in] p_instance Pointer to the driver instance structure.
* @param[in] address Address of a specific slave device (only 7 LSB).
* @param[in] p_data Pointer to a transmit buffer.
* @param[in] length Number of bytes to send.
* @param[in] no_stop If set, the stop condition is not generated on the bus
* after the transfer has completed successfully (allowing
* for a repeated start in the next transfer).
This function will return NRF_SUCCESS if the procedure was successful.
*/
err_code = nrf_drv_twi_tx(&m_twi, SENSOR_ADDR, reg, sizeof(reg), false);
NRF_LOG_INFO("error code6 = %s\r\n",nrf_strerror_find(err_code));
NRF_LOG_INFO(" set i2c address\r\n");
APP_ERROR_CHECK(err_code);
while (m_xfer_done == false);
NRF_LOG_INFO("done\r\n");
}