Can anyone help with reading from Mega64l USRT

Go To Last Post
20 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i am receiving a 8 bit data from an USRT. The message is like "1234567A" . I wonder how can i separate this message and only store the last letter of A ?

THX

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If the number of characters is a known amount, and you can tell when you are receiving the first character, just increment a count variable each time a character is received and when you are at the one you want, save it.

 

Keith.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

'1', '2', '3', '4', '5', '6', '7' are numeric characters.
'A' is not a number.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you for your respond .

Can you please make an sample code for me ?

or What what about this following :

Char character

character=UDR>>7;

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

tommynewman wrote:
Thank you for your respond . Can you please make an sample code for me ?

 

Better idea,

You write something and we can guide you from there.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

A hint

 


char c;

int main()
{
   ...
   ...

    while(1)
    {
        if(UCSRA & (1<<RXC))  // if a char received
        {
           c = UDR;
           if(c == 'A') do something;  
           if(c == 'B') do something else;  
           ...
           ...
        }
    }
}

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0
char c;
do {
    c = uart_getchar();
} while (c < 'A');
one_to_store = c;

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'd give Clawson an A+ on this homework assignment!   wink

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Heres a question....

 

The OP wants to get the last character from an 8 character string it appears, so the question to the OP would be:

 

Are you looking to extract the last character from the string, which could be just about anything, or will the last character always be an 'A'?

 

The OP does say:

tommynewman wrote:
store the last letter of A ?

 

But as history has shown this is not always the case.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello Thank you for your code.  I had make an example of what and UDR received "123456A". It can be any thing . but the only useful bit the last one. How can i get that one ?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

may i please ask you to show me the assignment ?

thx

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

what about this code ?

 

char c ;

 c= UDR >>7; right shit the UDR 7 bit to get the last one ?

 

does it works ?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

tommynewman wrote:
may i please ask you to show me the assignment ?

What assignment?

 

Since all  you want to do is grab the last character, then as artandsparks wrote:

Artandsparks wrote:

If the number of characters is a known amount, and you can tell when you are receiving the first character, just increment a count variable each time a character is received and when you are at the one you want, save it.

 

Keith.

 

tommynewman wrote:
Can you please make an sample code for me ?

Some ideas have already been shown.  Can you provide what you yourself have written and maybe we can work with that?

 

tommynewman wrote:
I had make an example of what and UDR received "123456A". It can be any thing . but the only useful bit the last one. How can i get that one ?

Does this string have a delimiter, or an end of message character after the 'A' that could be sensed?

 

What would also help is if you described what is sending this string of data.

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

i am reeving a message from a RF600D encoder. When a button is pressed it will send a meesage to my URST. 

this message is like: 

If S1 is pressed: 2345678A (2345678a if the battery voltage in the transmitter is low)
If S2 is pressed: 2345678B (2345678b if the battery voltage in the transmitter is low)
If S1 and S2 are pressed together: 2345678C (2345678c if the battery voltage in the transmitter is low)
If S4 is pressed: 2345678H (2345678h if the battery voltage in the transmitter 

 

i want to separate numbers and the character. use them or further programming .   How can i achieve this ? i was thining to right shit UDR to bit 7 to get the last character . (C=UDR>>7). is this works?

 

For exmale C to store  character.

N[7] to store number 

 

many thanks .

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I looked at the datasheet and found what I have been asking you on Page 5 regarding a delimiter

 

 

So what you do is load the received data into a buffer until you see a carriage return then exit the loop, ignoring the linefeed.  The last byte in the buffer will be the character you are looking for.

 

THe other option is to keep loading the buffer until you see the line feed and then exit the loop, and then extract the character at buffer[7] (you start at 0) into your local variable.

 

Jim

 

Edit: I am guessing this is a school project as you really do not need one of these things since you have an AVR with enough I/O to encode at least 32 switches easily.

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

Last Edited: Tue. May 16, 2017 - 03:37 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

 i was thining to right shit UDR to bit 7 to get the last character . (C=UDR>>7). is this works?

Definitly not.

 

It seems you do not understand not only the UART communication,

but even the difference between BYTE and BIT.

 

The idea that there can be 7 characters in the udr register and that you can get one of them by bit-shift operation is a real AVR-horror. 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

If you want the 7th one you need to read the UDR register 7 times. You did initially say "123456A" suggesting the first six would be digits and the one you want is a non digit. That's why I suggested:

char c;
do {
    c = uart_getchar();
} while (c < 'A');
one_to_store = c;

which ignores everything below 'A' so '1', '2', '3' and so on. But if it's really just "read until the 7th" then:

char c;
uint8_t i;
for (i=0; i < 7; i++) {
    c = uart_getchar();
}

At the end of that 'c' is holding the 7th character. (the previous 6 were all written to 'c' then over-written.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

clawson wrote:

If you want the 7th one you need to read the UDR register 7 times. You did initially say "123456A" suggesting the first six would be digits and the one you want is a non digit. That's why I suggested:

char c;
do {
    c = uart_getchar();
} while (c < 'A');
one_to_store = c;

which ignores everything below 'A' so '1', '2', '3' and so on. But if it's really just "read until the 7th" then:

char c;
uint8_t i;
for (i=0; i < 7; i++) {
    c = uart_getchar();
}

At the end of that 'c' is holding the 7th character. (the previous 6 were all written to 'c' then over-written.

He will also need to eat <cr><lf> char's too or the next time he reads data it will be out of sync.

 

Jim

 

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...

 

 

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The Codevision Wizard has a great setup for the USART that I use all the time, and would be ideal for what the OP wants, but since the OP has not shown what they have done so far....................No soup for them!

 

Jim

I would rather attempt something great and fail, than attempt nothing and succeed - Fortune Cookie

 

"The critical shortage here is not stuff, but time." - Johan Ekdahl

 

"Step N is required before you can do step N+1!" - ka7ehk

 

"If you want a career with a known path - become an undertaker. Dead people don't sue!" - Kartman

"Why is there a "Highway to Hell" and only a "Stairway to Heaven"? A prediction of the expected traffic load?"  - Lee "theusch"

 

Speak sweetly. It makes your words easier to digest when at a later date you have to eat them ;-)  - Source Unknown

Please Read: Code-of-Conduct

Atmel Studio6.2/AS7, DipTrace, Quartus, MPLAB, RSLogix user

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you everyone very helpfull. Let me try to write some code first .