Go Down

Topic: Arduino Interface with MAX11615 over I2C (Read 83 times) previous topic - next topic

Sumeet6621

Hi All,

I have connected MAX11615 to Arduino Uno over I2C with 4.7k pull-up resistors. Hardware wise the circuit is perfectly connected.

But when it comes to the FW, I am having difficulty reading data over I2C.
MAX11615 has SETUP and Configuration byte that needs to be set up properly. I have no success doing that using Wire.write function.
Also, MAX11615 gives output in 12 bits, which is also a concern for using read function.

I am RF design engineer. I have very little exposure to FWs so please pardon me in advance for saying something which is incorrect, but this has become a bottleneck. Any help is greatly appreciated. So far applications engineering team of MAXIM is not that helpful in terms of arriving at a solution for this problem.

Link to datasheet: https://datasheets.maximintegrated.com/en/ds/MAX11612-MAX11617.pdf

Look forward to hear from some folks.

Warm Regards,
Sumeet Patil

pylon

Quote
Hardware wise the circuit is perfectly connected.
Might we ask for the wiring diagram anyway?

Quote
MAX11615 has SETUP and Configuration byte that needs to be set up properly. I have no success doing that using Wire.write function.
Also, MAX11615 gives output in 12 bits, which is also a concern for using read function.
Please post the code you already have and the output it produces.

Sumeet6621

SCL is connected to Arduino pin A5
SDA is connected to Arduino pin A4 with 4.7k pullups resistors.

I am not using a cI2C library.

Please find the code:

/*
   Master i2c (advanced)
   Redirecting slave write & read functions in setup (to custom functions following typedef)
   Read and Write operations are then called using the same functions
   Function to get Chip ID are device dependant (and will probably only work on FUJITSU devices)

   This example code is in the public domain.

   created Jan 12 2017
   latest mod Jan 31 2017
   by SMFSW
*/

#include <ci2c.h>

const uint8_t blank = 0x00;      // blank tab filling value for test

I2C_SLAVE slave;               // slave declaration

void setup() {
   uint8_t str[3];
   memset(&str, blank, sizeof(str));

   Serial.begin(115200);   // start serial for output
   I2C_init(I2C_STD);      // init with Fast Mode (400KHz)
   I2C_slave_init(&slave, 33, I2C_NO_REG);
   I2C_slave_set_rw_func(&slave, I2C_wr_advanced, I2C_WRITE);
   I2C_slave_set_rw_func(&slave, I2C_rd_advanced, I2C_READ);

}

void loop() {
   const uint16_t reg_addr = 0;
   uint8_t str[10];
   memset(&str, blank, sizeof(str));

  I2C_write(&slave, 0, &str[10000010], sizeof(str));
  I2C_write(&slave, 0, &str[00001001], sizeof(str));
   I2C_read(&slave, 0, &str[0], sizeof(str));   // slave, Addr 0, str, read chars for size of str

   Serial.println();
   for (uint8_t i = 0; i < sizeof(str); i++)
   {
      Serial.print(str, HEX); // print hex values
      Serial.print(" ");
   }

   delay(5000);
}


/*! \brief This procedure calls appropriate functions to perform a proper send transaction on I2C bus.
 *  \param [in, out] slave - pointer to the I2C slave structure
 *  \param [in] reg_addr - register address in register map
 *  \param [in] data - pointer to the first byte of a block of data to write
 *  \param [in] bytes - indicates how many bytes of data to write
 *  \return Boolean indicating success/fail of write attempt
 */
bool I2C_wr_advanced(I2C_SLAVE * slave, uint16_t reg_addr, uint8_t * data, uint16_t bytes)
{
   slave->reg_addr = reg_addr;

   if (I2C_start() == false)                           { return false; }
   if (I2C_sndAddr(slave, I2C_WRITE) == false)               { return false; }
   if (slave->cfg.reg_size)
   {
      if (slave->cfg.reg_size >= I2C_NO_REG)   // if size >2, 16bit address is used
      {
         if (I2C_wr8((uint8_t) (reg_addr >> 8)) == false)   { return false; }
      }
      if (I2C_wr8((uint8_t) reg_addr) == false)            { return false; }
   }

   for (uint16_t cnt = 0; cnt < bytes; cnt++)
   {
      if (I2C_wr8(*(data++)) == false)                  { return false; }
      slave->reg_addr++;
   }

   if (I2C_stop() == false)                           { return false; }

   return true;
}


