Chat freely about anything...

User avatar
By parmar7725274
#27022 Hi All,

In our current product prototype we want to interface 6 Digit 7 segment display. The display is based on TM1637 display driver. TM1637 display driver use I2C for communication and I'm using GPIO 0 ( SCL ) and 2 ( SDA ) of ESP for communication.

Problem I'm facing is after sending START bytes to TM1637 Display driver I'm not able to get acknowledgement signal on GPIO2. Display is working fine with other development board with same logic. I also attach Code and TM1637 display driver's datasheet for a reference.

Any one have Idea where I'm wrong ? Is there any problem with GPIO initialization ?
Please help me !

Thanks & regards,
Prakash

Code: Select all
#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "tm1637.h"
#include "tm1637font.h"

/*  i2c Methods for handling data transfer to and from the tm1637. */

void ICACHE_FLASH_ATTR delay_us( uint8_t i )
{
   for( ; i>0; i-- );
}
/******************************************************************************
 * FunctionName :
 * Description  :
 * Parameters   : NONE
 * Returns      : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR i2c_start(void)
{
   os_printf("i2c_start - IN \n");

   I2C_MASTER_SCL_HIGH( );

   I2C_MASTER_SDA_HIGH( );

   delay_us(2);

        I2C_MASTER_SDA_LOW( );

        os_printf("i2c_start - OUT \n");
}

/******************************************************************************
 * FunctionName :
 * Description  :
 * Parameters   : NONE
 * Returns      : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR i2c_ack (void)
{
   uint8 ret = 0;

   os_printf("i2c_ack - IN \n");

   I2C_MASTER_SCL_LOW( );

   delay_us (5);

   PIN_PULLUP_EN( I2C_MASTER_SDA_MUX );               // enable pin PULL-UP
   GPIO_DIS_OUTPUT( GPIO_ID_PIN( I2C_MASTER_SDA_GPIO ));    // set I2C_MASTER_SDA_GPIO as input

       while( 1 )
      {
          ret = GPIO_INPUT_GET( GPIO_ID_PIN( I2C_MASTER_SDA_GPIO ) );
          os_printf("- %d ", ret);
          if(ret)
             break;
    }

    I2C_MASTER_SCL_HIGH();

    delay_us( 2 );

    I2C_MASTER_SCL_LOW();

    os_printf("i2c_ack - OUT \n");
}

/******************************************************************************
 * FunctionName :
 * Description  :
 * Parameters   : NONE
 * Returns      : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR i2c_stop (void)
{
    os_printf("i2c_stop - IN \n");

   I2C_MASTER_SCL_LOW();

   delay_us (2);

   I2C_MASTER_SDA_LOW();
   delay_us (2);

        I2C_MASTER_SCL_HIGH();
        delay_us (2);

        I2C_MASTER_SDA_HIGH();

        os_printf("i2c_stop - OUT \n");
}

/******************************************************************************
 * FunctionName :
 * Description  :
 * Parameters   : NONE
 * Returns      : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR i2c_write ( uint8_t oneByte )
{
    uint8_t i;

    os_printf("i2c_write - IN\n");

    for (i=0; i<8; i++)
    {
       
       I2C_MASTER_SCL_LOW();

       ( oneByte & 0x01 ) ? I2C_MASTER_SDA_HIGH() : I2C_MASTER_SDA_LOW();

       delay_us (3);

        oneByte = oneByte >> 1;

        I2C_MASTER_SCL_HIGH();
        delay_us (3);
    }

    os_printf("i2c_write - OUT \n");
}

/******************************************************************************
 * FunctionName : i2c_master_gpio_init
 * Description  :
 * Parameters   : NONE
 * Returns      : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR
i2c_master_gpio_init(void)
{
   os_printf("\ni2c_master_gpio_init - IN\n");

       ETS_GPIO_INTR_DISABLE() ;

       PIN_FUNC_SELECT(   I2C_MASTER_SDA_MUX,
                      I2C_MASTER_SDA_FUNC
                   );

       PIN_FUNC_SELECT(   I2C_MASTER_SCL_MUX,
                      I2C_MASTER_SCL_FUNC
                   );

        ETS_GPIO_INTR_ENABLE() ;

       GPIO_OUTPUT_SET(GPIO_ID_PIN( I2C_MASTER_SDA_GPIO ), 0);   // set I2C_MASTER_SDA_GPIO as Low-level output

       PIN_PULLUP_EN( I2C_MASTER_SDA_MUX );               // enable pin PULL-UP
       GPIO_DIS_OUTPUT( GPIO_ID_PIN( I2C_MASTER_SDA_GPIO ));    // set I2C_MASTER_SDA_GPIO as input

       GPIO_OUTPUT_SET( GPIO_ID_PIN( I2C_MASTER_SCL_GPIO ), 0);    // set I2C_MASTER_SDA_GPIO as Low-level output

       os_printf("i2c_master_gpio_init - OUT\n");

}

/******************************************************************************
 * FunctionName :
 * Description  :
 * Parameters   : NONE
 * Returns      : NONE
*******************************************************************************/
void ICACHE_FLASH_ATTR display( void )
{
   int i;

   i2c_start();
   i2c_write( 0x40 );
   i2c_ack();
   i2c_stop();

   i2c_start();
   i2c_write( 0xC0 );   // Set the starting address
   i2c_ack();
   for( i = 1; i <= TM1637_DIGITS; i++ )
   {
      i2c_write( 0xff );
      i2c_ack( );
   }
   i2c_stop();

   i2c_start();
   i2c_write( 0x8F );
   i2c_ack();
   i2c_stop();

}



here is a macro definitions :

Code: Select all#ifndef __tm1637_H__
#define __tm1637_H__

void i2c_master_gpio_init( void );
void display( void );

#define I2C_MASTER_SDA_MUX PERIPHS_IO_MUX_GPIO2_U
#define I2C_MASTER_SCL_MUX PERIPHS_IO_MUX_GPIO0_U

#define I2C_MASTER_SDA_GPIO 2
#define I2C_MASTER_SCL_GPIO 0

#define I2C_MASTER_SDA_FUNC FUNC_GPIO2
#define I2C_MASTER_SCL_FUNC FUNC_GPIO0

#define I2C_MASTER_SCL_LOW( )    \
   GPIO_OUTPUT_SET(GPIO_ID_PIN( I2C_MASTER_SCL_GPIO ), 0 )

#define I2C_MASTER_SCL_HIGH( )    \
   GPIO_OUTPUT_SET(GPIO_ID_PIN( I2C_MASTER_SCL_GPIO ), 1 )

#define I2C_MASTER_SDA_LOW( )    \
   GPIO_OUTPUT_SET(GPIO_ID_PIN( I2C_MASTER_SDA_GPIO ), 0 )

#define I2C_MASTER_SDA_HIGH( )    \
   GPIO_OUTPUT_SET(GPIO_ID_PIN( I2C_MASTER_SDA_GPIO ), 1 )

#define TM1637_DIGITS            6

#endif

Attachments
(712.75 KiB) Downloaded 254 times