Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Rx/Tx problem

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive
View previous topic :: View next topic  
Author Message
pratik

Bascom Member



Joined: 13 Oct 2005
Posts: 55

india.gif
PostPosted: Mon Jan 07, 2008 4:07 pm    Post subject: Rx/Tx problem Reply with quote

Hi,

I want to send 5 values from one micro controller to other through serial communication

TX----------------

$regfile = "89s2051.dat"
$crystal = 8000000
$baud = 2400
Config Debounce = 30

Dim Rx(10) As Byte

Rx(1) = 10
Rx(2) = 20
Rx(3) = 30
Rx(4) = 40
Rx(5) = 50

Do

Debounce P1.4 , 0 , Key , Sub

Wait 1

Loop

Key:

Printbin Rx(1) ; Rx(2) ; Rx(3) ; Rx(4) ; Rx(5)

Return


RX-------------

$regfile = "m8515.dat"
$crystal = 8000000
$baud = 2400
Config Lcdpin = Pin , Db4 = Portc.4 , Db5 = Portc.5 , Db6 = Portc.6 , Db7= Portc.7 , E = Portc.3 , Rs = Portc.2
Config Lcd = 16 * 2
Cls

Do

inputbin Rx(1) , Rx(2) , Rx(3) , Rx(4) , Rx(5)

Locate 1 , 1
Lcd Rx(1) ; " " ; Rx(2) ; " " ; Rx(3) ; " " ; Rx(4) ; " " ; Rx(5)


Loop

End


The problem is I am not able to receive the correct data

Need help
Back to top
View user's profile
rileyesi

Bascom Member



Joined: 19 Dec 2006
Posts: 398

blank.gif
PostPosted: Mon Jan 07, 2008 7:22 pm    Post subject: Reply with quote

Hi,

Quote:

$regfile = "89s2051.dat"


You might be in the wrong section. I don't think think this is an AVR chip!

However, to answer your question from an AVR view, I convert my data to a string variable and simply use the PRINT command on the transmitter side. On the receiver side, I do the following:

Code:

   While Inkey() <> "$"
   Wend
   Input Sdata
 


I add the $ symbol to my data at the transmitter. That way, the receiver knows where the start of the data package is.

Hope this helps.

Pete
Back to top
View user's profile
pratik

Bascom Member



Joined: 13 Oct 2005
Posts: 55

india.gif
PostPosted: Mon Jan 07, 2008 7:45 pm    Post subject: Reply with quote

hi,

thanks

i will try
Back to top
View user's profile
pratik

Bascom Member



Joined: 13 Oct 2005
Posts: 55

india.gif
PostPosted: Tue Jan 08, 2008 8:37 am    Post subject: Reply with quote

hi,

TX------------

Dim Sdata As String * 10
sdata= "1020304050"


do

print sdata

wait 1

loop


RX------------

Dim Sdata As String * 10
cls
lcd" start"
wait 1

do
While Inkey() <> "$"
Wend
Input Sdata

cls
lcd sdata

loop


As per your suggestion
But the lcd screen is blank
I connected TX to PC com port I receive $ & 1020304050

Any new suggestion because I want to send 5 nos of bytes which is not same at all the time
Back to top
View user's profile
Arera

Bascom Member



Joined: 23 Sep 2007
Posts: 386
Location: Wuppertal, Germany

germany.gif
PostPosted: Tue Jan 08, 2008 3:15 pm    Post subject: Reply with quote

Here´s a great tool to whatch the communication on the serial interface. I found it very helpful to solve communication problems.

http://www.docklight.de/download.htm

You only need to build an adapter-cable and maybe add some com-ports to your PC, then watch all the data trnsmission from both partners.
Back to top
View user's profile
rileyesi

Bascom Member



Joined: 19 Dec 2006
Posts: 398

blank.gif
PostPosted: Wed Mar 26, 2008 4:41 pm    Post subject: Reply with quote

Hi,

Sorry for the delay of my response.

For this to work, you have to include the $ symbol in your data. Modify your post to the following:

Code:

