Tormented Newbie - Frequent error using Fleury lcd code example

Go To Last Post
37 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I have had the same errors using a Atmega16, Atmega328p, and Arduino nano. But I managed to get

the code for the nano to compile and run. I have been using an Dragon using the ISP interface on AS7

(ver. 7.0.1645) with Win10.

 

Dang error message tells me the line in the makefile that caused the error, but then it doesn't create the

makefile for me to read?

 

I read about the possibility of it being a windows 10 problem and tried changing the avr workspace folder

location.

 

The threads I found were similar, but .o files, or the .elf file problem was unresolved.

 

Is there a way to read the .elf makefile that failed?

 

Thanks

 

Bill M.

 

Last Edited: Mon. Feb 26, 2018 - 03:09 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Show us the build output - that will tell us what is causing the upset. The error output just tells us there was an error.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The simplest and quickest way to get an answer:
.
ZIP up your project directory and attach the .zip file.
.
Then we can reproduce your project to see what the problem is.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Atmel really shot themselves in the foot when they retained Microsoft's "Error List" feature from Visual Studio. It filters the errors too much. All you see above are the final consequence of the errors in the build but not what caused them. As Kartman says, switch to "Output" after the build, copy all that and paste it into a message here.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 2

Also,

Your title of the thread hints that you are blaming the Peter Fleury code for the error.  There are thousands of us that use that code all the time without error so I would bet that there is something else causing your problem.

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

My guess is that there's a .c file not added to the project and undefined reference errors in the link.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

or, possibly, a missing or not-found .h file - giving undeclared stuff in the compile ... ?

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

So if you have a makefile, can you run "make all" from the command line?

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Ok, everyone.  WE have speculated enough.  Lets wait and see what the OP comes back with.  No sense filling the thread with guesses(Then again what fun is waiting right?)

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

There are thousands of us that use that code all the time without error so I would bet that there is something else causing your problem.

 

Agreed!

 

As far as I can tell, the program was originally written for the same chip I am using.

For a long time I thought there may be a difference in the pin registers on the newer

chips, so then I dug out the Atmega16.

 

I had the darnedest time finding the "output window." I didn't find it in help, nor in the menu Window Tab.

The online help mentioned that it exists, but no details to where it was.

 

Finally I founded by accident at the bottom of the error plane (window). But the output button

is covered up by a blue bar that says "ready."

 

I put the output and makefile in a pdf so that it can be searched, highlighted, and possibly

commented on. All the files including the project zip file are at the bottom of the page. 

 

 

Thanks for all the responses!

 

 

Bill M.

 

--- Build started: Project: GccApplication1, Configuration: Debug AVR ------
Build started.
Project "GccApplication1.cproj" (default targets):
Target "PreBuildEvent" skipped, due to false condition; ('$(PreBuildEvent)'!='') was evaluated as (''!='').
Target "CoreBuild" in file "C:\Program Files (x86)\Atmel\Studio\7.0\Vs\Compiler.targets" from project "C:\AVR workspace\GccApplication1\GccApplication1\GccApplication1.cproj" (target "Build" depends on it):
	Task "RunCompilerTask"
		Shell Utils Path C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils
		C:\Program Files (x86)\Atmel\Studio\7.0\shellUtils\make.exe all --jobs 4 --output-sync
		Building target: GccApplication1.elf
		Invoking: AVR/GNU Linker : 5.4.0
		"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe" -o GccApplication1.elf  lcd.o   -Wl,-Map="GccApplication1.map" -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=atmega16 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.150\gcc\dev\atmega16"
