Forum - MCS Electronics

 

FAQFAQ SearchSearch RegisterRegister Log inLog in

Soft Serial UART hang after reconnect

 
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR
View previous topic :: View next topic  
Author Message
acjacques

Bascom Member



Joined: 24 Feb 2019
Posts: 13
Location: Rio de Janeiro

brazil.gif
PostPosted: Fri Nov 22, 2019 3:17 pm    Post subject: Soft Serial UART hang after reconnect Reply with quote

My 328p with bellow code works fine to receiving the serial input but if there are a momentary disconnection from this input the processor hangs then only reconnecting after a reset.

I have tryed the timeout but it seems does not work.

Obs. The input pin PORTC.1 have a 1k series resistor. I dont believe this could matter in this issue.

Thanks for any help.

'============================code==================

$regfile = "m328pdef.dat"
$crystal = 16000000
$baud = 115200
$hwstack = 32
$swstack = 16
$framesize = 50
$lib "serin.lib"

Dim serin_timeout as long
Dim S As String * 8
Dim I As Word

do

serin_timeout = 50000
Serin S , 1 , PortC , 1 , 9600 , 0 , 8 , 1 'testada a saida digital no pino analogo
I = Val(s) 'isola só os numeros da string transformando para numerico
S = Str(i) 'numérico de volta para string
S = Format(s , "0000") 'formata a string
S = S + " mm" 'soma a string
Print S
Waitms 50

loop

(BASCOM-AVR version : 2.0.8.2 )
Back to top
View user's profile
Evert :-)

Bascom Expert



Joined: 18 Feb 2005
Posts: 2165

netherlands.gif
PostPosted: Fri Nov 22, 2019 11:07 pm    Post subject: Reply with quote

The serin is set as input, so if the signal is momentary disconnected then this input pickup noise etc. and will do strange things.
Try 10K pulldown resistor to hold the serin in known active state when the signal disconnect.

_________________
www.evertdekker.com Bascom code vault
Back to top
View user's profile Visit poster's website
EDC

Bascom Expert



Joined: 26 Mar 2014
Posts: 1136

poland.gif
PostPosted: Sat Nov 23, 2019 6:22 am    Post subject: Reply with quote

Mega328P are armed with PCINT on the every pin. You can start timer for "one or more byte long for the given baudrate" and somehow handle the timeout.
Back to top
View user's profile Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    www.mcselec.com Forum Index -> BASCOM-AVR 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