Bad initialization?

This is a discussion on Bad initialization? within the C Programming forums, part of the General Programming Boards category; UART2 RX TX initialization-how to use? Hello, I have problem with initialization UART2 in my project(STM8S105). Below you can see ...

  1. #1
    Registered User
    Join Date
    Dec 2011
    Posts
    1

    Bad initialization?

    UART2 RX TX initialization-how to use?
    Hello, I have problem with initialization UART2 in my project(STM8S105). Below you can see part of my code, what am i doing wrong?
    I'm trying to send sign to LCD display.

    Code:
    void UART2_Cmd(FunctionalState ENABLE);
    
    void UART2_InitGPS()
    {
        UART2_DeInit();
        UART2_Init( (u32)9600, UART2_WORDLENGTH_8D, UART2_STOPBITS_1,  UART2_PARITY_NO, UART2_SYNCMODE_CLOCK_DISABLE,  UART2_MODE_TXRX_ENABLE);    
    }
    
    void UART2_SendData8(u8 Data);
    
    u8 UART2_ReceiveData8(void);
    
    void main(void)
    {
        char tmp;
        LCD5110_init(); //function which initialize LCD
        LCD5110_set_XY(0,0); //function which set rows and columns in LCD
        UART2_SendData8(36);//
        UART2_ReceiveData8();
        tmp = UART2_ReceiveData8();
        LCD5110_write_char(tmp); //function which send characters to LCD 
    }
    I have to mention that i have no errors after compiling code and if I use function like this everything works fine(but I need UART to racive data from GPS and send it to LCD) :
    Code:
    void main(void)
    {
        char tmp=33; //33 -> "!" sign in my matrix(table or haw to name it)
        LCD5110_init(); //function which initialize LCD
        LCD5110_set_XY(0,0); //function which set rows and columns in LCD
       
        LCD5110_write_char(tmp); //function which send characters to LCD 
    }
    BR,
    Oklem

    P.S. If somebody wants to see whole code let me know
    https://my.st.com/_layouts/images/blank.gif

  2. #2
    Registered User joybanerjee39's Avatar
    Join Date
    Oct 2011
    Location
    kolkata
    Posts
    107
    return type of main is not void it's int

  3. #3
    Banned
    Join Date
    Aug 2010
    Location
    Ontario Canada
    Posts
    9,547
    Quote Originally Posted by joybanerjee39 View Post
    return type of main is not void it's int
    He's working in a microcontroller... there's no OS to return to...

    (And yes they ripped me about this one too...)

  4. #4
    Registered User
    Join Date
    Aug 2003
    Posts
    1,205
    Off the top of my head I dont see you calling UART2_Init anywhere in the codepath. Also add a while(1); right at the end of main, who knows what the MCU does once the program end. If that still doesnt work make a small program along the paths of:
    Code:
    void main(void)
    {
        char tmp = 0;
        UART2_Init(...);
        UART2_SendData8('A');
        tmp = UART2_GetData8();
        LCD5110_write_char(tmp);
        while(1);
    }
    Then get one of these:
    USB TTL Serial

    Solder it in place of the GPS (only need to solder RX, TX and GND) and try it with your computer to see if you can get the MCU to send 'A' to a terminal and see if you can send something to the MCU and have it show up on the LCD.

  5. #5
    Registered User joybanerjee39's Avatar
    Join Date
    Oct 2011
    Location
    kolkata
    Posts
    107
    Quote Originally Posted by CommonTater View Post
    He's working in a microcontroller... there's no OS to return to...

    (And yes they ripped me about this one too...)
    oops! my bad!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C initialization
    By vpshastry in forum C Programming
    Replies: 10
    Last Post: 09-16-2011, 01:17 PM
  2. SDL Initialization Error...
    By Comrade_Yeti in forum C++ Programming
    Replies: 0
    Last Post: 05-16-2005, 05:43 PM
  3. Invalid Initialization
    By Hexxx in forum C Programming
    Replies: 2
    Last Post: 11-27-2003, 09:48 PM
  4. Initialization. Are they the same?
    By lockpatrick in forum C++ Programming
    Replies: 3
    Last Post: 08-21-2002, 11:46 PM
  5. Initialization question
    By cpp4ever in forum C++ Programming
    Replies: 0
    Last Post: 10-19-2001, 05:09 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21