C:\AVR workspace\GccApplication1\GccApplication1\Debug\Makefile(108,1): error: recipe for target 'GccApplication1.elf' failed
		C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.150/gcc/dev/atmega16/avr5/crtatmega16.o:../../../../crt1/gcrt1.S:310: undefined reference to `main'
collect2.exe(0,0): error: ld returned 1 exit status
		make: *** [GccApplication1.elf] Error 1
		The command exited with code 2.
	Done executing task "RunCompilerTask" -- FAILED.
Done building target "CoreBuild" in project "GccApplication1.cproj" -- FAILED.
Done building project "GccApplication1.cproj" -- FAILED.

Build FAILED.
========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped ==========
################################################################################
# Automatically-generated file. Do not edit!
################################################################################

SHELL := cmd.exe
RM := rm -rf

USER_OBJS :=

LIBS :=
PROJ := 

O_SRCS :=
C_SRCS :=
S_SRCS :=
S_UPPER_SRCS :=
OBJ_SRCS :=
ASM_SRCS :=
PREPROCESSING_SRCS :=
OBJS :=
OBJS_AS_ARGS :=
C_DEPS :=
C_DEPS_AS_ARGS :=
EXECUTABLES :=
OUTPUT_FILE_PATH :=
OUTPUT_FILE_PATH_AS_ARGS :=
AVR_APP_PATH :=$$$AVR_APP_PATH$$$
QUOTE := "
ADDITIONAL_DEPENDENCIES:=
OUTPUT_FILE_DEP:=
LIB_DEP:=
LINKER_SCRIPT_DEP:=

# Every subdirectory with source files must be described here
SUBDIRS := 

# Add inputs and outputs from these tool invocations to the build variables
C_SRCS +=  \
../lcd.c

PREPROCESSING_SRCS += 

ASM_SRCS += 

OBJS +=  \
lcd.o

OBJS_AS_ARGS +=  \
lcd.o

C_DEPS +=  \
lcd.d

C_DEPS_AS_ARGS +=  \
lcd.d

OUTPUT_FILE_PATH +=GccApplication1.elf

OUTPUT_FILE_PATH_AS_ARGS +=GccApplication1.elf

ADDITIONAL_DEPENDENCIES:=

OUTPUT_FILE_DEP:= ./makedep.mk

LIB_DEP+= 

LINKER_SCRIPT_DEP+= 

# AVR32/GNU C Compiler

./%.o: .././%.c
	@echo Building file: $<
	@echo Invoking: AVR/GNU C Compiler : 5.4.0
	$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE)  -x c -funsigned-char -funsigned-bitfields -DDEBUG  -I"C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.150\include"  -O1 -ffunction-sections -fdata-sections -fpack-struct -fshort-enums -g2 -Wall -mmcu=atmega16 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.150\gcc\dev\atmega16" -c -std=gnu99 -MD -MP -MF "$(@:%.o=%.d)" -MT"$(@:%.o=%.d)" -MT"$(@:%.o=%.o)"   -o "$@" "$<"
	@echo Finished building: $<

# AVR32/GNU Preprocessing Assembler

# AVR32/GNU Assembler

ifneq ($(MAKECMDGOALS),clean)
ifneq ($(strip $(C_DEPS)),)
-include $(C_DEPS)
endif
endif

# Add inputs and outputs from these tool invocations to the build variables 

# All Target
all: $(OUTPUT_FILE_PATH) $(ADDITIONAL_DEPENDENCIES)

$(OUTPUT_FILE_PATH): $(OBJS) $(USER_OBJS) $(OUTPUT_FILE_DEP) $(LIB_DEP) $(LINKER_SCRIPT_DEP)
	@echo Building target: $@
	@echo Invoking: AVR/GNU Linker : 5.4.0
	$(QUOTE)C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-gcc.exe$(QUOTE) -o$(OUTPUT_FILE_PATH_AS_ARGS) $(OBJS_AS_ARGS) $(USER_OBJS) $(LIBS) -Wl,-Map="GccApplication1.map" -Wl,--start-group -Wl,-lm  -Wl,--end-group -Wl,--gc-sections -mmcu=atmega16 -B "C:\Program Files (x86)\Atmel\Studio\7.0\Packs\atmel\ATmega_DFP\1.2.150\gcc\dev\atmega16"
	@echo Finished building target: $@
	"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O ihex -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures  "GccApplication1.elf" "GccApplication1.hex"
	"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -j .eeprom  --set-section-flags=.eeprom=alloc,load --change-section-lma .eeprom=0  --no-change-warnings -O ihex "GccApplication1.elf" "GccApplication1.eep" || exit 0
	"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objdump.exe" -h -S "GccApplication1.elf" > "GccApplication1.lss"
	"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-objcopy.exe" -O srec -R .eeprom -R .fuse -R .lock -R .signature -R .user_signatures "GccApplication1.elf" "GccApplication1.srec"
	"C:\Program Files (x86)\Atmel\Studio\7.0\toolchain\avr8\avr8-gnu-toolchain\bin\avr-size.exe" "GccApplication1.elf"

# Other Targets
clean:
	-$(RM) $(OBJS_AS_ARGS) $(EXECUTABLES)
	-$(RM) $(C_DEPS_AS_ARGS)
	rm -rf "GccApplication1.elf" "GccApplication1.a" "GccApplication1.hex" "GccApplication1.lss" "GccApplication1.eep" "GccApplication1.map" "GccApplication1.srec" "GccApplication1.usersignatures"
	

 

Attachment(s): 

Last Edited: Mon. Feb 26, 2018 - 04:03 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

YOu are missing a MAIN.c file  What you have here is a LIBRARY only.

 

What AVR are you using, and what size LCD?  I have a demo that I hand out that can get you going

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

LOL

 

An Atmega16, 20x4 lcd.

 

 

Thanks

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:
YOu are missing a MAIN.c file 

Specifically, you are missing a function called main() - this is the standard entry point for a 'C' program.

 

The name of the file that contains main() is not important - but the function name is.

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What port is the LCD on?

 

 

JIm

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Last Edited: Mon. Feb 26, 2018 - 04:09 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

You do not have a "main"

 

Add the Fleury example file e.g. test_lcd.c to your project.

 

Right-click on the project and select Add -> Existing Item...

 

David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

jgmdesign wrote:

What port is the LCD on?

 

porta

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Now we've seen the error. Can I ask someone from Atmel exactly why it was that you reported:

 

but no sign of:

	C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.150/gcc/dev/atmega16/avr5/crtatmega16.o:../../../../crt1/gcrt1.S:310: undefined reference to `main'

