Hi Freaks,
I am trying to make the USART on my M48 work with the STK500. I have already tried this with the M16 with STK500 and it has worked. However, it has been a while and do not remember the clock settings.
I am using Dean's basic code to make it work with the STK500. Here it is:
#include#define USART_BAUDRATE 9600 #define BAUD_PRESCALE (((8000000/ (USART_BAUDRATE * 16UL))) - 1) //value to load into UBRR void USART0_init() { UCSR0B |= (1 << RXEN0) | (1 << TXEN0); // Turn on the transmission and reception circuitry UCSR0C |= (1 << UCSZ01) | (1 << UCSZ00); //Set to 8 bit no parity, 1 stop bit UBRR0L = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register UBRR0H = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register } int main (void) { char ReceivedByte; USART0_init(); for(;;) { while((UCSR0A & (1 << RXC0)) == 0) {}; ReceivedByte = UDR0; while((UCSR0A & (1 << UDRE0)) == 0){}; UDR0 = ReceivedByte; } }
I am pretty sure it is a clock selection issue on the STK500. Now when I connect my STK500 from the RS232 CTRL port to AVRStudio, I get the following options:
Ext Clock Internal RC Osc. 8MHz Internal RC osc. 128kHz External low freq.Crystal External full swing crystal External crystal oscillator 0.4 - 0.9 MHz External crystal oscillator 0.4 - 3 MHz External crystal oscillator 3.0 - 8.0 MHz External crystal oscillator 8.0 - MHz
Also the CLKDIV8 fuse in my AVRStudio programmer settings is checked.
Reading the STK500 manual tells me:
When the XTAL1 jumper is mounted, the STK500 internal clock system is used as main clock to the target AVR. The internal clock system can either use a crystal in the on-board crystal socket, or a software generated clock from the master MCU. The frequency of the software generated clock can be set from 0 to 3.68Mhz. The default value is 3.68Mhz. Section "Oscillator" explains how to set the clock frequency from AVR Studio. When using the STK500 software generated clock system as main clock, the target AVR microcontroller fuses should be configured for "external clock" as clock source. This gives shortest start-up time for the microcontroller. For details of start-up time, see the datasheet for the AVR microcontroller. Explanation of clock source fuses configuration, see "Fuse settings". Not all AVR devices have fuses for selection between using a crystal or oscillator as clock source.
So can I insert my 8MHz crystal into the crystal socket on the STK500 and select the "External crystal oscillator 3.0 - 8.0 MHz" in AVRStudio?
Thanks.
edit: What I can't understand is how this worked with an M16. I did not use any external crystal, I had the default settings on my STK500.