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.

ATMega8L external crystal problem?

Status
Not open for further replies.

m007moobond

Newbie level 3
Joined
Jul 18, 2011
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,435
Hi there,

I was working with the atmega8L micro-controller using the internal oscillator 1MHz and baud rate of 2500, but now I would like to use an external crystal 8MHz "or higher either up to 20MH" with baud rate 9600. I use the AVR Studio v4.18 to write my code and I have the Genius G840 programmer I use to burn the .hex file to the micro-controller using the G840 software. the only problem is that I don't know how to set the fuses with this prgrammer, I know the UBRRL = 0xFD and UBRRH = 0xD9 values from Engbedded AVR Fuse Calculator by selecting the Ext. Crystal/Resonator Medium Freq.; Start-up time 16K CK +64 ms; [CKSEL=1101 SUT=11] from the drop down menu. So can you help me set the fuses using the Genius G840 programmer.

/*--------Begining of Code-------------------------*/
#define FOSC 8000000// Clock Speed
#define BAUD 9600
#define MYUBRR ((FOSC/(16*BAUD))-1)

/* We must always include *.h in our protothreads code. */
#include <avr/io.h>
//#include <util/delay.h>
#include <avr/eeprom.h>

/*----------------------------------------------------------------
-----------------FUNCTIONS DECLARATION----------------------------
-----------------------------------------------------------------*/
void InitUART( unsigned char baudrate );
void TransmitByte( unsigned char data );
//void Init_Ports(void);
char isCharAvailable(void);
char receiveChar(void);
//void send_sds1(struct button B);
void PowerLed(void);

/*----------------------------------------------------------------
-----------------MAIN FUNCTION------------------------------------
-----------------------------------------------------------------*/
int count=0;
char string[225];
int loop;


int main()
{

InitUART(MYUBRR); //MYUBRR = 51 /* Set the baudrate to 9600 bps using a 8MHz internal oscillator */

TransmitByte('A');
TransmitByte('T');
PowerLed();

for(;;) /* Forever */
{
while(isCharAvailable() == 1)
{
// If a new character is received, get it
string[count] = receiveChar();
count++;
TransmitByte(string);
}
}
}

/*----------------------------------------------------------------
------------FUNCTIONS TO Initialize UART--------------------------
-----------------------------------------------------------------*/

void InitUART( unsigned char ubrr )//unsigned char baudrate )
{

/* Set baud rate */
UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;

UCSRB = (UCSRB | _BV(RXEN) | _BV(TXEN) ); /* Enable UART receiver and transmitter */
}

/*----------------------------------------------------------------
------------FUNCTIONS TO READ UART-------------------------------
-----------------------------------------------------------------*/
char receiveChar()
{
return UDR;/* Return the data */
}

char isCharAvailable()
{
// indicate a char has been received?
if ( (UCSRA & (0x80)) ) return 1;
else return 0;
}

/*----------------------------------------------------------------
------------FUNCTIONS TO WRITE UART-------------------------------
-----------------------------------------------------------------*/

void TransmitByte( unsigned char data )
{
while ( !(UCSRA & (_BV(UDRE))) ); /* Wait for empty transmit buffer */
UDR = data; /* Start transmittion */
}

/*----------------------------------------------------------------
------------FUNCTIONS TO Power On LED-----------------------------
-----------------------------------------------------------------*/
void PowerLed(void)
{
// enable PC1 as power LED
DDRC |= (1<<PC1);

// PIN1 PORTC set -> LED on
PORTC |= (1 << PC1);
}
/*--------End of code--------------------------*/
Another issue "for another project" is that I have another micro-controller atmega8L that I want to use it's internal oscillator of 8MHz with baud rate 9600 in the UART but when I program it and test it nothing is coming out of the TX and nothing is going into the RX even though I enabled the TX and RX in the code and I doubled checked the hyperterminal setting with baud rate 9600, databit 8, parity none, stop bit 1, and flow control none. The power LED works fine though, any idea what could be the problem:

/*--------Begining of Code-------------------------*/
#define FOSC 8000000// Clock Speed
#define BAUD 9600
#define MYUBRR ((FOSC/(16*BAUD))-1)

/* We must always include *.h in our protothreads code. */
#include <avr/io.h>
//#include <util/delay.h>
#include <avr/eeprom.h>

/*----------------------------------------------------------------
-----------------FUNCTIONS DECLARATION----------------------------
-----------------------------------------------------------------*/
void InitUART( unsigned char baudrate );
void TransmitByte( unsigned char data );
//void Init_Ports(void);
char isCharAvailable(void);
char receiveChar(void);
//void send_sds1(struct button B);
void PowerLed(void);

/*----------------------------------------------------------------
-----------------MAIN FUNCTION------------------------------------
-----------------------------------------------------------------*/
int count=0;
char string[225];
int loop;