which is the true error here??

 

Within the last week there was a thread from some student that said basically the same thing - that him and his friends were all getting "recipe failed" errors with no explanation of why it was occurring. Because beginners focus on the Error List rather than the proper place to look they aren't going to know (or learn the skill) of actually observing the build output. I assume the "Error List" is built by filtering all lines from the build output that contain "error" or perhaps "error:" ? I notice...

C:\AVR workspace\GccApplication1\GccApplication1\Debug\Makefile(108,1): error: recipe for target 'GccApplication1.elf' failed
		C:/Program Files (x86)/Atmel/Studio/7.0/Packs/atmel/ATmega_DFP/1.2.150/gcc/dev/atmega16/avr5/crtatmega16.o:../../../../crt1/gcrt1.S:310: undefined reference to `main'
collect2.exe(0,0): error: ld returned 1 exit status

The two lines that made it to the Error List contain "error:" but the middle line IS an error output too.

 

Actually (need to try this) does gcc send "informational" to stdout (>1) and errors to stderr (>2)? In which case should the Error List be built from >2 irrespective of whether it contains the "error" keyword ?

 

EDIT: Rats, no, that does not seem to work:

avr-gcc -mmcu=atmega16 -Os -v avr.c -o avr.elf 1> info.txt 2> err.txt

ALL the output ended up in err.txt

Last Edited: Mon. Feb 26, 2018 - 04:28 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I knew I needed a main function, and I searched for one.

 

I eliminated the test_lcd.c file because it included code for buttons

that I didn't need or understand.

 

I thought lcd.c was the main program, even though I did not find a main function.

 

Is this the proper forum for the below questions?

 

I am going to need a few more questions about expanding the project to include

other programs and substituting the lcd for serial output.

 

Or is it easier to set-up the serial output? and if so do I need a odd sized crystal?

or is sending serial output in one direction not a big deal?

 

 

Bill M.

 

Thanks to everyone for their input, it compiles now.

Last Edited: Mon. Feb 26, 2018 - 04:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
Atmel exactly why it was that you reported:

Again, you'd have thought it was in Atmel and Microchip's interest to actively monitor their forums and see what are the things that keep tripping-up people trying to use their products - wouldn't you?

 

<rolls-eyes>

 

ISTR that Eclipse had a a similar problem with not "catching" GCC linker errors - but that was spotted and fixed years ago.

 

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Ok, I have attached the demo - Untested as I do not have a Mega16 handy, but this worked on a M328.

 

Here are your PORT A pin connections:

 

 LCD_DATA0_PIN    0            /**< pin for 4bit data bit 0  */
 LCD_DATA1_PIN    1            /**< pin for 4bit data bit 1  */
 LCD_DATA2_PIN    2            /**< pin for 4bit data bit 2  */
 LCD_DATA3_PIN    3            /**< pin for 4bit data bit 3  */
 LCD_RS_PIN       4            /**< pin  for RS line         */
 LCD_RW_PIN       5            /**< pin  for RW line         */
 LCD_E_PIN        6            /**< pin  for Enable line     */

 

I assume internal 8Mhz RC oscillator as your clock source.

 

This should get you going.  The Test_LCD.c file simply runs a loop where the screen is constantly configures, and prints a message.  Leaves it these for two and a half seconds, then blanks the screen and repeats the process.  I chose to re-initialise the LCD every time so should you make a mistake on your wiring  as you correct it the screen will eventually come to life.

 

Jim

 

Attachment(s): 

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Last Edited: Mon. Feb 26, 2018 - 04:31 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Your nano board has a 16MHz crystal or resonator. Is this ‘odd sized’? Nevertheless, you want a crystal to ensure correct timing- the internal oscillator may not be close enough.

For an example of serial:
http://www.nongnu.org/avr-libc/user-manual/group__stdiodemo.html

The AVR has been around for about 20 years. Most questions you might ask have already been answered, so Google first.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wmazz wrote:
I eliminated the test_lcd.c file because it included code for buttons that I didn't need or understand.

In the code I sent you?  WHERE?  I just looked and see nothing about buttons

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:

Your nano board has a 16MHz crystal or resonator. Is this ‘odd sized’? Nevertheless, you want a crystal to

ensure correct timing- the internal oscillator may not be close enough.

 

For an example of serial:
http://www.nongnu.org/avr-libc/u...

The AVR has been around for about 20 years.

 

Most questions you might ask have already been answered, so Google first.

 

I would not ask a question without researching it first. There is a lot of material out

there, and sometimes I waste time on reading posts and info that doesn't pan out.

 

Like this tutorial from the AVR TUT section and Four Walled Cubical:

Quote:

If the system clock cannot be precisely divided down to a "magic" frequency for perfect communications, it
will have a percentage error (where a byte fails to be read or written inside designated time frame). System
clocks for perfect USART communications should be multiples of 1.8432MHz which when used will give a
0.00% error.

 

I have been messing around with micro controllers since the late-90's, and I have never used a uC with an 

oddball crystal, so I asked a question. But I can understand why it sounded lazy.

 

 

 

jgmdesign wrote:

wmazz wrote:

I eliminated the test_lcd.c file because it included code for buttons that I didn't need or understand.

In the code I sent you?  WHERE?  I just looked and see nothing about buttons

 

The "test_lcd" I was referring too was from the Peter Fleury example.

 

Thanks Again!

 

 

Bill M.

Last Edited: Fri. Mar 2, 2018 - 05:30 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

What do you consider to be an ‘oddball’ crystal frequency? For example, i use a 11.0592MHz crystal in my AVR designs. I consider that standard frequency.

Last Edited: Fri. Mar 2, 2018 - 08:07 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
What do you consider to be an ‘oddball’ crystal frequency? For example, i use a 11.0592MHz crystal in my AVR designs. I consider that standard frequency.

 

As well as using some 'odd' looking frequencies, I've also driven an AVR from a VCO, putting it inside a Phase-Locked Loop. As long as you stay within the specified frequency range then the chip neither knows nor cares what frequency it is running at.

#1 This forum helps those that help themselves

#2 All grounds are not created equal

#3 How have you proved that your chip is running at xxMHz?

#4 "If you think you need floating point to solve the problem then you don't understand the problem. If you really do need floating point then you have a problem you do not understand." - Heater's ex-boss

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Kartman wrote:
i use a 11.0592MHz crystal in my AVR designs. I consider that standard frequency.

It is, indeed, a very common frequency - because it divides nicely to easily give standard baud rates.

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Fri. Mar 2, 2018 - 08:49 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

All the "magic" crystals:

 

1.8432, 3.6864, 7.3728, 11.0592, 14.7456, 18.432

 

(which are all an integer multiple of 300Hz)

 

are going to be "common" because if some micro design centers around the use of UART then the designer is almost bound to select one that is "perfect for UART use". Why wouldn't you? It's not like they are more expensive than 1, 2, 4, 8, 16 MHz crystals.

 

One surprise actually is Arduino's choice of 16MHz. Never really understand why it was not "baud rate friendly" ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
the designer is almost bound to select one that is "perfect for UART use".

Well, an experienced designer would.

 

Probably the most frequently-recurring problem on 8052.com was newbies picking what they thought was a "nice" crystal frequency - rather than one of the "odd-looking" (to a newbie) UART-friendly ones.

 

One surprise actually is Arduino's choice of 16MHz. Never really understand why it was not "baud rate friendly" ?

see above ... ?

 

cheeky

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Maths is a lot easier with 8MHz or 16MHz.
115200 baud is ok with 16MHz but not with 8MHz.
.
Many Arduino designs have ceramic resonators which defeats the object of ANY accurate timing.
UART comms only needs 2% accuracy.
Many clones have proper 16MHz crystals. Which gives both accuracy and Serial comms.
.
David.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
One surprise actually is Arduino's choice of 16MHz. Never really understand why it was not "baud rate friendly" ?
It's legacy. The whole arduino movement was started by some students which did not know what they were doing.

The other question is: How did we get stuck with crasy numbers for baud rates in the first place?

 

For Crystals I prefer 18.432MHz or 9.216MHz. Those are nice for both accurate baud rates and an accurate (base 10) timer interrupt ticker.

Some years ago I even wrote a little pc program to generate C source code for timer constants:


/* A little PC program for calulating additonal prescaler / compare combinations.
 ~/projects/c/avr-timer2/main.c
*/

#include <stdio.h>
#include <stdlib.h>

int main( )
{
	int64_t FCPU [] = {		// CPU frequencies for which to calculate timer vals.
		3686400,
		4000000,
		7372800,
		9216000,
		11059200,
		18432000,
	};
	int PRE [] = { 0, 1, 8, 32, 64, 128, 256, 1024};
	int TIME [] = {500, 1000, 2500, 5000, 10000};	// Times in microseconds
	int Fcpu, Pre, Time, MaxCount, iActualTime;
	float fActualTime, Dev;

	for( Fcpu = 0; Fcpu < sizeof(FCPU)/sizeof(int64_t); Fcpu++)
	{
		printf("#endif\n");
		printf("//---------------------------------------------------------------------------\n");
		printf("#elif F_CPU == %d\n", (int)FCPU[Fcpu]);
		printf("//---------------------------------------------------------------------------\n");

		for( Time = 0; Time < sizeof(TIME)/sizeof(int); Time++)
		{
			for( Pre = 1; Pre < sizeof(PRE)/sizeof(int); Pre++)
			{
				MaxCount = (((FCPU[Fcpu] * TIME[Time] ) +  (PRE[Pre] * 500000)) / (PRE[Pre] * 1000000)) - 1;

				if( MaxCount <= 255 )	// Found the closest match.
				{
					fActualTime = (float)1e6*(PRE[Pre] *( MaxCount + 1))/ FCPU[Fcpu];
					iActualTime = fActualTime;

					if( Time == 0)
						printf( "#if TIMER_RESOLUTION == %d\t", iActualTime);
					else
						printf( "#elif TIMER_RESOLUTION == %d", iActualTime);

					printf("\t\t// %7.3fus.\n", TIME[Time], fActualTime);
					printf( "#  define PRESCALER		0x%02X"
							"\t\t// (%d*(1+%d))/ %2.3fMHz.\n", Pre, PRE[Pre], MaxCount, (float)FCPU[Fcpu]/1e6);
					printf( "#  define TIMER_COMPARE	%d\n", MaxCount);
					break;	// Found it.
				}
			}
		}
	}
	return 0;
}

Doing magic with a USD 7 Logic Analyser: https://www.avrfreaks.net/comment/2421756#comment-2421756

Bunch of old projects with AVR's: http://www.hoevendesign.com

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

One surprise actually is Arduino's choice of 16MHz. Never really understand why it was not "baud rate friendly" ?

 

Paulvdh wrote:
It's legacy. The whole arduino movement was started by some students which did not know what they were doing.

And then there's that stupid spacing on the "shield" connectors ...

 

angry

 

The other question is: How did we get stuck with crasy numbers for baud rates in the first place?

Probably came from the old dial-up modem bit rates ?

 

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Wasn't the ASR33 a 300 baud device? Everything since seems to be a multiple of that. I guess the question is what made 300 the obvious choice there?

 

EDIT well OK, scratch that theory because it was 110 baud. (I bought one once at a jumble sale, think it was 50p)

Last Edited: Sat. Mar 3, 2018 - 12:55 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
I guess the question is what made 300 the obvious choice there?

I guess it's down to the modulation technique, and the limitations of the good ol' copper phone line ?

 

probably rounded to a "convenient" number ?

 

EDIT

 

There was also 75 baud, wasn't there?

 

And some standards are "asymmetric" - with different Tx and Rx

 

The doubling doesn't quite work all the time; eg, 14400

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
Last Edited: Sat. Mar 3, 2018 - 01:47 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:
I guess the question is what made 300 the obvious choice there?
Common teletyper baud rates were 50, 75, and 100. The smallest common multiple of them is 300.

Stefan Ernst

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
Mhz Baud_Rate UBRRn Integer UBRRn Safely within 2%
16,000,000 1200 832.3333 832
16,000,000 2400 415.1667 415
16,000,000 4800 207.3333 207
16,000,000 9600 103.1667 103
16,000,000 14400 68.4444 68
16,000,000 19200 51.0833 51
16,000,000 38400 25.0416 25
16,000,000 57600 16.3611 13
16,000,000 115200 7.6805 7   No  ~08%
16,000,000 128000 6.8125 6   No  ~11%
16,000,000 25600 2.90625 2   No  ~31%

 

 

 

 

One last question on the Uart. Sorry, I know this isn't the right section

but since we have been discussing it here, I thought it would be ok.

 

This code is from a You-Tube video "Learning AVR-C Episode 10: Serial Communication (TX)"

#define F_CPU 16000000
#define BAUD 9600
#define UBRRn ((F_CPU/16/BAUD)-1)

This line:

#define UBRRn ((F_CPU/16/BAUD)-1)

Returns an integer?

If so my table is correct?

 

But what about the Baud rate of 115200? it appears to not be within 2%. But David

said 115200 was ok with 16_000_000MHz?

 

Does that mean there is a larger acceptable range of error for tx only? or tx & rx?

 

Is the range of error the reason why other micros have acceptable tx and rx capabilities

for serial debug programs? (screen), without using a "magic" frequency crystal?

 

 

Bill M.

 

david.prentice wrote:

Maths is a lot easier with 8MHz or 16MHz.
115200 baud is ok with 16MHz but not with 8MHz.
.
UART comms only needs 2% accuracy.
Many clones have proper 16MHz crystals. Which gives both accuracy and Serial comms.
.
David.

Last Edited: Sun. Mar 4, 2018 - 12:34 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am impressed that you have done the maths and created your table.
It would have been easier to just read the datasheet. It explains U2X and gives a "more useful" table.
.
In practice, you need U2X for 9600 baud @ 1Mhz and for 115200 baud @ 16Mhz.
.
The USART samples the signals either 16x or 8x. 16x is necessary for a noisy signal from phone or radio. Not very necessary for your hard-wired PC link. Not even for your GPS module because the intelligent GPS has done its own error correction before sending a "perfect" UART comms signal.
.
David.

Last Edited: Sun. Mar 4, 2018 - 06:54 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

<util/setbaud.h>

 

(Just saying ;-)