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.

Setting prescaler for 8MHz external oscillator in Atmega2560

Status
Not open for further replies.

chandlerbing65nm

Member level 5
Member level 5
Joined
Apr 5, 2018
Messages
80
Helped
0
Reputation
0
Reaction score
1
Trophy points
8
Activity points
709
I am relatively new in Atmega MCU's (too used with graphical interfaces). I am using an external clock with 8MHz in my Atmega2560. My problem is that I cannot use UART communication with PIC18->Atmega2560 and STM32F4->Atmega2560 (no acknowledgements).

I thought that it is my baud rate that is not right, maybe the Atmgea2560 is using prescaler div by 8 in default (not familiar with Atmega). So, I forcely changed the prescaler to div by 1 using this little code:

Code:
void setup() {

  noInterrupts();
  CLKPR = 0x80; /*Enabling the clock prescaler function*/
  CLKPR = 0x00; /*Setting the prescaler to div by 1*/
  interrupts();
}

I also use this one in the bootloading/programming:
Code:
2560.menu.clock.8MHz_external=External 8 MHz
2560.menu.clock.8MHz_external.upload.speed=57600
2560.menu.clock.8MHz_external.bootloader.low_fuses=0xf7
2560.menu.clock.8MHz_external.build.clkpr=
2560.menu.clock.8MHz_external.build.clock_speed={build.f_cpu}
2560.menu.clock.8MHz_external.build.f_cpu=8000000L


Now, when setting the Atmega2560 Serial, Serial1, Serial2, and Serial3 to 9600 baud rate and PIC18/STM32F4 to 9600 baud rate, can my problem in UART be vanished (ack's will receive)? -theoretically

I cannot verify it now since it is weekend, things are in the office.

To those who are expert in this things, your help is much appreciated.

Regards, Tim
 

Hi,

The ATMega comes with a datasheet. It is for free.
Read it. There isva UART chapter.
There are tabke with UART baudrates vs clock frequencies.
In addition there is a formula.

Klaus
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top