Forum: µC & Digital Electronics rs232 or usb

von guest (Guest)

Attached files:

Rate this post
0 useful
not useful

I am a novice in the microcontroller and i have since one Week a 

I engraved this code below on mysmatcontrolM8 (s. picture).
But, i obtain only weird character although it is working property on 
STK500 with atmega8.

I have already verified the frequenz, the Baud Rate and all are OK.

However, i obtain only weird character

I viewed the mysmartcontrolM8 product description: power supply via USB 
connection, 5 V or 3.3 V.
I think, that maybe the failing is the diference between the power 
supply of my PC and mysmatcontrolM8 (atmega8) !!! is that right!?!  And 
please which transformer  can i use?

Or, where is my fault!?!
can somebody help me!!!

thank you

#ifndef F_CPU
/* In the new version of the WinAVR/Mfile Makefile guideline One can defined F_CPU in the Makefile, a repeated 
   definition here would lead to a compiler warning . therefore "prevention" through    #ifndef/#endif

   This "Prevention" can lead to Debugger, if AVRStudio use a another, not the hardware fitting Clock rate: 
   Then the    following definition doesn't use, but instead the default value (1 MHz?) of AVRStudio - hence 
   the Output of a warning if F_CPU yet does not define:*/ 
#warning "F_CPU was not defined yet, now make up with 3686400"
#define F_CPU 3686400L // Systemtakt in Hz - define as  long>> Without errors in the computation 

#define BAUD 9600L
#define UBRR_VAL ((F_CPU+BAUD * 8)/(BAUD*16)-1)     //clever round
#define BAUD_REAL (F_CPU/(16*(UBRR_VAL+1)))         //real baud rate
#define BAUD_ERROR ((BAUD_REAL*1000)/BAUD-1000)     //Error per thousand

#if ((BAUD_ERROR>10)||(BAUD_ERROR<-10))
#error Systematic error in the baud rate more than 1% and thus too high!

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

void USART_Init(void) 
  UBRRH = (unsigned char)(UBRR_VAL>>8);  // Set baud rate
  UBRRL = (unsigned char)UBRR_VAL;
  UCSRB |= (1<<RXEN)|(1<<TXEN);    // Enable receiver and transmitter
  UCSRC = (1<<URSEL) | (1<<UCSZ0)|(1<<UCSZ1);  // Set frame format: 8data, 1stop bit        

}//end USART_Init()

void USART_Putc(unsigned char c)
  while (!(UCSRA & (1<<UDRE))); // Do nothing until data have been transmited 
  UDR = c;                // Put data into Buffer, sends the data
}//end USART_Putc()

void USART_Puts (char *string)
    while( *string != '\0' )  //as long as *string != '\0' so unlike the "stringer end-character"
}//end USART_Puts()

int main(void) 
    USART_Puts("Hey !!!!");  

   return 0;                     
} //end main()

von H.C. (Guest)

Rate this post
0 useful
not useful
How did you connect the board to your PC?  I wonder about the physical 

The reason why I'm asking is: I miss to see some kind of level converter 
on the board (which doesn't necessarily mean it's not there).

von guest (Guest)

Rate this post
0 useful
not useful
thank you for your interrest.

I have connected on PC over the USB interface, which provides a virtual
COM3-Port to the PC.


von H.C. (Guest)

Rate this post
0 useful
not useful
I see.  I assume you've made sure the baudrate is correct at 9600?  If 
so, I'm running out of ideas.

von Andreas S. (andreas) (Admin) Flattr this

Rate this post
0 useful
not useful
Is your clock really 3.68 MHz? By default the ATmega8 is running on the 
internal 1 MHz RC oscillator. Make sure you have set all the necessary 
fusebits for running with the external crystal (see datasheet).

von guest (Guest)

Rate this post
0 useful
not useful

i have it.

all is ok. except that during all this time, I compiled  the bad .exe 


thank all


Entering an e-mail address is optional. If you want to receive reply notifications by e-mail, please log in.

Rules — please read before posting

  • Post long source code as attachment, not in the text
  • Posting advertisements is forbidden.

Formatting options

  • [c]C code[/c]
  • [avrasm]AVR assembler code[/avrasm]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]

Bild automatisch verkleinern, falls nötig
Note: the original post is older than 6 months. Please don't ask any new questions in this thread, but start a new one.