PDA

View Full Version : HSERIN doesn´t work



wurm
- 17th July 2007, 11:04
Hallo,

I´m new here and I need some help.
I´m using a PIC16F873a in a handswitch. There I send and receive via UART some information.
Sending works fine. But I´m not able to receive some data.
The signal lays on the RX-Port. Thats correct.

Is there something wrong in my code?
I want to receive some characters (CHR(101), CHR(105), CHR(106))



' Säulentastatur medifa MXT-Steuerung
' PIC 16F873 für Tastenauswertung
'--------------------------------------------------
' (c) 2007 by WURM IT Solutions
' [email protected]
' Tel.: +49 2721 9279070
' -------------------------------------------------

' Controller: PIC 16F873A / 4MHz Resonator
' Modell: medifa MOT 601700
' Bus: RS485 / 19200 Baud / Half duplex
' -------------------------------------------------

' Software-Revision: V1.0 05.07.2007 Inbetriebnahme
'


' Definitionen
define osc 4
include "modedefs.bas"

DEFINE HSER_RCSTA 90h
DEFINE HSER_TXSTA 24h
DEFINE HSER_BAUD 19200 ' 19200 Bauds
DEFINE HSER_CLOERR 1



' Port-Definitionen
adcon1 = 7 'Ports auf digital
p1 var porta.0
p2 var porta.1
p3 var porta.2
p4 var porta.3
p5 var porta.5
p6 var portc.0
p7 var portb.7
p8 var portb.6
p9 var portb.5
p10 var portb.4
ELEIN var portc.1
s1 var word
s2 var word
s3 var word
s4 var word
s5 var word
s6 var word
s7 var word
s8 var word
s9 var word
s10 var word
s11 var word
s12 var word
s13 var word
s14 var word
s15 var word
s16 var word
s17 var word
s18 var word
Bus_out var byte
Bus_out_alt var byte
zaehler var word
Bus_in var Byte
busrw var portc.5

' Ports als Ein- bzw. Ausgang
input porta.3
input porta.5
input portc.0
input portb.7
input portb.6
input portb.5


output porta.0
output porta.1
output porta.2
output portc.1
output portc.5


' Hauptprogramm
high ELEIN 'EL-Folie und Display beim Start ausschalten
'pause 5000

'high busrw 'für senden = high, für empfangen = low

Schleife:
low busrw
repeat
hserin [Bus_in]
until Bus_in = 101 or Bus_in = 105 or Bus_in = 106

if Bus_in = 101 then gosub Taste
if Bus_in = 105 then gosub Power_on
if Bus_in = 106 then gosub Power_off

goto Schleife

Taste:
low ELEIN 'Test
' Ebene 1 abfragen S2, S1, S14, S13, S8, S7
low p10
s1=0
s2=0
s3=0
s4=0
s5=0
s6=0
s7=0
s8=0
s9=0
s10=0
s11=0
s12=0
s13=0
s14=0
s15=0
s16=0
s17=0
s18=0

high p3
low p2
low p1

if p4 = 1 then s2 = 1
if p5 = 1 then s1 = 1
if p6 = 1 then s14 = 1
if p7 = 1 then s13 = 1
if p8 = 1 then s8 = 1
if p9 = 1 then s7 = 1


' Ebene 2 abfragen S4, S3, S16, S15, S10, S9
low p3
high p2
low p1

if p4 = 1 then s4 = 1
if p5 = 1 then s3 = 1
if p6 = 1 then s16 = 1
if p7 = 1 then s15 = 1
if p8 = 1 then s10 = 1
if p9 = 1 then s9 = 1


' Ebene 3 abfragen S6. S5. S18. S17. S12. S11
low p3
low p2
high p1

if p4 = 1 then s6 = 1
if p5 = 1 then s5 = 1
if p6 = 1 then s18 = 1
if p7 = 1 then s17 = 1
if p8 = 1 then s12 = 1
if p9 = 1 then s11 = 1

low p3
low p2
low p1


' Bus_out ausgeben

Bus_out = 099
zaehler = 0
if s1 = 1 then Bus_out=001:zaehler = zaehler + 1
if s2 = 1 then Bus_out=002:zaehler = zaehler + 1
if s3 = 1 then Bus_out=003:zaehler = zaehler + 1
if s4 = 1 then Bus_out=004:zaehler = zaehler + 1
if s5 = 1 then Bus_out=005:zaehler = zaehler + 1
if s6 = 1 then Bus_out=006:zaehler = zaehler + 1
if s7 = 1 then Bus_out=007:zaehler = zaehler + 1
if s8 = 1 then Bus_out=008:zaehler = zaehler + 1
if s9 = 1 then Bus_out=009:zaehler = zaehler + 1
if s10 = 1 then Bus_out=010:zaehler = zaehler + 1
if s11 = 1 then Bus_out=011:zaehler = zaehler + 1
if s12 = 1 then Bus_out=012:zaehler = zaehler + 1
if s13 = 1 then Bus_out=013:zaehler = zaehler + 1
if s14 = 1 then Bus_out=014:zaehler = zaehler + 1
if s15 = 1 then Bus_out=015:zaehler = zaehler + 1
if s16 = 1 then Bus_out=016:zaehler = zaehler + 1
if s17 = 1 then Bus_out=017:zaehler = zaehler + 1
if s18 = 1 then Bus_out=018:zaehler = zaehler + 1
if zaehler > 1 then Bus_out = 099
if s1 = 1 and s2 = 1 then Bus_out = 098


high busrw
HSEROUT [Bus_out]
low busrw

return


' Sub POWER_ON
Power_on:
low ELEIN
return


' Sub POWER_OFF
Power_off:
high ELEIN
return

BrianT
- 24th July 2007, 06:22
I think you will find that HSERIN is not a fully self contained command for sending or receiving data through the UART. You must manually manage the CREN bit and probably more for reliable results.

I had many intermittent problems with that command so I gave up and now only use DEBUG, SERIN or SERIN2 which have the advantage they can be assigned to any pin.

HTH
Brian

Darrel Taylor
- 24th July 2007, 07:23
wurm,

Do you have pins 2 and 3 connected together on the 75176? (!RE/DE)
<br>

dhouston
- 24th July 2007, 11:38
RS485 half-duplex is usually single master, multiple slaves with slaves transmitting only after being requested to do so by the master. Is this the code for a slave? If so, could the problem be on the other end?

wurm
- 29th July 2007, 14:23
So thanks for your answers.
I`ve found out the problems.

I have two SP485 drivers in the layout and one was connected as receiver and one as sender.
Then the bus doesn´t work correctly.
The second problem was solluted by setting and resetting cren register.

Best regards,
Wurm