int main()
{

InitUART(MYUBRR); //MYUBRR = 51 /* Set the baudrate to 9600 bps using a 8MHz internal oscillator */

TransmitByte('A');
TransmitByte('T');
PowerLed();

for(;;) /* Forever */
{
while(isCharAvailable() == 1)
{
// If a new character is received, get it
string[count] = receiveChar();
count++;
TransmitByte(string);
}
}
}

/*----------------------------------------------------------------
------------FUNCTIONS TO Initialize UART--------------------------
-----------------------------------------------------------------*/

void InitUART( unsigned char ubrr )//unsigned char baudrate )
{

/* Set baud rate */
UBRRH = (unsigned char)(ubrr>>8);
UBRRL = (unsigned char)ubrr;

UCSRB = (UCSRB | _BV(RXEN) | _BV(TXEN) ); /* Enable UART receiver and transmitter */
}

/*----------------------------------------------------------------
------------FUNCTIONS TO READ UART-------------------------------
-----------------------------------------------------------------*/
char receiveChar()
{
return UDR;/* Return the data */
}

char isCharAvailable()
{
// indicate a char has been received?
if ( (UCSRA & (0x80)) ) return 1;
else return 0;
}

/*----------------------------------------------------------------
------------FUNCTIONS TO WRITE UART-------------------------------
-----------------------------------------------------------------*/

void TransmitByte( unsigned char data )
{
while ( !(UCSRA & (_BV(UDRE))) ); /* Wait for empty transmit buffer */
UDR = data; /* Start transmittion */
}

/*----------------------------------------------------------------
------------FUNCTIONS TO Power On LED-----------------------------
-----------------------------------------------------------------*/
void PowerLed(void)
{
// enable PC1 as power LED
DDRC |= (1<<PC1);

// PIN1 PORTC set -> LED on
PORTC |= (1 << PC1);
}

/*--------End of code--------------------------*/


Thanks in advance for your help, looking forward for your replies :)
 

you could not use 20MHz External X. You could use up to 16MHz Xtall...
 

you could not use 20MHz External X. You could use up to 16MHz Xtall...

Thanks for your reply,

no problem, it's just that I had a 20MHz crystal lying around and after I checked the datasheet I though I could use it. But I have no problem NOT using the 20MHz, what I want to do is to speed it up a little bit that's why I want to use an external crystal...any idea on how to set the fuses using the genius G840 programmer, and just a reminder I'm using the AVR Studio v4.18 to write my .c code and I use the G840 programmer to burn the .hex file to the micro-controller
 

m007moobond said:
what I want to do is to speed it up a little bit that's why I want to use an external crystal...

Read datasheet carefully. Since you are using ATmega8L, the 8MHz is the best you can get. Read the manual page1 to the down side, see for "Speed Grades".
 

Dear ALERTLINK,

I went to this website and I know the fuse low and high values "0xFD and 0xD9 respectively", the only problem is that I'm using the Genius G840 programmer to burn the .hex file to the micro-controller and I don't know how to set the fuses using the G840 software, do u have any idea on how to set the fuses

thanks in advance :)

---------- Post added at 10:14 ---------- Previous post was at 10:05 ----------

Dear alexxx,

Thanks for your reply, I read the datasheet and I edited my code so it can work on the internal 8MHz oscillator with baud rate 9600 but for some reason nothing is coming out of TX or RX even though I enabled them in the code and made sure I have the right setting in the hyper terminal...any idea what the problem could be.

Also I'm trying to use an external 8MHz crystal for another project but I don't know how to set the fuse using the Genius G840 programmer that I use to burn the .hex file to the micro-controller, I know the fuse low and fuse high values "0xFD and 0xD9" any idea how I can set fuses using the G840 programmer..

thanks in advance...
 

Set the "config Setting" in the G840 software for 8MHz while programming your IC.

---------- Post added at 14:47 ---------- Previous post was at 14:44 ----------

Follow Fuse settings in G840 Software "Config Setting"
CKSEL0 = Checked
CKSEL1 = Checked
CKSEL2 = Unchecked
CKSEL3 = Checked
 

You post screenshot of config setting page of G840 software. Actually i have also got genius programmer but it is G540. I am posting from mine. Most likely yours may be similar. Advance members may comment more precisely.


Default settings. How to change various parameters accordingly?
There are overclockers reaching the limits.
 
Last edited:

You post screenshot of config setting page of G840 software. Actually i have also got genius programmer but it is G540. I am posting from mine. Most likely yours may be similar. Advance members may comment more precisely.


Settings on the attached snapshot are for 1MHz crystal not for 8MHz. for reference a snapshot is being attached for 8MHz.

View attachment crystel.bmp
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top