Microchip® Advanced Software Framework

Quick start guide for the AT30TS

This is the quick start guide for the AT30TS Temperature Sensor Library, with step-by-step instructions on how to configure and use the driver.

Basic use case

In the basic use case, the below setup is used:

  1. The type of the AT30TS component - AT30TSE758
  2. The development board used is Temperature Sensor Xplained
  3. Defined two corresponding symbols in the project properties ATAVRTEMPSENSORX, AT30TSE758
  4. The AT30TSE758 is connected to the TWIC of an Xmega256A3BU
  5. Temperature Sensor Xplained kit is plugged onto the Xmega-A3BU Xplained Development Kit
  6. TWI is configured as master
  7. 10 bytes of data is written to the device. This is read back and verified
  8. Temperature is read at defined intervals and displayed

Setup steps

Prerequisites

  1. AT30TSxx temperature sensor is interfaced via TWI
  2. So, we need to add TWI Master driver and define the
  • TWI module to be used.

Example code

The device addresses given below are defined for ATAVRTEMPSENSORX development board

* #define TWI_MODULE &TWIC
* #define TWI_SPEED 50000
* #define EXAMPLE_TS_DEVICE AT30TSE758
* #define EXAMPLE_TS_DEVICE_ADDR AT30TSE758_ADDR_LOCAL
* #define AT30TSE758_ADDR_LOCAL 0x48
*

The application will be somewhat similar to the below

* uint8_t ibuf[16] = {0};
* static uint8_t test_pattern[PATTERN_TEST_LENGTH];
* sensor_data_t sensor_data;
* static uint8_t ret = 0;
* uint8_t i = 0;
*
* irq_initialize_vectors();
* attach_device(EXAMPLE_TS_DEVICE_ADDR, EXAMPLE_TS_DEVICE);
* opt.chip = EXAMPLE_TS_DEVICE_ADDR;
* opt.speed = TWI_SPEED;
* twi_master_setup(TWI_MODULE, &opt);
*
* sensor_data.config_reg.value = 0;
* sensor_data.config_reg.option.RES = RES12;
* if (write_config(sensor_data.config_reg.value) != TWI_SUCCESS) {
* test_fail_indication();
* }
* char senseData[50] = {0};
* read_temperature(&sensor_data);
* sprintf(senseData, "%d.%04d DegC",
* sensor_data.temperature.itemp,
* sensor_data.temperature.ftemp);
*
* // Perform a write access & check write result
* if ((ret = ts_write_memory(EE_TEST_ADDR, PATTERN_TEST_LENGTH,
* (void *)test_pattern)) != TWI_SUCCESS) {
* test_fail_indication();
* }
*
* // Allow time for EEPROM to settle
* delay_ms(5);
* // Clear test_pattern
* memset(ibuf, 0, sizeof(ibuf));
*
* // Perform a read access & check read result
* if (ts_read_eeprom(EE_TEST_ADDR, PATTERN_TEST_LENGTH,
* ibuf) != TWI_SUCCESS) {
* test_fail_indication();
* }
* // Check received data against sent data
* for (i = 0; i < PATTERN_TEST_LENGTH; i++) {
* if (ibuf[i] != test_pattern[i]) {
* test_fail_indication();
* }
* }
*
*

Workflow

The TWI module to be used in the application can be defined in 'conf_twim.h'

#define TWI_MODULE &TWIC
  1. Make sure that the required preprocessor symbols for the selected sensor device and the development board (if any) are defined in the project options eg: ATAVRTEMPSENSORX , AT30TSE758
  2. Enable the system clock and initialize TWI as Master
    * attach_device(EXAMPLE_TS_DEVICE_ADDR, EXAMPLE_TS_DEVICE);
    * opt.chip = EXAMPLE_TS_DEVICE_ADDR;
    * opt.speed = TWI_SPEED;
    * twi_master_setup(TWI_MODULE, &opt);
    *
    *

Usage steps

Example code

Add to, e.g., main loop in application C-file:

* read_temperature(&sensor_data);
* sprintf(senseData, "%d.%04d DegC",
* sensor_data.temperature.itemp,
* sensor_data.temperature.ftemp);
* status = ts_write_eeprom(address, write_size, buf);
* status = ts_read_eeprom(EE_TEST_ADDR, PATTERN_TEST_LENGTH, ibuf);
*