Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

serin hangs on repeat usage

Status
Not open for further replies.
Help, Can not get Second SERIN call to function. SERIN (or Hserin ) will hang when called a second time.
SEROUT works correctly. Appreciate any suggestions.






Here is my code:





'PROCESSOR TYPE -- 16F877A


Define CLOCK_FREQUENCY = 16
Define CONFIG = 0x3f3a
AllDigital
ConfigPin RC6 = Output 'serial OUTPUT
ConfigPin RC7 = Input 'serial INPUT

Dim k(10) AsByte 'INPUT BUFFER
Dim i AsByte 'FOR/NEXT COUNTER

Define LCD_BITS = 4 '- defines the number of data interface lines (allowed values are 4 and 8; default is 4)
Define LCD_DREG = PORTC '- defines the port where data lines are connected to (default is PORTB)
Define LCD_DBIT = 0 '- defines the position of data lines for 4-bit interface (0 or 4; default is 4), else ignore
Define LCD_EREG = PORTD '- defines the port where E line is connected to (default is PORTB)
Define LCD_EBIT = 3 '- defines the pin where E line is connected to (default is 2)
Define LCD_RSREG = PORTD '- defines the port where RS line is connected to (default is PORTB)
Define LCD_RSBIT = 2 '- defines the pin where RS line is connected to (default is 3)
Define LCD_COMMANDUS = 5000 '- defines the delay after LCDCMDOUT statement (default value is 5000)
Define LCD_DATAUS = 100 '- defines the delay after LCDOUT statement (default value is 100)
Define LCD_INITMS = 100 '- defines the delay for LCDINIT statement (default value is 100
Lcdinit 0 'no cusor

startup:

Call read_comm(k(10)) 'read 10 items from comm port 'WORKS once AFTER PIC POWER ON
For i = 1 To 10
Serout PORTC.6, 9600, " = ", k(i), CrLf 'send 10 items -- THESE CORRECTLY DISPLAY ON PC
Lcdcmdout LcdClear
Lcdout "LAST IN CHAR " k(i)
Next i

WaitMs 1000

Call read_comm(k(10)) 'read 10 items from comm port 'SECOND CALL FAILS with LOCK UP
For i = 1 To 10
Serout PORTC.6, 9600, " = ", k(i), CrLf 'send 10 items
Lcdcmdout LcdClear
Lcdout "RCVD CHAR IS " k(i)
Next i
End 'read 10 items from comm port
'****************************************
Proc read_comm(j AsByte)
For i = 1 To 10
Serin PORTC.7, 9600, j 'read in 1 item
k(i) = j
Next i
End Proc
 
AHHHH . working code, bad ground to usb/uart module--only had rx-tx connected-- works as it should now'
Suprised that it worked at all. Thanks anyway
 
Just a little help information...

Hserin and serin can both hang the program, even if the hardware is correct..
It is wiser to poll the RCIF ( Hserin ), or the receive portpin (Serin)... so you can keep the program flow.

For instance... If you are using a radio device then it would be hanging frequently...
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top