/*! \brief This procedure calls appropriate functions to perform a proper receive transaction on I2C bus.
 *  \param [in, out] slave - pointer to the I2C slave structure
 *  \param [in] reg_addr - register address in register map
 *  \param [in, out] data - pointer to the first byte of a block of data to read
 *  \param [in] bytes - indicates how many bytes of data to read
 *  \return Boolean indicating success/fail of read attempt
 */
bool I2C_rd_advanced(I2C_SLAVE * slave, uint16_t reg_addr, uint8_t * data, uint16_t bytes)
{
   slave->reg_addr = reg_addr;

   if (bytes == 0)   { bytes = 1; }

   if (slave->cfg.reg_size)
   {
      if (I2C_start() == false)                           { return false; }
      if (I2C_sndAddr(slave, I2C_WRITE) == false)               { return false; }
      if (slave->cfg.reg_size >= I2C_NO_REG)   // if size >2, 16bit address is used
      {
         if (I2C_wr8((uint8_t) (reg_addr >> 8)) == false)      { return false; }
      }
      if (I2C_wr8((uint8_t) reg_addr) == false)               { return false; }
   }
   if (I2C_start() == false)                              { return false; }
   if (I2C_sndAddr(slave, I2C_READ) == false)                  { return false; }

   for (uint16_t cnt = 0; cnt < bytes; cnt++)
   {
      if (I2C_rd8((cnt == (bytes - 1)) ? false : true) == false)   { return false; }
      *data++ = TWDR;
      slave->reg_addr++;
   }

   if (I2C_stop() == false)                              { return false; }

   return true;
}


/*! \brief This procedure calls appropriate functions to get chip ID of FUJITSU devices.
 *  \param [in, out] slave - pointer to the I2C slave structure
 *  \param [in, out] data - pointer to the first byte of a block of data to read
 *  \return Boolean indicating success/fail of read attempt
 */
bool I2C_get_chip_id(I2C_SLAVE * slave, uint8_t * data)
{
   const uint16_t bytes = 3;
   I2C_SLAVE slave_ID;

   I2C_slave_init(&slave_ID, 0xF8 >> 1, I2C_NO_REG);   // Dummy slave init for I2C_sndAddr

   if (I2C_start() == false)                              { return false; }
   if (I2C_sndAddr(&slave_ID, I2C_WRITE) == false)               { return false; }
   if (I2C_wr8(slave->cfg.addr << 1) == false)                  { return false; }
   if (I2C_start() == false)                              { return false; }
   if (I2C_sndAddr(&slave_ID, I2C_READ) == false)               { return false; }

   for (uint16_t cnt = 0; cnt < bytes; cnt++)
   {
      if (I2C_rd8((cnt == (bytes - 1)) ? false : true) == false)   { return false; }
      *data++ = TWDR;
   }

   if (I2C_stop() == false)                              { return false; }

   return true;
}

Sumeet6621

the output is as follows:

0 0 0 0 0 0 0 0 0 0

pylon

Quote
SCL is connected to Arduino pin A5
SDA is connected to Arduino pin A4 with 4.7k pullups resistors.
That's not a wiring diagram. What about GND, Vcc, etc? Do you have the pull-up for the SDA only or for SCL too? Where do you pull them?
The chip runs at 3V3, so the internal pull-ups activated in your library may damage the chip.

If you use this library, you use the wrong features. To access the chip the Arduino must be I2C master, not slave as it is in your code. Why don't you use the Wire library?

What do you expect these lines to do? There is no comment so I have no clue. I'm sure they are wrong but I have to know what they should do to tell you how to fix them.
Code: [Select]
  I2C_write(&slave, 0, &str[10000010], sizeof(str));
  I2C_write(&slave, 0, &str[00001001], sizeof(str));


Always use code tags for code (that's the </> button in the editor)!

Go Up