This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Reading TMP102 sensor data over i2c.

I'm a beginner on embedded field.

I am having a nrf51822 development kit & Starter Kit and a mbed HRM1017(including nrf51822). I tested mbed source code for advertising TMP102 sensor data. mbed.org/.../ It worked.

But I'd like to implement on nrf51822 development kit (pca10005). but i don't know how to read sensor data over I2C. I found only ds1624 code. I want TMP102 code.

Where should I start from?

Below Code didn't worked.

#define TMP102_ADDRESS (0x90 << 1)

int main(void)
{
    nrf_gpio_port_dir_set(NRF_GPIO_PORT_SELECT_PORT1, NRF_GPIO_PORT_DIR_OUTPUT);

 if (!twi_master_init())
 {
     nrf_gpio_port_write(NRF_GPIO_PORT_SELECT_PORT1, 0x55);
     while (true) 
     {
         // Do nothing.
     }
 }

while(true)
{             
    int8_t temperature;
    int8_t temperature_fraction;
			
        uint8_t data_buffer[2];
    //if (twi_master_transfer((uint8_t)TMP102_ADDRESS, 0x00, 1, TWI_DONT_ISSUE_STOP))
    //{
	    if (twi_master_transfer(TMP102_ADDRESS | TWI_READ_BIT, data_buffer, 2, TWI_ISSUE_STOP)) 
	   {
	    temperature = (int8_t)data_buffer[0];
	    temperature_fraction   = (int8_t)data_buffer[1];
					
	    nrf_gpio_port_clear(NRF_GPIO_PORT_SELECT_PORT1, 0x7F);
	    nrf_gpio_port_set(NRF_GPIO_PORT_SELECT_PORT1, (uint8_t)temperature);

	    }
	    nrf_delay_ms(100);
      //}
}
}

In twi config file, I set 24pin, 25pin. and I connected 24pin, 25pin, Vext, GND of NRF6310 to SCL, SDA, VCC, GNF of TMP102.

Parents Reply Children
No Data
Related