1
\$\begingroup\$

I am trying to program ATmega8 for testing purposes using CVAVR as cross compiler and avrdude GUI as burner. Though I am able to burn the program, I think I am missing something in the coding part. It may be quite silly.

I have 2 questions:

  1. I am using Xbee Pro for wireless communication. It works with 5V and my ATmega8 board, I think provided the required voltage. But there is no communication happening with the other Xbee Pro module attached to my laptop. I am using XCTU and have checked the baud rate and other settings. On the other hand, when I used a MAX 232 circuit and then communicate with my laptop using a Serial to USB converter, I was able to send data to my laptop on XCTU. I used putchar("f"); on the XCTU sometimes "." was getting printed and sometimes "K" (then I realized that it was junk).

    So I want to ask: is voltage causing problems with transmission?

  2. In the coding part, when I am using MAX, I am using the following code:

     x = getchar();  
     if(x == 97) 
     {
         lcd_clear();
         lcd_gotoxy(0,0);
         lcd_putsf("x");
         PORTB = 0b00000001;   
         delay_ms(300);
     } 
     else 
     {
         lcd_clear();
         lcd_gotoxy(0,0);
         lcd_putsf("Shailendra Singh");
         PORTB = 0b00000010;   
         delay_ms(300);
     }
    

The rest of code and registers initialization is done by CVAVR itself but this is the code of main concern. What I want is that when I press "a" on my laptop, if operation must be performed but I am confused by

if(x == 97)

97 is the ASCII value of "a". Am I using it correctly by comparing x with 97 (I assumed that when "a" is pressed).

Along with that with getchar(), I can receive only one character, what if I want to receive a full string?

\$\endgroup\$
  • \$\begingroup\$ I can see, when you are sending data you are using delay functions. Do not use delays where communication is concerned. Which is why you receive only a few letters on the other side. This is a simple serial communication so check if you have baud rate, parity, stop bits, etc same for the transmitter and receiver. \$\endgroup\$ – David Norman Jun 22 '13 at 3:03
  • \$\begingroup\$ @DavidNorman: I am using delay so as to print the value of received character on LCD, if i will not use delay, characters will be printed on LCD , but they wouldn't be visible clearly. \$\endgroup\$ – shailendra Jun 23 '13 at 7:32
  • \$\begingroup\$ I do not understand. I've never heard that before. \$\endgroup\$ – David Norman Jun 23 '13 at 10:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.