• Welcome to Andy's Workshop Forums. Please login or sign up.
 

stm32plus 4.0.3 -exam. hd44780 - F1MD not work =(

Started by PC-maniak, February 20, 2016, 12:43:32 pm

Previous topic - Next topic

PC-maniak

Hi I am a beginner in the field STM32
So I wanted to first try the example HD44780
code compilation went fine
but lcd is not working

i have this board :
http://www.ebay.com/itm/181617112245?_trksid=p2057872.m2749.l2649&ssPageName=STRK%3AMEBIDX%3AIT

I changed the pins used to be able to connect the LCD to my board but it does not work

Then I added a blinking LED on the board I saw that the code works and does not get stuck with (it flashes How should)

enclose a photo of the whole assembly

please where I make mistakes? = (


/*
* This file is a part of the open source stm32plus library.
* Copyright (c) 2011,2012,2013,2014 Andy Brown <www.andybrown.me.uk>
* Please see website for licensing terms.
*/

#include "config/stm32plus.h"
#include "config/display/character.h"


using namespace stm32plus;
using namespace stm32plus::display;


/**
*
* HD44780 20x4 character LCD demo. For this demonstration
* we will attach the character LCD to the following pins:
*
* PC[0] => RS
* PC[1] => ENABLE
* PC[2] => D0
* PC[3] => D1
* PC[4] => D2
* PC[5] => D3
*
* This demonstration attachs a text terminal class to the
* LCD for convenient text output. We then go into an
* infinite loop writing out the famous Lorem Ipsum
* passage, scrolling the display each time the output
* reaches the end of the display.
*
* Compatible MCU:
*   STM32F0
*   STM32F1
*   STM32F4
*
* Tested on devices:
*   STM32F103ZET6
*   STM32F407VGT6
*/


/**
* The sample text
*/


static const char *sampleText[]={
  "Lorem","ipsum","dolor","sit","amet,","consectetur","adipisicing","elit,","sed","do","eiusmod","tempor","incididunt","ut","labore","et","dolore","magna","aliqua.","Ut","enim","ad","minim","veniam,","quis","nostrud","exercitation","ullamco","laboris","nisi","ut","aliquip","ex","ea","commodo","consequat.","Duis","aute","irure","dolor","in","reprehenderit","in","voluptate","velit","esse","cillum","dolore","eu","fugiat","nulla","pariatur.","Excepteur","sint","occaecat","cupidatat","non","proident,","sunt","in","culpa","qui","officia","deserunt","mollit","anim","id","est","laborum",NULL
};


class HD44780Test {

  public:

    void run() {

      int i,written,len;

      /*
       * Initialise the 6 required pins for output
       */
      GpioC<DefaultDigitalOutputFeature<13> > pc;

      GpioA<DefaultDigitalOutputFeature<0,1,2,3,4,5> > pa;

      /*
       * Initialise the 20x4 display
       */

      HD44780 lcd(pa[0],pa[1],pa[2],pa[3],pa[4],pa[5],16,2);

      /*
       * Attach a terminal to the display so we can easily demonstrate the
       * text output function
       */

      CharacterLcdTerminal<HD44780> terminal(lcd);

      /*
       * Write out the sample text
       */

      terminal.clear();

      for(i=written=0;;) {

        // if the current word plus trailing space would wrap, start a new line

        len=strlen(sampleText[i])+1;
        if(written+len>16) {
          terminal << '\n';
          written=0;
        }

        // write out the current word with the following space

        terminal << sampleText[i] << ' ';
        written+=len;

        // if there is no next word then start again

        if(sampleText[++i]==NULL)
          i=0;

        // delay for a 500ms before the next word
MillisecondTimer::delay(1000);
pc[13].set();
        MillisecondTimer::delay(1000);
pc[13].reset();
      }
    }
};


/*
* Main entry point
*/

int main() {

  // set up SysTick at 1ms resolution
  MillisecondTimer::initialise();

  HD44780Test test;
  test.run();

  // not reached
  return 0;
}



Andy Brown

Hi, welcome to the forum.

I can see two mistakes in the wiring that are the cause of the issue.

Most important is that your data lines are connected to the LCD DB0..DB3. When running in 4-bit mode it is the high 4 bits, DB4..DB7, of the LCD data bus that connect to D0..D3. Change your wiring like this:

PA2 (D0) => LCD DB4
PA3 (D1) => LCD DB5
PA4 (D2) => LCD DB6
PA5 (D3) => LCD DB7

The other thing is that your contrast might be at such a level that you cannot see any characters. It's best to connect it (pin #3, Ve) through a 10K pot to ground. You can then turn the pot to the ideal position for viewing the display, measure the resistance and then put a fixed value resistor in its place.

Your code works without any modifications but make sure that your linker.ld file is set for a flash memory size of 64kb to match your MCU. Here's a photo of me running your code.

It's worse than that, it's physics Jim!

PC-maniak

Andy thanks you =) !

But I do not understand why it is inscribed in the example data pin 0-3  ::)

if it needs to use data pin 4-7  :o

;D

Andy Brown

I admit it can be misleading. I refer in the documentation to the bit positions within a 4-bit word D0, D1, D2, D3. They are then physically connected to the high 4 pins of the LCD data bus. I could certainly improve the documentation to be more clear about that.
It's worse than that, it's physics Jim!

PC-maniak

aha! yes for beginners the total is very misleading  :o