Dim Sdata As String * 11
sdata= "$1020304050"
 


Note that if your transmitter stops sending data, the receiver will be stuck in the loop forever. If this is a potential problem for you, you will need to add a counter, or something, to exit. Let me know if you need me to explain further.

Hope this helps.

Regards,

Pete
Back to top
View user's profile
rileyesi

Bascom Member



Joined: 19 Dec 2006
Posts: 398

blank.gif
PostPosted: Wed Mar 26, 2008 5:04 pm    Post subject: Reply with quote

Hi,

I want to ammend my previous post.

Keep the TX statement the same and add the $ symbol to your print statement.

Code:

TX------------

Dim Sdata As String * 10
sdata= "1020304050"


do

print "$";sdata

wait 1

loop
 


Hope this helps.

Pete
Back to top
View user's profile
Beke

Bascom Member



Joined: 14 Feb 2008
Posts: 45

hungary.gif
PostPosted: Wed Mar 26, 2008 6:25 pm    Post subject: Reply with quote

Hi rileyesi
There is a small problem with the way you suggest (to use the Print command), and this is the following: if you want to transmit all sort of data, among them the 0 value, you cannot transform this to a character string, because there is no character corresponding to the zero value (abstractly spoken, there is: the "null" character, i.e.nothing.) For this reason, the use of printbin/inputbin is necessary. This means only a small change in your code.
Back to top
View user's profile
rileyesi

Bascom Member



Joined: 19 Dec 2006
Posts: 398

blank.gif
PostPosted: Wed Mar 26, 2008 6:39 pm    Post subject: Reply with quote

Hi,

I have used this in system that have been running for years communicating using RF MODEMs and the data includes zeros. This also works if the boards are connected directly with a serial cable, you just have to use a null MODEM.

To be more specific, I have 4 data points that I need to send at the same time. Also, I want the data length to be the same each time, so I force a zero when it is needed (for example, 123 will be sent as 0123).

Here is a code snippet:

Code:

   Astring = Str(a(1))
   Astring = Format(astring , "0000")
   Bstring = Str(a(2))
   Bstring = Format(bstring , "0000")
   Cstring = Str(a(3))
   Cstring = Format(cstring , "0000")
   Dstring = Str(a(4))
   Dstring = Format(dstring , "0000")
   Print "$" ; Astring ; Bstring ; Cstring ; Dstring
 


Where Astring, etc. are DIMed as strings and A(x) is a integer array. This results in a 17 digit data packet each PRINT command and it starts with a $ sign.

At the receiver side, I tear the string back into the origonal four data points. (i.e. 0123 equals 123).

To be honest, I got this method either here or (more likely) from the old BASCOM e-mail ring. I like to give credit where credit is due!

Hope this helps.

Pete

EDIT: Added additional thoughts

There are other ways of data transfer, I am sure. One that comes to mind (but I have never used it) is using data delimiters. For example, you can separate your data using a comma and then your receiver will know where the data ends and the next one begins.

I am sure that there are much more qualified people here who could expand on this idea.
Back to top
View user's profile
Beke

Bascom Member



Joined: 14 Feb 2008
Posts: 45

hungary.gif
PostPosted: Wed Mar 26, 2008 9:06 pm    Post subject: Reply with quote

Hi,
to be more clear what I was speaking of here is this code snippet, run it in simulation:
Code:
Dim A As String * 5
  A = Chr(65) + Chr(66) + Chr(67) + Chr(0) + Chr(68)
  Print A
  Print Len(a)
  End  
Back to top
View user's profile
rileyesi

Bascom Member



Joined: 19 Dec 2006
Posts: 398

blank.gif
PostPosted: Wed Mar 26, 2008 10:29 pm    Post subject: Reply with quote

Hi,

I got your point from your first post. That is why I did my program the way I did! I needed to have an RS-232 communications link and I don't think PRINTBIN would work.

I hope this helps the origonal poster!! If not, let us know.

Regards,

Pete
Back to top
View user's profile
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    www.mcselec.com Forum Index -> BASCOM-AVR Archive All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum