go away spammer

Author Topic: UART between AtMega8 and Palm... Getting 49 instead of 1...  (Read 1638 times)

0 Members and 1 Guest are viewing this topic.

Offline corrado33Topic starter

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Ok, I've got my AtMega8 receiving text from my palm.  (Well, numbers specifically because I can't display letters).

I don't have a serial cable, (those things are freaking hard to find now-a-day... at least locally).

Anyway, both the cable coming from my PDA and the level adapter I bought have male ends, so I hooked up the TX of the palm to the RX of the level adapter.  (Pin 2 to Pin 3).  And ground to ground. I'm pretty sure that's all good and fine.  Oh and I hooked a 2k2 ohm resistor up between the level adapter and the RX pin of the atmega.  

Now, here's my code.

Code: [Select]
#include <avr/io.h>
#include "C:\ReaperR.h"


int main()
{
display(1,1000); //Just display 1 to make sure everything is on etc.
int data=0; //Data variable
DDRD &= ~0x01; //Make sure RX port is input
UCSRA = 0x00; //UCSRA doesn't do much, just flags to check
PORT_OFF(UBRRH,8); //Make sure URSEL is low so I can access UBRRH
UBRRH = 0x00; //Set first part of baud rate
PORT_ON(UCSRC,8); //Make sure URSEL is high so I can access UCSRC
UCSRC |= 0x86; //Asynchronous, No Parity, 1 stop bit, 8 bit char size
UBRRL = 0x19; //Set second part of baud rate (2400)
UCSRB = 0x10; //Enable the reciever
display(2,1000); //Display 2 so I see the program has reached this far
while(1==1)
{
while(!(UCSRA & 0x80)); //Wait till there is unread data
data = UDR; //Put data into variable
display(data,1000); //Display data for 1000 milliseconds
}
}

So basically what happens is I write 1 on the palm, and it displays 49, I write 2 and it displays 50, 3-->51, 4-->52 etc etc all of the way up to 9.  

Now all my display function does is takes a two digit number and displays it on my 7 segment display.  I know it works, I haven't had any problems with it.  It won't display anything unless it recognizes it.  The variable in the function that holds the data is initialized every time it's run, so there's no way it could be hanging out without being reset.  

Now I realize that I don't need the whole 8 bits because the way the program on the palm works now is that it sends something as soon as it's written.  There is no way for me to queue up a 1 then 0 to send "10".  

I just don't get why I get these numbers.  Any help?

EDIT:  Oh and the program on the palm works fine when hooked up to the computer and looked at through hyperterminal.
EDIT2: And the MCU displays the same thing when I hook it up to the computer and send it numbers from hyperterminal.   
« Last Edit: July 03, 2011, 02:14:25 PM by corrado33 »

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,944
  • Helpful? 99
Re: UART between AtMega8 and Palm... Getting 49 instead of 1...
« Reply #1 on: July 03, 2011, 03:06:56 PM »
Quote
So basically what happens is I write 1 on the palm, and it displays 49, I write 2 and it displays 50, 3-->51, 4-->52 etc etc all of the way up to 9. 
Your code and connections are working perfectly. An ASCII '1' is a Decimal 49 and a Hex 31.

Look up the ASCII table to see what the codes are for "printable" numbers. Also study the number systems, Binary, Hex & Decimal, to see how a value can be represented.

Offline corrado33Topic starter

  • Supreme Robot
  • *****
  • Posts: 611
  • Helpful? 11
Re: UART between AtMega8 and Palm... Getting 49 instead of 1...
« Reply #2 on: July 03, 2011, 03:28:37 PM »
Your code and connections are working perfectly. An ASCII '1' is a Decimal 49 and a Hex 31.

Look up the ASCII table to see what the codes are for "printable" numbers. Also study the number systems, Binary, Hex & Decimal, to see how a value can be represented.

That's good to hear!  I'm actually extremely surprised it worked (on the first try).  And I didn't break anything.

I'm really excited though, this means I can use my palm for processing.  Which is kinda useless unless I do something that requires a good bit of processing.   ;D

 


Get Your Ad Here

data_list