GPIO problem in Interfacing with TM1637 Display Driver

parmar7725274
Posts: 21
Joined: Wed Jun 03, 2015 1:20 pm

GPIO problem in Interfacing with TM1637 Display Driver

Postby parmar7725274 » Wed Aug 26, 2015 1:47 am

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 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
                   );

    GPIO_REG_WRITE(   GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO)),
                      GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO))) |
                      GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE));             //open drain;
      
        GPIO_REG_WRITE(   GPIO_ENABLE_ADDRESS,
                      GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_MASTER_SDA_GPIO));
   
       GPIO_REG_WRITE(   GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO)),
                     GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SCL_GPIO))) |
                     GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE));                //open drain;
   
        GPIO_REG_WRITE( GPIO_ENABLE_ADDRESS,
                       GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << I2C_MASTER_SCL_GPIO) );
   
        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

Last edited by parmar7725274 on Thu Sep 03, 2015 2:07 pm, edited 1 time in total.

xad74
Posts: 6
Joined: Sat Aug 29, 2015 8:36 pm

Re: GPIO problem in Interfacing with TM1637 Display Driver

Postby xad74 » Sat Aug 29, 2015 8:43 pm

应该是开漏模式的问题,他提供的例程中
GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO)), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(I2C_MASTER_SDA_GPIO))) | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); //open drain;
是错误的,希望他们能提出改进方法

eriksl
Posts: 159
Joined: Fri May 22, 2015 6:22 pm

Re: GPIO problem in Interfacing with TM1637 Display Driver

Postby eriksl » Sat Sep 05, 2015 2:21 am

I don't know if this is resolved in the meantime.

My universal I/O bridge can assign SDA and SCL to random GPIO's. I'm always using GPIO4 and GPIO5, but GPIO0 and GPIO2 should work just as well (provided they're pulled up properly). I don't really trust the example I2C code from Espressif, it's really far too simple. So I suggest giving my firmware a shot, just to be sure. It has a function to send and receive arbitrary byte strings over i2c. I am curious to know if it works indeed, I2C over GPIO0 and GPIO2. It might be that the boot loader tries to send some data over GPIO0 or GPIO2 during boot and that may fool the I2C client into thinking it sees a start condition. In that case you should do an I2C bus reset procedure after boot (which, Espressif, of course, did not implement).

parmar7725274
Posts: 21
Joined: Wed Jun 03, 2015 1:20 pm

Re: GPIO problem in Interfacing with TM1637 Display Driver

Postby parmar7725274 » Sat Sep 05, 2015 10:54 am

Hi eriksl,

Thanks for your reply.

Can I get your firmware ?

Thanks & regards,
Prakash

eriksl
Posts: 159
Joined: Fri May 22, 2015 6:22 pm

Re: GPIO problem in Interfacing with TM1637 Display Driver

Postby eriksl » Sat Sep 05, 2015 3:02 pm

Of course, source and compiled: https://github.com/eriksl/esp8266-universal-io-bridge

I will make a new release soon (but no change in I2C code anyway).

I hope it gives a clue to where the actual problem is, as is gives state and actual problem on error.

Who is online

Users browsing this forum: No registered users and 41 guests