Checking if fuses are correct

I bought my second arduino Uno (clone) as I blew up my last one..
I have had some funny things with it, a progam that worked on my last board does not work on this board..

I dont use the Ardunio Gui and just use WINAVR.. The program just reads and writes to UART.. for some reason when i set it at baud 9600 it only works at baud rate 19200.

My question is, I'm wonding if the fuses arent set right? and the clock is setup wrong or something? How can I read and confirm the fuses are correct? Or Test the speed of the clock?

the code (that doesnt work, unless i double the buad rate on my PC from what it should be) is as follows:

#include <avr/io.h> 
#include <util/delay.h> 
#include <stdlib.h> 
#include <avr/interrupt.h> 
#include <stdlib.h> 

/* UART SERIAL DEFINES */ 
#define BAUD 9600 
#define MYUBRR F_CPU/16/BAUD-1 


/* SETUP UART */ 
void USART_Init( unsigned int ubrr); 

void USART_Interrupt_On(void); 

/* Simple methods to make UART read and transmit more readble - Extremely unnecessary*/ 
void USART_Transmit( unsigned char data ); 

unsigned char USART_Receive( void ); 

void SendString(char *StringPtr); 



 char input[20]; 
 int counter; 



/* SETUP UART */ 
void USART_Init( unsigned int ubrr) 
{ 
   /*Set baud rate */ 
   UBRR0H = (unsigned char)(ubrr>>8); 
   UBRR0L = (unsigned char)ubrr; 
    
  /*Enable receiver and transmitter */ 
   UCSR0B = (1<<RXEN0)|(1<<TXEN0); 
    
   /* Set frame format: 8data, 2stop bit */ 
   UCSR0C = (1<<USBS0)|(3<<UCSZ00); 
} 




/* Simple methods to make UART read and transmit more readble - Extremely unnecessary*/ 
void USART_Transmit( unsigned char data ) 
{ 
   while(!(UCSR0A & (1<<UDRE0))); 
   UDR0 = data; 
} 


unsigned char USART_Receive( void ) 
{ 
   return UDR0; 
} 

void SendString(char *StringPtr) 
{ 
    
   while(*StringPtr != 0x00) 
   {  
   USART_Transmit(*StringPtr);    
   StringPtr++; 
   }        

} 





int main(void) 
{ 

   //Setup Serial 
   USART_Init(MYUBRR);    
    
   while(1) 
   {       
      SendString("this doesnt work!"); 
      _delay_ms(1000); 
   } 
}

You can use avrdude with the -v (verify) option to see what the settings are.

