Post Go back to editing

communication between MAX32655FTHR and ADT7420 sensor

Category: Software
Product Number: MAX32655FTHR, ADT7420
Software Version: Maxim Micros SDK (Windows), 1.0.0

Hi,

I am trying to use MAX32655FTHR board to connect the ADT7420 via I2C to read the temperature.

The IDE is Maxim Micros SDK (Windows), 1.0.0 (Eclipise), however, it seems that the communication is failed.

The hardware setup goes like:

MAX32655 P0_30 - ADT7420 pin1
MAX32655 P0_31 - ADT7420 pin3
MAX32655 3V3 - ADT7420 pin5
MAX32655 GND - ADT7420 pin6

The code is 

/***** Includes *****/
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include "i2c.h"
#include "mxc_device.h"
#include "mxc_delay.h"



/***** Definitions *****/
#define I2C_MASTER MXC_I2C1 ///< I2C instance
#define I2C_FREQ 100000 ///< I2C clock frequency

#define ADT7420_ADDR 0x48 // change this according to your device
#define ADT7420_CONF_REG 0x03
#define ADT7420_TEMP_REG 0x00


// *****************************************************************************
int main(void)
{
    int error = E_NO_ERROR;
    uint8_t conf = 0x00;  // ADT7420 13-bit resolution, normal mode

    printf("\n****************** I2C SENSOR DEMO *******************\n");

    error = MXC_I2C_Init(I2C_MASTER, 1, 0); //MAX32655 master mode
    if (error != E_NO_ERROR) {
        printf("I2C master configure failed with error %i\n", error);
        return error;
    }

    MXC_I2C_SetFrequency(I2C_MASTER, I2C_FREQ);//set clock frequency

    int error_slave = E_NO_ERROR;

    //set slave address ADT7420
    error_slave = MXC_I2C_SetSlaveAddr(I2C_MASTER, ADT7420_ADDR, 0);
    if (error_slave != E_NO_ERROR) {
        printf("I2C slave configure failed with error %i\n", error_slave);
        return error_slave;
    }

    uint16_t *byte_result;
    uint8_t byte_send[3]={ADT7420_ADDR,ADT7420_CONF_REG,conf};
    
    struct _i2c_req_t i2c_struct;
    i2c_struct.i2c=I2C_MASTER;
    i2c_struct.addr=ADT7420_ADDR;
    i2c_struct.tx_buf=byte_send;
    i2c_struct.tx_len=3;
    i2c_struct.rx_buf=byte_result;
    i2c_struct.rx_len=0;
    i2c_struct.restart=0;
    i2c_struct.callback=NULL;

    int communication_result=0;
    //set up ADT7420,first write ADT7420 address then write configuration register address, finally send the mode to the register
    communication_result = MXC_I2C_MasterTransaction(&i2c_struct);
    MXC_Delay(MXC_DELAY_SEC(1));
    while (1) {
        //read temperature result,first write ADT7420 address then write register address(temp address), finally read register value
        byte_send[1]=ADT7420_TEMP_REG;
        i2c_struct.tx_len=2;
        i2c_struct.rx_len=2;
    	communication_result=MXC_I2C_MasterTransaction(&i2c_struct);
        MXC_Delay(MXC_DELAY_SEC(1));
    }

    return E_NO_ERROR;
}

when i run it, it seems the 

communication_result=MXC_I2C_MasterTransaction(&i2c_struct); goes wrong, and the return value is -9 which means a communication error.
I will appreciate it if you can tell me how to fix that.
Thanks.