0
\$\begingroup\$

I am trying to interface LCD 16x2 with STM32 for learning purpose. I already interfaced with AVR, PIC etc. that code ported some of. But its not working. What am I doing wrong?

void LCD_init(void)
    {
    
      HAL_Delay(20);
      lcd_cmd(0x30);
      HAL_Delay(20);
      lcd_cmd(0x30);
      HAL_Delay(20);
      //Delay_Us(100);
      lcd_cmd(0x28);
      HAL_Delay(20);
       lcd_cmd(0x28);            // Function set (4-bit interface, 2 lines, 5*7Pixels)
       lcd_cmd(0x28);            // Function set (4-bit interface, 2 lines, 5*7Pixels)
       lcd_cmd(0x0c);            // Make cursorinvisible
       lcd_Clear();            // Clear screen
       lcd_cmd(0x6);            // Set entry Mode(auto increment of cursor)
    }
    
    oid lcd_cmd(__uint16_t cmd)
    {       GPIOB->ODR =0;
            HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10, GPIO_PIN_RESET);
            cmd = (cmd << 8) ;
            GPIOB->ODR =  (cmd & 0xf000);
            lcd_Strobe();
            cmd = (cmd << 4) ;
            GPIOB->ODR =  (cmd & 0xf000);
            lcd_Strobe();
            GPIOB->ODR =0;
    }
    
    
    void lcd_data(__uint16_t lcd_data)
    {     GPIOB->ODR =0x0000;
        // HAL_GPIO_WritePin(GPIOB,GPIO_PIN_10, GPIO_PIN_SET);
         lcd_data = (lcd_data << 8) ;
         GPIOB->ODR =  (lcd_data& 0xf000)|0x400;
         lcd_Strobe();
         GPIOB->ODR =0;
         lcd_data = (lcd_data << 4) ;
         GPIOB->ODR =  (lcd_data & 0xf000)|0x400;
         lcd_Strobe();
         GPIOB->ODR =0;
    }
    
    
    void lcd_Clear(void)
    {
        lcd_cmd(0x01);
        HAL_Delay(5);
    }
    
    void lcd_String(const char *ptr)  // ptr pointing the address of displaying string
    {
        while (*ptr)             // check weather the endo of file then exit the loop
        {
            lcd_data(*ptr++);    // Sending data to LCD_data functions
        }
    }



 void lcd_Strobe(void)
{

    HAL_GPIO_WritePin(GPIOB,GPIO_PIN_11, GPIO_PIN_SET);// LCD Enable PIN to High
   // HAL_Delay(1);
    //Delay_Us(100);
    HAL_GPIO_WritePin(GPIOB,EN_Pin, RESET);// LCD Enable High to Low
    //Delay_Us(100);PIO_PIN_11
   // HAL_Delay(1);
 }

enter image description here

\$\endgroup\$
12
  • 1
    \$\begingroup\$ Electrone - Hi, I see you are already getting help & have given more details about the specific problem & your troubleshooting so far, where you asked the same question on the edaboard.com forum here. Other site members here might be able to help, but I don't want to waste your time (or mine) doing troubleshooting & asking for specific tests, which will overlap / duplicate the actions you are already doing, and the advice you are getting, on that thread. || Can you be more specific than "not working"? \$\endgroup\$
    – SamGibson
    Commented Oct 2, 2023 at 10:37
  • \$\begingroup\$ sir ,i am struggling it toclearout from 2 days , Its nothing display \$\endgroup\$
    – Electrone
    Commented Oct 2, 2023 at 10:50
  • \$\begingroup\$ posted here also to get more suggestion \$\endgroup\$
    – Electrone
    Commented Oct 2, 2023 at 11:03
  • 2
    \$\begingroup\$ Electrone - As I said, I don't want to waste your time duplicating the help which is ongoing in that edaboard.com thread. However from a very quick scan of the code, you have only shown initialisation & helper functions (which may or may not be correct) and which should not actually compile (it says oid instead of void in one place). I don't see any code provided here which tries to display anything. Quickly checking on the edaboard.com forum I linked previously, I see you provided extra code (i.e. your main.c) there, but not here :( I recommend you make the question here complete. \$\endgroup\$
    – SamGibson
    Commented Oct 2, 2023 at 11:29
  • 2
    \$\begingroup\$ You've left VEE floating and you have VDD & VSS to your LCD connected the wrong way around. If Proteus simulated smoke then you'd see it coming out of your LCD. \$\endgroup\$
    – brhans
    Commented Oct 2, 2023 at 12:10

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.