NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Support Forum » No serial without lcd_init();

August 29, 2012
by dan_engbers
dan_engbers's Avatar

I fired up a project using only the serial port for communications as I required on of the AOC ports for Input Capture.

When I commented out the LCD lines, to keep things clean, I ended up receiving some gibberish on the screen.

I created a very simply Hello World program earlier on, so I used just that with serial and ended up with a "âXª±±½± world!"

Today I found the time to try again, I uncommented the #include for lcd.h and lcd_init(); and sure enough the problem went away.

If the nerdkit staff could look at this I'm sure it would be appreciated. I can try later on, but I want to get rocking on figuring out this input capture (single SIG on sensor, no interrupts used and no experience).

August 29, 2012
by pcbolt
pcbolt's Avatar

Dan -

I'm not sure what you are asking here. Could you clarify a few things...

  • Is AOC a typo for ADC?

  • Which LCD lines did you comment out?

  • If you commented out the LCD lines...is the gibberish on some 'other' screen?

  • Where did "%$#@%* world!" show up?

I'm not a NK staff guy, I'm just curious. Feel free to post the code you are using in this thread so it can be examined in greater detail. Screen shots might help...or a pic of the gibberish you are seeing. It might have something to do with the "Stream" functions in "C". Not sure tho.

August 29, 2012
by dan_engbers
dan_engbers's Avatar

Sorry, typo...ACO (Analog Comparator Output).

I commented out #include "lcd.h" and then any lines that called functions from that header file. So lcd_init(); lcd_home(); etc

The gibberish showed up via serial port. If you run Putty (or another terminal emulator) you can receive text via your Serial port.

So the gibberish showed up in Putty for me.

August 29, 2012
by dan_engbers
dan_engbers's Avatar
/*
 * HelloWorld_Serial1.c
 *
 * Created: 8/27/2012 4:57:56 PM
 *  Author: Dan
 */

#define F_CPU 14745600

#include <stdio.h>
#include <avr/io.h>
#include <avr/pgmspace.h>

#include "delay.h"
//#include "lcd.h"
#include "uart.h"

int main(void){

    // fire up the LCD
    //  lcd_init();
    //  FILE lcd_stream = FDEV_SETUP_STREAM(lcd_putchar, 0, _FDEV_SETUP_RW);
    //  lcd_home();

    // init Serial Comm
    uart_init();
    FILE uart_stream = FDEV_SETUP_STREAM(uart_putchar, uart_getchar, _FDEV_SETUP_RW);
    stdin = stdout = &uart_stream;

    // print message to screen
    //                     20 columns wide:
    //                     01234567890123456789
    //  lcd_line_one();
    //  lcd_write_string(PSTR("Hello, world!"));

    // print message to Serial
    printf_P(PSTR("Hello, world!\r\n"));

    while(1){
        // Do Nothing
    }
    return 0;
}
August 30, 2012
by Rick_S
Rick_S's Avatar

The compiler is optimizing something out, turn off optimizations by changing the line in the makefile that says:

GCCFLAGS=-g -Os -Wall -mmcu=atmega328p

to:

GCCFLAGS=-g -O0 -Wall -mmcu=atmega328p

(leave the micro for whichever variety you have) That is changing the dash capital letter O lower case letter s to dash capital letter O number zero. After I did this is worked as expected.

Rick

August 30, 2012
by dan_engbers
dan_engbers's Avatar

That might solve some unexplainable issues I've been having...partially anyway.

I've been using Atmel Studio 6 so I don't have a makefile, but that option was set to O1 as a default on the project.

Thanks Rick. I'll test that later tonight.

June 16, 2013
by kschallitz
kschallitz's Avatar

Hi guys, I hate to ask a "silly question", but this is starting to bother me... I can't seem to get serial I/O to work at all. I've used the code listed above by Dan but I get nothing output on PUTTY (COM4 115200 N81). Connecting the green / yellow wires does echo in Putty. I've confirmed the wires are connected to the correct Pins on the NerdKit (or else I wouldn't have been able to program it!). I've also tried it at both 3.6v and 5v, but neither work.

Hard to ask for help on this with a general, "it's not working, help!" but, ya... it's not working. Help!

If there are any more details that I can offer that would give someone the insight as to what's wrong, let me know.

I somewhat suspect that it may have something to do with my makefile and the link options or something.

Right now I am using Linker Flags: -mmcu=atmega328p -Wl,-u

Compile options: -mmcu=atmega328p -g -O0 -Wall

Hope that helps!

June 16, 2013
by kschallitz
kschallitz's Avatar

Ooops Link flags got cutoff for some reason... here is the full link flags:

-mmcu=atmega328p -Wl,-u,vfprintf -lprintf_flt -Wl,-u,vfscanf -lscanf_flt -lm

June 17, 2013
by pcbolt
pcbolt's Avatar

kschallitz -

What operation system are you using? Everything looks OK at first glance. You might try using a progam called "RealTerm" (freeware). It has quite a few options and has a screen that shows each individual wire connected to the comm port. It may help troubleshoot the problem.

Post a Reply

Please log in to post a reply.

Did you know that you can connect a computer keyboard to your microcontroller? Learn more...