Society of Robots - Robot Forum

Electronics => Electronics => Topic started by: airman00 on September 22, 2008, 08:19:04 PM

Title: ATmega8 Fuses and UART
Post by: airman00 on September 22, 2008, 08:19:04 PM
Hello,

I am trying to follow through this tutorial ( intended for the ATmega168)http://www.societyofrobots.com/microcontroller_uart_50_robot.shtml

My issue lies in the fuse settings. I am supposed to set the following fuses : (http://www.societyofrobots.com/images/microcontroller_uart_clock_settings.png)

However in AVRstudio when I need to select fuses I get totally different choice for fuses.

(http://i273.photobucket.com/albums/jj202/erobot/Misc%20Documentation/fuses.jpg)

The ATmega8 should be running at 8mhz internal oscillator.

Can someone please guide me to a solution to this fuses issue.

Thanks,
Eric
Title: Re: ATmega8 Fuses and UART
Post by: pomprocker on September 22, 2008, 10:55:36 PM
Every atmega has different fuses!!
Title: Re: ATmega8 Fuses and UART
Post by: airman00 on September 23, 2008, 07:25:36 AM
Every atmega has different fuses!!

Yea I know that , I mean what would I do with the CKDIV8 fuse , whats the same type of fuse on the ATMega8

Would I have to run the ATmega8 at a lower speed and therefore use a lower baud?
Title: Re: ATmega8 Fuses and UART
Post by: pomprocker on September 23, 2008, 10:04:06 AM
atmega8 doesnt have a ckdiv8 fuse

does baud really have anything to do with clock speed?
Title: Re: ATmega8 Fuses and UART
Post by: airman00 on September 23, 2008, 10:29:45 AM
atmega8 doesnt have a ckdiv8 fuse

does baud really have anything to do with clock speed?

yes it effects error rate
(http://www.societyofrobots.com/images/microcontroller_uart_error.gif)
Title: Re: ATmega8 Fuses and UART
Post by: Webbot on September 23, 2008, 12:36:38 PM
The fuses set in your screen shot are correct.

SUT_CKSEL is set to use the internal clock at 8MHz.
Title: Re: ATmega8 Fuses and UART
Post by: pomprocker on September 23, 2008, 01:11:50 PM
Can you even do UART at 1MHz on the atmega8?
Title: Re: ATmega8 Fuses and UART
Post by: TrickyNekro on September 23, 2008, 01:26:21 PM
Can you even do UART at 1MHz on the atmega8?

That depends on the device you are talking at man... and it's baudrate...
Suppose you have a device with slow baud rate like an el chipo transmitter...
When 1MHz is good...
Usually 10MHz will be too good for any hobby associated comm, If you therefore like to place a bigger crystal like a 20MHz one...
You can get better resolution in many things like PWM, more steps for servos if they handle (which most do however)...
That kinda stuff...
So yep you can even overcloack a micro but in comm expect a greater error...

That's from me...

And airman yup that's the right config!!! cheers!!!
Title: Re: ATmega8 Fuses and UART
Post by: airman00 on September 23, 2008, 04:38:33 PM
thx for the replies guys
(http://i273.photobucket.com/albums/jj202/erobot/Misc%20Documentation/fuses.jpg)

Would I have to check off any other fuses for it to work?
Title: Re: ATmega8 Fuses and UART
Post by: pomprocker on September 23, 2008, 04:53:47 PM
no you dont really even need brown out.

also you may not need the size of your boot sector that big
Title: Re: ATmega8 Fuses and UART
Post by: airman00 on September 23, 2008, 04:57:27 PM
I assume I should check off RSTDISBL  ?
Title: Re: ATmega8 Fuses and UART
Post by: pomprocker on September 23, 2008, 08:08:28 PM
Please note that your AVR needs an external RESET source for the ISP interface to work.
When you program the RSTDISBL fuse you disable the ISP interface at the same time.

To reenable the ISP interface you need to use High Voltage Programming to unprogram the RSTDISBL fuse.
To do this you need an STK500. The procedure and connections for High Voltage Programming is located in the AVR Studio Helpfiles:
AVR Tools on-line help --> STK 500 User's Guide --> Hardware description --> High Voltage Programming.
Title: Re: ATmega8 Fuses and UART
Post by: airman00 on September 23, 2008, 08:15:04 PM
oh ok pomprocker

I have it flash an LED OK @ 8mhz but the UART just doesnt work!

I followed the tutorial perfectly but I just cant get the ATmega8 to transmit  or receive over UART ! Everything is set up exactly how Admin said to do it in the tutorial

Did anyone have the same problems with their UART on the ATmega8?

Thanks,
Eric
Title: Re: ATmega8 Fuses and UART
Post by: pomprocker on September 23, 2008, 08:17:51 PM
oh ok pomprocker

I have it flash an LED OK @ 8mhz but the UART just doesnt work!

I followed the tutorial perfectly but I just cant get the ATmega8 to transmit  or receive over UART ! Everything is set up exactly how Admin said to do it in the tutorial

Did anyone have the same problems with their UART on the ATmega8?

Thanks,
Eric



its most likely the baud rate.

check global.h, makefile, and the baud at which you initiate in your main C file.

make sure you set your BlueSMiRF to the correct baud, and make sure you set the port in windows to the right baud.
Title: Re: ATmega8 Fuses and UART
Post by: airman00 on September 24, 2008, 08:04:42 AM
I think uart.c is the issue
There is no compatibility for the ATmega8 , only ATmega 168.
Anyone know how to make my own compatibility script for the ATmega8?

Code: [Select]
// compatibility with most newer processors
#ifdef UCSRB
#define UCR UCSRB
#endif
// compatibility with old Mega processors
#if defined(UBRR) && !defined(UBRRL)
#define UBRRL UBRR
#endif
// compatibility with megaXX8 processors
#if defined(__AVR_ATmega88__) || \
defined(__AVR_ATmega168__) || \
defined(__AVR_ATmega644__)
#define UDR UDR0
#define UCR UCSR0B
#define RXCIE RXCIE0
#define TXCIE TXCIE0
#define RXC RXC0
#define TXC TXC0
#define RXEN RXEN0
#define TXEN TXEN0
#define UBRRL UBRR0L
#define UBRRH UBRR0H
#define SIG_UART_TRANS SIG_USART_TRANS
#define SIG_UART_RECV SIG_USART_RECV
#define SIG_UART_DATA SIG_USART_DATA
#endif
// compatibility with mega169 processors
#if defined(__AVR_ATmega169__)
#define SIG_UART_TRANS SIG_USART_TRANS
#define SIG_UART_RECV SIG_USART_RECV
#define SIG_UART_DATA SIG_USART_DATA
#endif
// compatibility with dual-uart processors
// (if you need to use both uarts, please use the uart2 library)
#if defined(__AVR_ATmega161__)
#define UDR UDR0
#define UCR UCSR0B
#define UBRRL UBRR0
#define SIG_UART_TRANS SIG_UART0_TRANS
#define SIG_UART_RECV SIG_UART0_RECV
#define SIG_UART_DATA SIG_UART0_DATA
#endif
#if defined(__AVR_ATmega128__)
#ifdef UART_USE_UART1
#define UDR UDR1
#define UCR UCSR1B
#define UBRRL UBRR1L
#define UBRRH UBRR1H
#define SIG_UART_TRANS SIG_UART1_TRANS
#define SIG_UART_RECV SIG_UART1_RECV
#define SIG_UART_DATA SIG_UART1_DATA
#else
#define UDR UDR0
#define UCR UCSR0B
#define UBRRL UBRR0L
#define UBRRH UBRR0H
#define SIG_UART_TRANS SIG_UART0_TRANS
#define SIG_UART_RECV SIG_UART0_RECV
#define SIG_UART_DATA SIG_UART0_DATA
#endif
#endif
Title: Re: ATmega8 Fuses and UART
Post by: pomprocker on September 24, 2008, 09:46:09 AM
I wonder how then I had UART working on my atmega8 for many months before upgrading to the mega168....
Title: Re: ATmega8 Fuses and UART
Post by: airman00 on September 24, 2008, 10:39:33 AM
I wonder how then I had UART working on my atmega8 for many months before upgrading to the mega168....

I guess I was incorrect

hmmmm , what fuses did you set on the ATmega8?  Any other things you can provide me that worked for you?
Title: Re: ATmega8 Fuses and UART
Post by: Webbot on September 24, 2008, 12:15:28 PM
Did anyone have the same problems with their UART on the ATmega8?

I just changed the fuse to use the 8MHz internal clock (like you have done).

I included uart.h

and then in my initialisation routine I initialised the UART as follows

   uartInit();  // initialize the UART (serial port)
   uartSetBaudRate(19200);// set the baud rate of the UART for our debug/reporting output

and then I wrote to it using rprintfChar and rprintfStr.

All worked ok.
Title: Re: ATmega8 Fuses and UART
Post by: airman00 on September 24, 2008, 01:11:54 PM
OK thanks for the input Webbot , I guess its a baud issue. I'll focus on that .
Title: Re: ATmega8 Fuses and UART
Post by: Admin on October 08, 2008, 05:26:59 AM
Was this ever resolved?
Title: Re: ATmega8 Fuses and UART
Post by: airman00 on October 08, 2008, 07:05:28 AM
Was this ever resolved?

nope . I just got some 168's in the mail , so I'm gonna try with those.
Title: Re: ATmega8 Fuses and UART
Post by: Mikael on May 21, 2009, 08:32:53 AM
oh ok pomprocker

I have it flash an LED OK @ 8mhz but the UART just doesnt work!

I followed the tutorial perfectly but I just cant get the ATmega8 to transmit  or receive over UART ! Everything is set up exactly how Admin said to do it in the tutorial

Did anyone have the same problems with their UART on the ATmega8?

Thanks,
Eric


I followed the tutorial perfectly but I just cant get the ATmega8 to transmit  or receive over UART ! Everything is set up exactly how Admin said to do it in the tutorial

I don´t know if it would help but here´s a tip (I had a similar problem like you):
Did you try to setup the baudrate like this example?:

#define BAUDRATE 57600
#define UBRRVAL ((F_CPU/(BAUDRATE*16UL))-1)

UBRRL=(uint8_t)UBRRVAL;      //low byte
UBRRH=(uint8_t)(UBRRVAL>>8);   //high byte   

In that case please instead take help of the clockspeeds/Baudrates/Error Table in the datasheet and do like this example:

#define BAUDRATE 57600
#define UBRRVAL ((F_CPU/(BAUDRATE*16UL))-1)

UBRRL=3;      //low byte
UBRRH=(3/256);   //high byte, downshift 8 times, divide by 2^8

It helped me.
/Mikael

Title: Re: ATmega8 Fuses and UART
Post by: Pierre on January 03, 2010, 04:15:11 PM
I am following through the UART with the ATmega8 on an other post.  It really seems that Airman00 would be wright about the ATmega8 with UART using the photoresistor on the $50 robot.


http://www.societyofrobots.com/robotforum/index.php?topic=9944.0 (http://www.societyofrobots.com/robotforum/index.php?topic=9944.0)