Problem with RS485 print/input string HELP!!!

Rasprava o AVR mikrokontrolerima, AVR projekti i drugo vezano za AVR...

Moderators: pedja089, stojke369, trax, InTheStillOfTheNight

Post Reply
Laco
Posts: 1
Joined: 09-11-2010, 12:42
Location: Split, HRVATSKA

Problem with RS485 print/input string HELP!!!

Post by Laco »

Napisao sam u Bascom AVR-u test program za RS485 komunikacije između ATMEGA128 - master i ATMEGA32 - slave. Imam slijedeći problem, na Slave LCD-u dobijem prvi zna chr(240) u stringu.

$regfile = "m128def.dat" 'Master
$crystal = 10000000
$hwstack = 32
$swstack = 20
$framesize = 40
$baud = 9600

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
Cursor Off
Config Com1 = 9600 , Synchrone = 0 , Parity = Even , Stopbits = 1 , Databits = 8 , Clockpol = 0 ' MUST MATCH THE SLAVE

Dim S As String * 8 , S1 As String * 8

Config Print0 = Porte.2 , Mode = Set ' use portd.2 for the direction
Rs485dir Alias Porte.2

Config Rs485dir = Output

'Rs485dir = 0 ' go to receive mode
Rs485dir = 1

S = "08.03.11"
S1 = "13:12:58"

Lcd "RS485 sending."
Wait 1

Do
Cls
Gosub Rs485_send
Loop
End

Rs485_send:
Rs485dir = 1
Print S
Print S1
Locate 1 , 1 : Lcd "S : " ; S
Locate 2 , 1 : Lcd "S1: " ; S1
Waitms 500
Return
*********************************************************

$regfile = "m32def.dat" ' slave
$crystal = 10000000
$baud = 19200
$hwstack = 32
$swstack = 40
$framesize = 40
$baud = 9600

Config Lcdpin = Pin , Db4 = Porta.4 , Db5 = Porta.5 , Db6 = Porta.6 , Db7 = Porta.7 , E = Portd.6 , Rs = Portd.4
Config Lcd = 16 * 2
Cls
Cursor Off

Dim S As String * 8 , S1 As String * 8 , Resp As String * 2



Config Print0 = Portd.2 , Mode = Set ' use portd.2 for the direction
Rs485dir Alias Portd.2

Config Rs485dir = Output

Rs485dir = 0 ' go to receive mode
'Rs485dir = 1 ' go to send mode

Lcd "RS485 receiving"
Wait 1

Do
Cls
Gosub Rs485_read

Loop

End

Rs485_read:

S = " "
S1 = " "
Input S
Input S1
Locate 1 , 1 : Lcd "S : " ; S
Locate 2 , 1 : Lcd "S1: " ; S1
Waitms 500
Return
*************************************
Na Slave LCD-u dobijem

S : chr(240)08.03.1 umjesto 08.03.11
S1: chr(240)13:12:5 umjesto 13:12:58

Unaprijed se zahvaljujem na pomoći
User avatar
Kizo
Pravo uznapredovao :)
Pravo uznapredovao :)
Posts: 387
Joined: 01-11-2009, 22:40
Location: Hrvatska

Re: Problem with RS485 print/input string HELP!!!

Post by Kizo »

Vidim da ti kontroleri rade na 10MHz što znači da će uvijek postojati mala baud greška. Sve je ok dokle je ukupna greška manja od 2%, no pošto imaš problem, treba probati sa nekim "baud friendly" kristalom.
Dalje se nameče pitanje dali je prijemni dio buffered tj. što se događa kada master izvršava Print, a slave izvršava Waitms 500. Vjerujem da se taj slučaj ne može dogoditi, da bascom ima implementiran nekakav flow control, no s tim gotovim naredbama nikad nisi na čistu što se tu točno događa, te ih nikad nisam previše volio.
buco-1
Napredujem
Napredujem
Posts: 105
Joined: 24-10-2010, 21:22

Re: Problem with RS485 print/input string HELP!!!

Post by buco-1 »

A da probas poslati jedan znak, prazno polje, prije slanja niza? To bi trebalo sinkronizirati rutine za komunikaciju u MCU-ima i otkloniti gresku.
Today's scientists have substituted mathematics for experiments, and they wander off through equation after equation, and eventually build a structure which has no relation to reality.
- Nikola Tesla
Post Reply