This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

Need help using tm1637 on nRF528232 (SDK V15.2.0)

Hi.
I want to output numbers to tm1637 display with nrf52832.

The existing library is dedicated to Arudino, so we will contact you to change it for nRF52.
(Existing library: github.com/.../DigitalTube)

Most of the code above uses pinMode, digitalWrite, and digitalRead to output to the screen. (Using CLK and DIO pins)

So I created a function to use for nRF52 as follows.

#ifndef INPUT
#define INPUT 0x00
#endif

#ifndef OUTPUT
#define OUTPUT 0x01
#endif

#ifndef INPUT_PULLUP
#define INPUT_PULLUP 0x02
#endif

#ifndef HIGH
#define HIGH 0x01
#endif

#ifndef LOW
#define LOW 0x00
#endif

void pinMode (
    
uint32_t pin, uint8_t mode)
{
  
if (mode == OUTPUT)
  
{
    
nrf_gpio_cfg_output (pin);
  
}

  
else if (mode == INPUT)
  
{
    
nrf_gpio_cfg_input (pin, GPIO_PIN_CNF_PULL_Pulldown);
  
}

  
else if (mode == INPUT_PULLUP)
  
{
    
nrf_gpio_cfg_input (pin, GPIO_PIN_CNF_PULL_Pullup);
  
}
}

void
digitalWrite (
    
uint32_t pin, uint32_t value)
{
  
nrf_gpio_pin_write (pin, value);
}

uint32_t
digitalRead (
    
uint32_t pin)
{
  
return nrf_gpio_pin_read (pin);
}

Then, change all of the parts corresponding to the above existing source to the following contents, and execute
There were some letters that came out normally, but most of the letters were not printed properly.

Is there a problem with the above function? If you need to change it, please let us know the change.

Currently, clk (P0_08), dio (P0_07) are used.

Thank you.

Parents
  • I don't see anything obviously wrong in your code. It could be a timing issue though. This datasheet states that:

    And I don't see anything in the Arduino library that limits the frequency. You should probably do as  suggests, and verify that your nRF52 outputs correct signals. 

  • I don't see anything in the Arduino library that limits the frequency
    the code uses pinMode, digitalWrite, and digitalRead

    I think that would severely limit the speed (ie, frequency) ... ?!

  • Everything is relative I guess. I did a quick test with 's code and the Arduino library. With no extra limitations to the frequency (other than the slow nature of the bit banging itself) the clock frequency is 263 kHz:

    Slow, but not slow enough. The nRF52 is a little too fast. 

    Test code:

    #include <stdbool.h>
    #include <stdint.h>
    
    #include "nrf.h"
    #include "nordic_common.h"
    #include "boards.h"
    
    #define Clkpin 22
    #define Datapin 23
    
    #ifndef INPUT
    #define INPUT 0x00
    #endif
    
    #ifndef OUTPUT
    #define OUTPUT 0x01
    #endif
    
    #ifndef INPUT_PULLUP
    #define INPUT_PULLUP 0x02
    #endif
    
    #ifndef HIGH
    #define HIGH 0x01
    #endif
    
    #ifndef LOW
    #define LOW 0x00
    #endif
    
    void pinMode (uint32_t pin, uint8_t mode)
    {
      if (mode == OUTPUT)
      {
        nrf_gpio_cfg_output (pin);
      }
    
      else if (mode == INPUT)
      {
        nrf_gpio_cfg_input (pin, GPIO_PIN_CNF_PULL_Pulldown);
      }
    
      else if (mode == INPUT_PULLUP)
      {
        nrf_gpio_cfg_input (pin, GPIO_PIN_CNF_PULL_Pullup);
      }
    }
    
    void digitalWrite (uint32_t pin, uint32_t value)
    {
      nrf_gpio_pin_write (pin, value);
    }
    
    uint32_t digitalRead (uint32_t pin)
    {
      return nrf_gpio_pin_read (pin);
    }
    
    void writeByte(int8_t wr_data)
    {
      uint8_t i,count1;   
      for(i=0;i<8;i++)        //sent 8bit data
      {
        digitalWrite(Clkpin,LOW);      
        if(wr_data & 0x01)digitalWrite(Datapin,HIGH);//LSB first
        else digitalWrite(Datapin,LOW);
        wr_data >>= 1;      
        digitalWrite(Clkpin,HIGH);
          
      }  
    }
    
    /**
     * @brief Function for application main entry.
     */
    int main(void)
    {
        pinMode(Clkpin,OUTPUT);
        pinMode(Datapin,OUTPUT);
        writeByte(0xAA);
        while (true)
        {
            // Do nothing.
        }
    }
    /** @} */
    

Reply
  • Everything is relative I guess. I did a quick test with 's code and the Arduino library. With no extra limitations to the frequency (other than the slow nature of the bit banging itself) the clock frequency is 263 kHz:

    Slow, but not slow enough. The nRF52 is a little too fast. 

    Test code:

    #include <stdbool.h>
    #include <stdint.h>
    
    #include "nrf.h"
    #include "nordic_common.h"
    #include "boards.h"
    
    #define Clkpin 22
    #define Datapin 23
    
    #ifndef INPUT
    #define INPUT 0x00
    #endif
    
    #ifndef OUTPUT
    #define OUTPUT 0x01
    #endif
    
    #ifndef INPUT_PULLUP
    #define INPUT_PULLUP 0x02
    #endif
    
    #ifndef HIGH
    #define HIGH 0x01
    #endif
    
    #ifndef LOW
    #define LOW 0x00
    #endif
    
    void pinMode (uint32_t pin, uint8_t mode)
    {
      if (mode == OUTPUT)
      {
        nrf_gpio_cfg_output (pin);
      }
    
      else if (mode == INPUT)
      {
        nrf_gpio_cfg_input (pin, GPIO_PIN_CNF_PULL_Pulldown);
      }
    
      else if (mode == INPUT_PULLUP)
      {
        nrf_gpio_cfg_input (pin, GPIO_PIN_CNF_PULL_Pullup);
      }
    }
    
    void digitalWrite (uint32_t pin, uint32_t value)
    {
      nrf_gpio_pin_write (pin, value);
    }
    
    uint32_t digitalRead (uint32_t pin)
    {
      return nrf_gpio_pin_read (pin);
    }
    
    void writeByte(int8_t wr_data)
    {
      uint8_t i,count1;   
      for(i=0;i<8;i++)        //sent 8bit data
      {
        digitalWrite(Clkpin,LOW);      
        if(wr_data & 0x01)digitalWrite(Datapin,HIGH);//LSB first
        else digitalWrite(Datapin,LOW);
        wr_data >>= 1;      
        digitalWrite(Clkpin,HIGH);
          
      }  
    }
    
    /**
     * @brief Function for application main entry.
     */
    int main(void)
    {
        pinMode(Clkpin,OUTPUT);
        pinMode(Datapin,OUTPUT);
        writeByte(0xAA);
        while (true)
        {
            // Do nothing.
        }
    }
    /** @} */
    

Children
No Data
Related