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

nRF52 LCD cannot display custom character

Hi, guys. 

I'm using nRF52 DK (PCA10040) and 16x2 LCD (ST7032i). I would like to create a custom icon (e.g. degree Celsus ℃). Here is my code. It doesn't print anything on the screen. Thank you! 

// custom icon: degree 
uint8_t degree_icon[8] = {
  0x06,
  0x09,
  0x09,
  0x06,
  0x00,
  0x00,
  0x00,
  0x00
};


// Send command to LCD to do configuration
void ST7032_command(uint8_t command)
{
    uint8_t cmd_command = 0x00;
    uint8_t st7032_cmd[2] = {cmd_command, command};

    ret_code_t  err_code_st7032_command;
    err_code_st7032_command = nrf_drv_twi_tx(&m_twi, ST7032_I2C_DEFAULT_ADDR, st7032_cmd, sizeof(st7032_cmd), false);
    APP_ERROR_CHECK(err_code_st7032_command);
    nrf_delay_ms(1);
}


// Send command to LCD to display data on LCD screen
void ST7032_write(uint8_t value)
{
    uint8_t cmd_write = 0x40;
    uint8_t st7032_cmd[2] = {cmd_write, value};

    ret_code_t  err_code_st7032_write;
    err_code_st7032_write = nrf_drv_twi_tx(&m_twi, ST7032_I2C_DEFAULT_ADDR, st7032_cmd, sizeof(st7032_cmd), false);
    APP_ERROR_CHECK(err_code_st7032_write);
    nrf_delay_ms(20);
}


void ST7032_setCursor(uint8_t col, uint8_t row)
{
    // 0x00, 0x40 (hex) =  0, 64 (int)
    // 0x14, 0x54 (hex) = 20, 84 (int)
    const int row_offsets[] = { 0x00, 0x40, 0x14, 0x54 };

    if ( row > numlines ) {
      row = numlines-1;
    }
    ST7032_command(LCD_SETDDRAMADDR | (col + row_offsets[row]));
}


void ST7032_createChar(uint8_t location, uint8_t *char_map) {
    location &= 0x7; // we only have 8 locations 0-7
    ST7032_command(LCD_SETCGRAMADDR | (location << 3));
    for (int i=0; i<8; i++) {
        ST7032_write(char_map[i]);
    }
    ST7032_command(0x80);
}


// ------------ In the "main loop", I have the following code to print the custom icon --------------
ST7032_setCursor(13, 1);       // row 1, column 13
ST7032_createChar(0,degree_icon);
ST7032_write(0);

Parents Reply Children
No Data
Related