Nokia 5110 LCD initialization issue

I am trying to connect Nokia 5110 LCD to BeagleBone Black Rev-C over SPI protocol.

The connections are exactly as shown on the page 6 of: Nokia5110-BeagleBone Black Connections

I wrote a C equivalent of Arduino's code for Philips PCD8544 (Nokia 3310) driver. Where I export the required GPIO ports and send commands and data over SPI interface.

I successfully installed and ran Adafruit's python-library: Adafruit Nokia LCD

My problem is

I have a strange issue, when I run this python code first and then my C code, the code works perfect! But if I run my C code before the python code, I get no output. Logic says that the python code must be initializing something that I am missing in my code.

Here's how I initialize the LCD:

    fd_spi_dev = open(device, O_RDWR);
//set mode
mode = SPI_MODE_0;
ioctl(fd_spi_dev, SPI_IOC_WR_MODE, &mode);
ioctl(fd_spi_dev, SPI_IOC_RD_MODE, &mode);
//set max bitrate
speed = 4000000;
ioctl(fd_spi_dev, SPI_IOC_RD_MAX_SPEED_HZ, &speed);
ioctl(fd_spi_dev, SPI_IOC_WR_MAX_SPEED_HZ, &speed);
// set an msb first
lsbsetting = 0;
ioctl(fd_spi_dev, SPI_IOC_WR_LSB_FIRST, &lsbsetting);
// set bits per word
bits = 8;
ioctl(fd_spi_dev, SPI_IOC_WR_BITS_PER_WORD, &bits);
ioctl(fd_spi_dev, SPI_IOC_RD_BITS_PER_WORD, &bits);

lcd_write_cmd(0x21);    // LCD extended commands
lcd_write_cmd(0xB8);    // set LCD Vop (contrast)
lcd_write_cmd(0x04);    // set temp coefficient
lcd_write_cmd(0x14);    // set biad mode 1:40
lcd_write_cmd(0x20);    // LCD basic commands
lcd_write_cmd(0x09);    // LCD all segments on
/* I am expecting to see all segments lit here */
sleep(5);
lcd_write_cmd(0x0C);    // LCD normal video 

void lcd_write_cmd(uint8_t cmd) {
    uint8_t *tx = &cmd;
    uint8_t rx;
    uint32_t len = 1;

    struct spi_ioc_transfer tr = {
       .tx_buf = (uint32_t)tx,
       .rx_buf = (uint32_t)&rx,
       .len = len,
       .delay_usecs = delay,
       .speed_hz = speed,
       .bits_per_word = bits,
       .cs_change = 1,
    };

   size = write(fd_dc_val, "0", 1);
   size = write(fd_cs_val, "0", 1);

   ioctl(fd_spi_dev, SPI_IOC_MESSAGE(1), &tr);

   write(fd_cs_val, "1", 1);
}

I am a novice in embedded programming. I would greatly appreciate any help. Thank you.

Answers


If you're not missing an initialization step (and I haven't checked you against the 5110 datasheet), it must either be something wrong with your ioctls or a timing issue.

You could try using a library that abstracts away the ioctl calls to rule that out (I'm partial to my own: https://github.com/graycatlabs/serbus ;).

If it still doesn't work with that then I'd say it's probably a timing issue - Python is a lot slower than C when it comes to file I/O, so it might not be giving the LCD driver enough time to update after some of the commands - check the datasheet to see if it needs you to give it some time after any of the commands.


Need Your Help

jQuery Accordion expand all div

jquery accordion expansion

Is it possible to expand all components when page is load or when an event occurs?

Removal of Node in Binary Search Tree

c algorithm tree

I have the a BST that looks like this: