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

nRF52 failed to read from max30102 through I2C

I've been trying to use nRF52 (PCA10040 board) with SDK 12 to read data from max30102 through I2C.

I used non-blocking read and this is twi init function and event hander:

void twi_init (void)
{
  ret_code_t err_code;

  const nrf_drv_twi_config_t twi_config = {
   .scl                = DEVICE_SCL_PIN,    // 25
   .sda                = DEVICE_SDA_PIN,    // 26
   .frequency          = NRF_TWI_FREQ_100K,
   .interrupt_priority = APP_IRQ_PRIORITY_HIGH
  };

  err_code = nrf_drv_twi_init(&twi_instance, &twi_config, twi_handler, NULL);
  APP_ERROR_CHECK(err_code);

  nrf_drv_twi_enable(&twi_instance);
}


void twi_handler(nrf_drv_twi_evt_t const * p_event, void * p_context)
{   
  switch(p_event->type)
  {
    case NRF_DRV_TWI_EVT_DONE:
    m_xfer_done = true;
        break;
    case NRF_DRV_TWI_EVT_ADDRESS_NACK:            
        break;
    case NRF_DRV_TWI_EVT_DATA_NACK:
        break;
    default:
        break;   
  }
}

However, when I used the following code to read from one of its registers, I couldn't get expected value.

reg_addr = 0xFF;   // register 0xFF stores fixed part ID 0x15
device_address = 0x57; 
uint8_t part_id[2];
m_xfer_done = false;
err_code = nrf_drv_twi_tx(&twi_instance, device_address, &reg_addr, 1, true);

if(NRF_SUCCESS == err_code) {	// always SUCCESS
	m_xfer_done = false;
	err_code = nrf_drv_twi_rx(&twi_instance, device_address, part_id, 1);
	// ALWAYS error with value 0x11
	printf("\t\t ** (0x%2X 0x%2X) 0x%2X\r\n", part_id[0], part_id[1], err_code);
} else {
	printf("\t\t\tnrf_drv_twi_rx error 0x%X\r\n", err_code);
}

The device address by data sheet is 0xAF; somehow I was suggested ([link text])(devzone.nordicsemi.com/.../) to use 0x57. But I cannot get value 0x15.

I have successfully tested the sensor with Arduino UNO. What did I miss on nRF52?

Parents Reply Children
No Data
Related