Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi
i have a problem with UART that when i send 0 from vb and the PIC receive it and multiply it by 100 it it become 1111 on the led i use PIC18F452 and have a lot of consecutive UART read
could any one help me ????????

[Added from OP comment]

here is the reading code in PIC
C++
if (UART1_Data_Ready())
       {    a=0;

         for( a=0;a<3;a++)
         {
         ch_Rd= UART1_Read();
         b=ch_Rd;
         delay_ms(2);

         ch_Rd= UART1_Read();
           delay_ms(2);
         acc=ch_Rd;
         b+=acc*100;
         loc[a]=b;

          }

and here is a sample of sening code frome the VB :
VB
serial1.Write(1)
        serial1.Write(2)
        serial1.Write(0)
        serial1.Write(3)
        serial1.Write(0)
        serial1.Write(4)
        serial1.Write(0)

when i display the content of loc[1] for example on leds i had something like:11110011
Posted
Updated 2-May-13 2:05am
v2
Comments
OriginalGriff 2-May-13 7:49am    
From that? Probably not...
This is not a good question - we cannot work out from that little what you are trying to do.
Remember that we can't see your screen, access your HDD, or read your mind.
Perhaps a code sample might help?
Use the "Improve question" widget to edit your question and provide better information.
salah_abughalyon 2-May-13 7:55am    
thank you for your attention to may question
here is the reading code in PIC
if (UART1_Data_Ready())
{ a=0;

for( a=0;a<3;a++)
{
ch_Rd= UART1_Read();
b=ch_Rd;
delay_ms(2);

ch_Rd= UART1_Read();
delay_ms(2);
acc=ch_Rd;
b+=acc*100;
loc[a]=b;

}
and here is a sample of sening code frome the VB :
serial1.Write(1)
serial1.Write(2)
serial1.Write(0)
serial1.Write(3)
serial1.Write(0)
serial1.Write(4)
serial1.Write(0)
when i display the content of loc[1] for example on leds i had something like:11110011
could you help

1 solution

You are probably going to think I'm being really nasty to you here - I'm not...

The first thing that springs to mind is: where did you get the idea that a 2ms delay would be enough time to guarantee the receive of a character will occur? You can't just go "Oh, I've got a char, another one will be along in 2ms, so I'll grab that" - it's not like busses!

So when you "read" that the UART is ready, you then grab whatever it happens to have regardless of where there is a character or not, and then multiply it by 100 before stuffing it into memory. Why? Why 100? is that supposed to be a special number with characters? Because trust me, it isn't...

Why don't you go right back to the beginning, and try to make sure that you can receive a single byte correctly, then look at what you have to do to receive two, and so on, because it doesn't look like you have thought things through very far as yet. Perhaps a trip to the Microchip web site and its example code would help?
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900