rs232 or usb

Guest #1449186
Hey,

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

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

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

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

12

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

18

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

23

24
#include <avr/io.h>
25
#include <stdlib.h>
26
#include <inttypes.h>
27
#include <util/delay.h>
28

29

30

31
void USART_Init(void) 
32
{
33
  
34
  UBRRH = (unsigned char)(UBRR_VAL>>8);  // Set baud rate
35
  UBRRL = (unsigned char)UBRR_VAL;
36
  
37
  UCSRB |= (1<<RXEN)|(1<<TXEN);    // Enable receiver and transmitter
38
  
39
  UCSRC = (1<<URSEL) | (1<<UCSZ0)|(1<<UCSZ1);  // Set frame format: 8data, 1stop bit        
40

41
}//end USART_Init()
42

43

44
void USART_Putc(unsigned char c)
45
{
46
  while (!(UCSRA & (1<<UDRE))); // Do nothing until data have been transmited 
47
    
48
  UDR = c;                // Put data into Buffer, sends the data
49
  _delay_ms(10);   
50
}//end USART_Putc()
51

52

53
void USART_Puts (char *string)
54
{
55
    while( *string != '\0' )  //as long as *string != '\0' so unlike the "stringer end-character"
56
    {  
57
        USART_Putc(*string);
58
        string++;
59
    }
60
}//end USART_Puts()
61

62
int main(void) 
63
{
64
  USART_Init();
65
  USART_Puts("\r\n");
66
  while(1) 
67
  {
68
    USART_Puts("Hey !!!!");  
69
  }
70

71
   return 0;                     
72
} //end main()
Attached files:
Guest #1449222
How did you connect the board to your PC?  I wonder about the physical 
connection.

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).
Guest #1449230
Hey,
thank you for your interrest.

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

greet
Admin #1449828
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).
Guest #1451803
hey,

i have it.

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

stupid!

thank all

Reply

A question of your own? This thread is over 17 years old. Ask it in a thread of its own – more people read along there, and it gets answered more often and sooner.

Start a new thread

A fix, an addition or feedback on this thread? Then reply here.

Formatting
  • [c]C-Code[/c]
  • [code]code in other languages, ASCII drawings[/code]
  • [math]formula (LaTeX syntax)[/math]
  • [[Title]] – link to an article
  • Link to another post: right-click its post ID (#8078628), copy the address, paste it into the text

More about formatting

Post long source code as an attachment, not in the text.

Already registered? Log in

Not shown to anyone. We send you a link; your post appears once you confirm it there.

By submitting you create a free account and accept the terms of use.