You can set the appropriate fuse which outputs the clock to one of the pins (I don't recall which one) and then test that pin.

Can someone who has a Arudino Uno Post their avrdude -v details.

here is mine:

C:\Users\Michael.PTH>avrdude -v -c arduino -p atmega328p -P com3

avrdude: Version 5.10, compiled on Jan 19 2010 at 10:45:23
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "C:\WinAVR-20100110\bin\avrdude.conf"


         Using Port                    : com3
         Using Programmer              : arduino
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page
      Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  Max W   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     5     4    0 no       1024    4      0  3600  36 00 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  45 00 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  45 00 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  45 00 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  45 00 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  45 00 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0 0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0 0 0x00 0x00

         Programmer Type : Arduino
         Description     : Arduino
         Hardware Version: 3
         Firmware Version: 3.3
         Vtarget         : 0.3 V
         Varef           : 0.3 V
         Oscillator      : 28.800 kHz
         SCK period      : 3.3 us

avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0

avrdude: safemode: lfuse reads as 0
avrdude: safemode: hfuse reads as 0
avrdude: safemode: efuse reads as 0
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

You are barking up the wrong tree. F_CPU has the wrong value for your board.

that was the fist thing I checked.

F_CPU = 16000000 in the make file...

which I thought was correct

Your fuses just don't look right. As in, they aren't being measured. Here are mine:

$ avrdude -c usbtiny -v -p m328p

avrdude: Version 5.8cvs, compiled on Jan 15 2010 at 17:27:01
         Copyright (c) 2000-2005 Brian Dean, http://www.bdmicro.com/
         Copyright (c) 2007-2009 Joerg Wunsch

         System wide configuration file is "/usr/local/CrossPack-AVR-20100115/etc/avrdude.conf"
         User configuration file is "/Users/nick/.avrduderc"
         User configuration file does not exist or is not a regular file, skipping

         Using Port                    : unknown
         Using Programmer              : usbtiny
         AVR Part                      : ATMEGA328P
         Chip Erase delay              : 9000 us
         PAGEL                         : PD7
         BS2                           : PC2
         RESET disposition             : dedicated
         RETRY pulse                   : SCK
         serial program mode           : yes
         parallel program mode         : yes
         Timeout                       : 200
         StabDelay                     : 100
         CmdexeDelay                   : 25
         SyncLoops                     : 32
         ByteDelay                     : 0
         PollIndex                     : 3
         PollValue                     : 0x53
         Memory Detail                 :

                                  Block Poll               Page                       Polled
           Memory Type Mode Delay Size  Indx Paged  Size   Size #Pages MinW  MaxW   ReadBack
           ----------- ---- ----- ----- ---- ------ ------ ---- ------ ----- ----- ---------
           eeprom        65     5     4    0 no       1024    4      0  3600  3600 0xff 0xff
           flash         65     6   128    0 yes     32768  128    256  4500  4500 0xff 0xff
           lfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           hfuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           efuse          0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           lock           0     0     0    0 no          1    0      0  4500  4500 0x00 0x00
           calibration    0     0     0    0 no          1    0      0     0     0 0x00 0x00
           signature      0     0     0    0 no          3    0      0     0     0 0x00 0x00

         Programmer Type : USBtiny
         Description     : USBtiny simple USB programmer, http://www.ladyada.net/make/usbtinyisp/
avrdude: programmer operation not supported

avrdude: Using SCK period of 10 usec
avrdude: AVR device initialized and ready to accept instructions

Reading | ################################################## | 100% 0.01s

avrdude: Device signature = 0x1e950f
avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as D6
avrdude: safemode: efuse reads as 5

avrdude: safemode: lfuse reads as FF
avrdude: safemode: hfuse reads as D6
avrdude: safemode: efuse reads as 5
avrdude: safemode: Fuses OK

avrdude done.  Thank you.

Note the different version of avrdude.

stowaway:
Can someone who has a Arudino Uno Post their avrdude -v details.

C:\Users\Michael.PTH>avrdude -v -c arduino -p atmega328p -P com3

The bootloader reports zero for the fuses. You will have to use a programmer.

ok thanks guys, i didnt realise i'd have to use a differnet programmer.

ill put it in my USBasp and test it tonight :wink:

I havent had a chance to check the fuses in a programmer yet.. However I did a simple blink LED test wiht a delay,
The delay should be (i though) 10seconds.. however its closer to 6.5 seconds!! can anyone explain whats going on?

Code:

#include <avr/io.h> 
#include <util/delay.h> 
int main(void) 

{ 
   DDRB = (1 << PB5); 
    
   PORTB = (1 << PB5); 
    
   while (1) 
   { 
    
   PORTB ^= (1 << PB5); 
   _delay_ms(10000); 
  
   }

MakeFile: (deleted half to fit max character limit)

# Hey Emacs, this is a -*- makefile -*- 
#---------------------------------------------------------------------------- 
# WinAVR Makefile Template written by Eric B. Weddington, Jörg Wunsch, et al. 
# 
# Released to the Public Domain 
# 
# Additional material for this makefile was written by: 
# Peter Fleury 
# Tim Henigan 
# Colin O'Flynn 
# Reiner Patommel 
# Markus Pfaff 
# Sander Pool 
# Frederik Rouleau 
# Carlos Lamas 
# 
#---------------------------------------------------------------------------- 
# On command line: 
# 
# make all = Make software. 
# 
# make clean = Clean out built project files. 
# 
# make coff = Convert ELF to AVR COFF. 
# 
# make extcoff = Convert ELF to AVR Extended COFF. 
# 
# make program = Download the hex file to the device, using avrdude. 
#                Please customize the avrdude settings below first! 
# 
# make debug = Start either simulavr or avarice as specified for debugging, 
#              with avr-gdb or avr-insight as the front end for debugging. 
# 
# make filename.s = Just compile filename.c into the assembler code only. 
# 
# make filename.i = Create a preprocessed source file for use in submitting 
#                   bug reports to the GCC project. 
# 
# To rebuild project do "make clean" then "make all". 
#---------------------------------------------------------------------------- 


# MCU name 
MCU = atmega328p 


# Processor frequency. 
#     This will define a symbol, F_CPU, in all source code files equal to the 
#     processor frequency. You can then use this symbol in your source code to 
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done 
#     automatically to create a 32-bit value in your source code. 
#     Typical values are: 
#         F_CPU =  1000000 
#         F_CPU =  1843200 
#         F_CPU =  2000000 
#         F_CPU =  3686400 
#         F_CPU =  4000000 
#         F_CPU =  7372800 
#         F_CPU =  8000000 
#         F_CPU = 11059200 
#         F_CPU = 14745600 
#         F_CPU = 16000000 
#         F_CPU = 18432000 
#         F_CPU = 20000000 
F_CPU = 16000000 


# Output format. (can be srec, ihex, binary) 
FORMAT = ihex 


# Target file name (without extension). 
TARGET = main 


# Object files directory 
#     To put object files in current directory, use a dot (.), do NOT make 
#     this an empty or blank macro! 
OBJDIR = . 


# List C source files here. (C dependencies are automatically generated.) 
SRC = $(TARGET).c ATMega328_SPI_MASTER.c ATMega328_SERIAL.c

Well I just read the comments above the _delay_ms function (in delay.h):

   When the user request delay which exceed the maximum possible one,
   _delay_ms() provides a decreased resolution functionality. In this
   mode _delay_ms() will work with a resolution of 1/10 ms, providing
   delays up to 6.5535 seconds (independent from CPU frequency).  The
   user will not be informed about decreased resolution.

Note the reference to 6.5535 seconds. :slight_smile:

Yep,

you are right. I changed it to 5second delay and its right on the money.

My problem must originate elsewhere.

stowaway:
I bought my second arduino Uno (clone) as I blew up my last one..

Which bootloader is installed?

I'm not sure? would this effect the UART?

Possibly. Optiboot resets the processor (using the Watchdog); you can assume the registers are set to power-up values. I believe previous bootloaders did not reset the processor. Were I in your shoes I would make certain all the USART registers are set to known values (e.g. UCSR0A).