Go Down

Topic: Standard Fuse Settings for 16Mhz ATMega328p (Read 133950 times) previous topic - next topic

clivemist




So do delay() calls in sketches you upload delay for the correct amount of time or not?



If you mean in a main body of code, they are not, also my baud is mismatching again..


Do they take too long? or not enough time? By what factor are they wrong?



Sorry, I tried that again.

A delay(1000) posts roughly every second. The baud is mismatched..

dc42

Is the baud rate mismatched only when you are uploading a program through the bootloader, or it is also mismatched when you do a Serial.begin followed by a Serial.print ?
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

clivemist

My head is spinning a little so please excuse me if I have missunderstood you here, but..

This is the sketch I am using:

--------------------------------------------
void setup()                   
{
  Serial.begin(300);         

void loop()                       
{
  Serial.println("Hello world!"); 
  delay(1000);
}
--------------------------------------------

When I bring up the serial monitor it posts at baud 2400 every second.

dc42

In summary:

1. Delay calls execute in the correct amount of time. So the clock is almost certainly running at the right speed.

2. To communicate with the serial port of the device, you have to set the PC to a baud rate 8x higher than the device is supposedly set to.

Therefore, either the PC software is at fault and is running at a baud rate 8x lower than you ask for, or the UART in your 328p-au is running at a baud rate 8x higher than you ask for. Can you connect to a standard Arduino at 2400 baud using the same board setting, to verify that the PC software is operating correctly?

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

dc42

I've just tried to communicate with my Arduino Uno at 300 baud, and it doesn't work. It works at higher baud rates. Maybe a bug in the Arduino software? Try a higher baud rate.

You might also like to upload the following sketch to see what the UART baud rate divisor is set to:

Code: [Select]

void setup()
{
  Serial.begin(2400);
}

void loop()
{
  Serial.print((int)UBRR0H, HEX);
  Serial.write(',');
  Serial.print((int)UBRR0L, HEX);
  Serial.write(',');
  Serial.println((int)UCSR0A, HEX);
  delay(1000);
}
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

clivemist

I tried changing my port settings, this seemed to make no difference regardless of what I set the baud to..

I uploaded the sketch you kindly put up.

I had to change the begin from (2400) to (14400) as there was no option for x8 baud in the serial monitor.

This is what I got back:

"0, 8A, 2
0, 8A, 42
0, 8A, 42
0, 8A, 42
0, 8A, 42..." (repeats)

Until I hit reset and then it repeats from "0, 8A, 2".


All possible serials that are readable by IDE (serial x8):

14400 / serial 115200:

"0, 8A, 2
0, 8A, 42
0, 8A, 42
0, 8A, 42.."


4800 / serial 38400:

"1, A0, 2
1, A0, 42
1, A0, 42
1, A0, 42.."


2400 / serial 19200:

"3, 40, 2
3, 40, 42
3, 40, 42
3, 40, 42.."


1200 / serial 9600:

"6, 82, 2
6, 82, 42
6, 82, 42
6, 82, 42.."


and finally
300 / serial 2400:

"D, 4, 0
D, 4, 40
D, 4, 40
D, 4, 40.."



dc42

Can you remind me what you have connected between the microcontroller TxData pin and the PC?

The bad rate divisors from your data look OK to me. I'm wondering whether the USART is operating in synchronous master mode instead of asynch mode - that could explain the x8 speed. Try this sketch, which reads back all the USTAT control registers:

Code: [Select]

void setup()
{
}

void loop()
{
  Serial.begin(2400);
  byte ubrr0h = UBRR0H;
  byte ubrr0l = UBRR0L;
  byte ucsr0a = UCSR0A;
  byte ucsr0b = UCSR0B;
  byte ucsr0c = UCSR0C;
 
  //Serial.begin(2400);
  Serial.print((unsigned int)ubrr0h, HEX);
  Serial.write(',');
  Serial.print((unsigned int)ubrr0l, HEX);
  Serial.write(',');
  Serial.print((unsigned int)ucsr0a, HEX);
  Serial.write(',');
  Serial.print((unsigned int)ucsr0b, HEX);
  Serial.write(',');
  Serial.println((unsigned int)ucsr0c, HEX);
  delay(1000);
}


At 2400 baud I get: 3,40,62,98,6.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

clivemist

Running the low fuse CLKDIV8 (0x77) posts at the selected baud but 8x slower, as expected..

I get back:

Serial(S)/Result(R):

S:300
R:??" ?|? "
(All other bauds are similar garbage)

S:1200
R:"6, 82, 2
   6, 82, 42.."

S:2400
R:"3, 40, 2
   3, 40, 42.."

S:4800
R:"1, A0, 2
   1, A0, 42.."

S:9600
R:"0, CF, 2
   0, CF, 42.."

S:14400
R:",` @¢ü,` Pm ,` Pm "
(All other bauds are similar garbage)

S:19200
R:"0, 67, 2
   0, 67, 42.."

S:28800
R:"¸øó¸¸h¸¸h"
(All other bauds are similar garbage)

S:38400
R:"0, 33, 2
   0, 33, 42.."

S:57600
R:"0, 10, 0
   0, 10, 40.."

S:115200
R:"0, 10, 2
   0, 10, 42.."


The Delay(1000) is now running posts at roughly 8 seconds (which I gather is expected?).
I hope this helps in some way.

I was just reading up on these commands and from what I gather they are to do with the Usart.
In terms of design, could noise from the crystal or other sources cause this issue, or is my design safe in terms of the mechanics?
IE is this a definite IC issue..
Could this be caused by the IC overheating, or is it something software orientated?

I'm just wondering as if my design is stable, at least I can move on from the actual design of the PCB itself, and start to focus on changing over IC's etc instead of having to knock up board after board trying new things..

clivemist


Can you remind me what you have connected between the microcontroller TxData pin and the PC?

The bad rate divisors from your data look OK to me. I'm wondering whether the USART is operating in synchronous master mode instead of asynch mode - that could explain the x8 speed. Try this sketch, which reads back all the USTAT control registers:

Code: [Select]

void setup()
{
}

void loop()
{
  Serial.begin(2400);
  byte ubrr0h = UBRR0H;
  byte ubrr0l = UBRR0L;
  byte ucsr0a = UCSR0A;
  byte ucsr0b = UCSR0B;
  byte ucsr0c = UCSR0C;
 
  //Serial.begin(2400);
  Serial.print((unsigned int)ubrr0h, HEX);
  Serial.write(',');
  Serial.print((unsigned int)ubrr0l, HEX);
  Serial.write(',');
  Serial.print((unsigned int)ucsr0a, HEX);
  Serial.write(',');
  Serial.print((unsigned int)ucsr0b, HEX);
  Serial.write(',');
  Serial.println((unsigned int)ucsr0c, HEX);
  delay(1000);
}


At 2400 baud I get: 3,40,62,98,6.




Upon changing the fuses back to default:

I get: 3,40,62,98,6.
So that checks out!

I am using an ATMEGA8u2-AU for Tx/Rx..

dc42

The programming on the atmega328p looks OK, and if delay calls are taking the right amount of time then the clock speed is correct. So my best guess it that it's something to do with the 8u2 programming, or the PC device driver, or a mismatch between the two. I think the PC sends a code to the 8u2 to tell it what baud rate to use, but maybe the meanings assigned to the codes in the 8u2 software are not the same as the ones used in the PC driver.
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

clivemist

I had a feeling there might be a problem between the PC and 8U2..

At least I'm not going nuts..

Basically the firmware I use for my R3 16u2 works for DFU over USB.
As far as I understand there is no difference between the 8u2 and -au?

I had wondered before if I would need to burn the fuses on the 8u2 but believed it to be able to work straight 'out of the box'. (This is the first time I have got this far..)

Is there a way of buring the fuses via USB, or will I need to ISP?

dc42

I've just looked at the default settings for the 8u2 fuses in http://www.engbedded.com/fusecalc and it appears that it defaults to dividing the clock frequency by 8, just like the atmega328p. This explains why you need to set the PC to 8x the actual baud rate. I suggest you read the 8u2 datasheet to confirm this.

Unless you have put any bootloading code on the 8u2, you will need to program it via ICSP. How did you program it in the first place?
Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

clivemist

Ah.. I didnt..

Also I havent included a header in this design, I had messed up another part anyway, so just as well!

For now I will get this sorted, and hopefully it wil all lock in.

Fantastic, thanks for the help!

JohnnyFyve

I have an Arduino Uno. Using PROGISP I think I accidentally overwrote the fuse settings to 0xD9E1, this thread says it should be set to 0x5DEFF. My Arduino was running blink code and it still is, but with the new clock its really slow, probably 10x slower. Unfortunately I can't just reset the fuse back to 0x5DEFF, PROGISP says it "Chip Enable Program Error." Arduino IDE gives
Code: [Select]
avrdude: stk500_getsync(): not in sync: resp=0x00
whenever I try to upload anything. Any suggestions on how to fix this? Did I brick my Arduino?

CrossRoads

Reburn the bootloader from the IDE using an AVR ISP Programmer. That should reset the fuses.
If you can't, then it's time for a new chip.


Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

Go Up