Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] 16x2 LCD interfacing with Atmega32 and 16Mhz external crystal

Status
Not open for further replies.

pepaboy

Newbie level 5
Newbie level 5
Joined
Mar 25, 2012
Messages
9
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,351
Hi , i got a simple problem i can't solve ..

I'm interfacing ATM1602B 16x2 LCD with Atmega32 and 16Mhz external crystal in avr studio6 and for some reason the data which i sent to the LCD isn't shown on the LCD.
I have tried than to return to the default state of the Atmega32 in taking out the 16Mhz external crystal and using the 1Mhz internal Atmega32 frequency and it works without any problem.
My question is , do i need to change something in my code in order to use the LCD with 16Mhz external crystal ( beside F_CPU 16000000UL)?
Appreciate any help !
 

Are you using an lcd library?
This sepems to be related to a delay problem, check if there is a clock define in the lib header.
Also set the clock in the project properties instead of using the define in main.
 

I'm not using any lcd libary and the clock F_CPU=16000000UL is already set in the project properties
i'm using this delay library:
#include <util/delay.h>

i check it out in nonguru:
https://www.nongnu.org/avr-libc/user-manual/delay_8h_source.html
it seems you're right, the default of the delay.h library is set to 1Mhz . i'm not sure but it seems setting the clock F_CPU=16000000UL in the project properties collide with the default in the delay.h library.
is there a way to change the default frequency in the delay.h library?
 

I have only used AVR studio 4 and use the project properties to set the clock, I never had a problem with the delay.
There is no other seperate clock define for the delay lib.
I'm not sure what is wrong in your case.

- - - Updated - - -

Do you set the clock in
AVRstudio_clock1.jpg

You should also see it defined in
AVRstudio_clock2.jpg

- - - Updated - - -

There is no other separate clock define for the delay lib.

I mean there is no define you need to set manually , there is only one define included in the library that is set to 1MHz if you don't define a clock for the project.
 

in avr studio6 i went to Project menu → Filename Properties (Alt+F7) → Toolchain → AVR/GNU C Compiler → Symbols → Add F_CPU=16000000UL to Defined Symbols.
Photo:
https://obrazki.elektroda.pl/5037982900_1348952148.png

i searched through the net it seems like the only place where the F_CPU should be defined in avr studio6.
but in general if i change the F_CPU will i need to change the length of delays which i'm using ?
 

I think this should do it.

If the clock isn't detected in the delay lib then there should be a warning
# warning "F_CPU not defined for <util/delay.h>"

Do you see such a warning in the compile log?
 

got it! needed to add few more delays before sending a string to the LCD , it works as a charm now..
 

This is ironic.. I was going to upgrade to a 16Mhz, instead of the built in 8Mhz (atmega32) and read as much as I could about it on the internet first (I've bricked more avrs than I can count by now, haha. )

Anyways, I was reading this thread and hoping the same thing wouldn't happen to me. Of course it did. The LCD stopped working, everything else works like a charm. I've updated my F_CPU in the project properties as you were talking about, even added a define for F_CPU myself, and i changed the hz in the lcd.h library file.

Then I tried increasing the delays as you mentioned, but still no luck :( Please help me, I'm almost done with this project (well, at least I've done all the hard work. Now comes the fun. Programming :))

So, if anyone could help me I would GREATLY appreciate it.

I might add:

Atmega32, 16Mhz 22pF x 2
LCD 20x2, standard one. I'm using AVR Dragon and AVR Studio for my programming. Maybe I should to some other fuse setting? I used An external crystal/resonator high freq Start up time 16k CK + 64ms.

On the LCD, the topmost row is all lit in black boxes, lower row is just illuminated by the backlight.

Thanks


EDIT: Hmm, i just noticed something weird. If I put a breakpoint just at the start of my project, it doesn't even break there. It opens a dissasembler, and i can keep hitting "run" forever, it never runs my code. Anyone recognize that??

It happened with a newly created project too, I made it just to test the LCD in a more friendly environment... This is weird..
 
Last edited:

On the LCD, the topmost row is all lit in black boxes, lower row is just illuminated by the backlight.

The above description usually indicates improper initialization of the LCD.

Most LCDs require a period to power on properly and obtain a known initial state, providing too long a delay has no ill effect, however too short a delay can produce the described result.

After the LCD has been allowed to fully power on to its proper initial state, an initialization process described in the devices specific datasheet can proceed.

Each issued command must be followed by a minimum delay as outlined in the datasheet.

Once this initialization process has been completed, the device can be configured further by issuing specific configuration commands each either followed by a delay or if the device offers the feature, monitoring of the busy flag for completion.


A typical initialization of a HD44780 compatible chipset is as follows:



Rather than the stated 15ms delay for power on, I would recommend a minimum of 50ms which seems to be adequate for most applications.


It would be difficult to advice you further without examining your code, therefore post your code so that we can assist you further.


BigDog
 

...Once this initialization process has been completed, the device can be configured further by issuing specific configuration commands each either followed by a delay or if the device offers the feature, monitoring of the busy flag for completion...
Thanks for the post!

However, that doesn't seem to be the problem. I tried making a new project, with F_CPU at 16000000UL and declaring some variables etc:
Code:
#include <avr/io.h>
#include <math.h>
#define F_CPU 16000000UL
#include <util/delay.h>

int test;

int main(void)
{
    while(1)
    {
		
		test = 1;
		_delay_ms(5000);
		test = 2;
		_delay_ms(5000);
		test =3;
		_delay_ms(5000);
		test = 4;
		_delay_ms(5000);
		test = 5;
    }
}
Then I placed breakpoints on every line and when I try to start a debug session (with the chip fused at High res/cap) I get following error:
AVR Studio was unable to start your debug session.
Please verify device selection, interface settings, target power and connections to the target device
Details:
Unable to connect to tool context:
'Atmel.VsIde.AvrStudio.Services.TargetService.TCF.Internal.Services.Remote.ToolProxy+ToolContext'.

Any Ideas?

If I change the fuse settings to work with the internal RC osc at 8Mhz it works fine. I'm going to try another crystal when I get home from work.

Thanks!

- - - Updated - - -

Strange, now that error is gone but I get the same thing happens that It did in the first place with the project I'm actually working on (not this test project)
Instead of breaking on my breakpoints it stops somewhere in an assembly file, and I can keep pressing continue (F5) forever, without ever getting to my code.
Pictures:
debug fuses.png
debugassemblywindow.png

It doesn't matter if I have OCDEN on or off. I don't really know what OCDEN does more than it has something to do with on-chip debugging...


EDIT:
I tried with a 10Mhz crystal. Now the program seems to be running but It doesn't stop at breakpoints. OCDEN on/off doesn't matter. I could not step into the program and step by myself either (start debugging and break option).. argh.
With the "real project" (lcd, keypad etc) that disassembler displays again....

This also happens sometimes:
nosourceavailible.png

Sorry for spamming, just trying to give you as much information as possible.
 
Last edited:

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top