serin command stucks all program

Hi i am in trouble again. I am using axe133 for lcd display. My main is axe 020. Which is 28x2 chip. I got 3 spare pins in 18m2 chip in axe133. I want to use these for defferent output. Like, i want a pulsout at pin c.0 but when program runs and comes to (serin Rx, boud, b1) this command, it stucks. Can anyone give me any suggestion about that please. I want continue pulse out from pin c.0 when there is no lcd print command. I am pasteing the main part of commands here. Problems in big letters part. Please help
Code:
* * #define use_welcome*
symbol line_length = 16
symbol baud = N2400_16
symbol RX**= C.5*
symbol enable *= C.6 
symbol rs **= C.7*
 EEPROM $00, (" **Serial LCD **") *
; store msg in the EEPROM memory 
EEPROM $10, (" www.picaxe.com ")
 *; store msg in the EEPROM memory * 
EEPROM $20, ("This is msg 2 **") 
*; store msg in the EEPROM memory 
EEPROM $30, ("This is msg 3 **")
 *; store msg in the EEPROM memory 
EEPROM $40, ("This is msg 4 **")
 *; store msg in the EEPROM memory 
EEPROM $50, ("This is msg 5 **") 
*; store msg in the EEPROM memory 
EEPROM $60, ("This is msg 6 **")
 *; store msg in the EEPROM memory
 EEPROM $70, ("This is msg 7 **") *
; store msg in the EEPROM memory 
EEPROM $80, ("This is msg 8 **") *
; store msg in the EEPROM memory 
EEPROM $90, ("This is msg 9 **") *
; store msg in the EEPROM memory 
EEPROM $A0, ("This is msg 10 *") *
; store msg in the EEPROM memory 
EEPROM $B0, ("This is msg 11 *") 
*; store msg in the EEPROM memory 
EEPROM $C0, ("This is msg 12 *") *
; store msg in the EEPROM memory 
EEPROM $D0, ("This is msg 13 *") *
; store msg in the EEPROM memory 
EEPROM $E0, ("This is msg 14 *") 
*; store msg in the EEPROM memory 
EEPROM $F0, ("This is msg 15 *") 
*
 ; display welcome message if desired 
#ifdef use_welcome* 
let b1 = 0*
gosub msg*** *
low rs**
 let pinsB = 192**
pulsout enable,1 **
high rs***
let b1 = 1***
gosub msg***
; do it 
#endif** 

main: * *
[B]serin RX,baud,b1*[/B]

[SIZE=4]If b1 = 0 then 
Pulsout c.0, 100 
Pause 1000 
Goto main 
Endif *[/SIZE]
 
if b1 < 253 then
 let pinsB = b1 **
pulsout enable,1 
*
goto main***

else if b1 = 254 then 
low rs 
 serin RX,baud,b1*
*
 let pinsB = b1 **
pulsout enable,1 
High rs

else if b1 = 253 then
 serin RX,baud,b1**

gosub msg**
*
 
Last edited by a moderator:

tony_g

Senior Member
have you tried adding an optional timeout to the serin statement so it will not sit there and hang until it receives some data.

manual 2, page 204
 

westaust55

Moderator
As suggested by tony, you can incorporate a timeout with the SERIN command.
However, be aware that while performing some other task(s) the 18M2 may miss receipt of some incoming data.
You may need to consider a pulse first from the AXE020 prior to the Serout and use interrupts on the 18M2 but that is not guaranteed (I have not checked 18M2 interrupt capability on 18M2) and will add to complexity.
 

SAborn

Senior Member
As you are only receiving 8 bytes of data into b1 with serin, you might want to consider using "background" receive, as this will place the data into b1 while other tasks are being done, then you can check b1 for a change of data when you are ready for it in your program.
Background receive can solve many problems with serial data and program hangups.
 

westaust55

Moderator
The HSERIN is the background receive command.see PICAXE manual 2 page 91.
For the 18M2 that uses pin C.2 (physical leg 8) which is one of the free pins on the AXE133.
 

westaust55

Moderator
@Shah,

Your code at post 1 suggests a 100ms pulse every second.
Can you elaborate on the pulses that you with to send through pin C.0?
Frequency or period between each and the mark or high duration. Even telling is the purpose of the pulses might be helpful.

How critical is the timing? Keep in mind that SERIN for example will stop some background tasks as well - but Manual2 Appendix 4 makes no mention of background HSERIN affecting other tasks so could be test time unless others can confirm (maybe not since it uses dedicate internal hardware).
Then folks here may be able to determine/suggest, particularly if the timing is not critical, if alternate method could apply such as PWM if frequency is say > ~500 Hz or if ~50Hz is okay then consider the SERVO related commands.
 
i did not try timeout.

Thanks guys. I think timeout will work in my program. I am going to work now. I will try later. And let you know.
 
@westaust

Thanks. I will let you know. I am not going to do any critical task with my 18m2 because as you know i got only three spare pins. I will use one for pulse out, one for readadc (that must when all other command stoped) and one for lcd backlight. Now i have to go to work, i will try time out at first when i back. Thanks
 
serin timeout problem.

Hi. I tried timeout for serin command pulsout at the same time. it gives pulse perfectly but doesnt stop when serin data receiveing. Actually i want to get a pulse every 500ms and wait for serin data input all at once (what it does) but i also want pulsout will stop when serin data is receiving and start pulsout again when all data been recieved. Is that possible? Can anyone tell me how would be the command if i want to da that please? I am pasteing a part of command again bellow.
 
modified command for serin

main: * *

Pulsout c.0, 100

serin[500,main],RX,baud,b1*




if b1 < 253 then
let pinsB = b1 **
pulsout enable,1
*
goto main***

else if b1 = 254 then
low rs
serin RX,baud,b1*
*
let pinsB = b1 **
pulsout enable,1
High rs

else if b1 = 253 then
serin RX,baud,b1**

gosub msg**
*
 

hippy

Ex-Staff (retired)
Actually i want to get a pulse every 500ms and wait for serin data input all at once (what it does) but i also want pulsout will stop when serin data is receiving and start pulsout again when all data been recieved.
What is your definition or criteria of "all data been recieved" ?
 
all data been recieved

I mean to say that if i want to print '' hello world'' and when all these letters printed on lcd then the pulse out will start again.
 

hippy

Ex-Staff (retired)
I mean to say that if i want to print '' hello world'' and when all these letters printed on lcd then the pulse out will start again.
But how does the PICAXE know all data which will be sent has been sent ?

It can use a timeout so it starts pulsing again, say, half a second after the last data has been sent and received, but that is what you already have in your program.

How long do you want it to hold off pulsing for after the last data has been sent ?
 

hippy

Ex-Staff (retired)
A 5 second timeout would be 10 periods of 500ms, so you could change ...

Code:
main:
  Pulsout c.0, 100
  serin[500,main],RX,baud,b1
Add a 'timeout' variable, reset it to 10 when any data is received, and let it count down to zero when nothing is received ...

Code:
Symbol timeout = b[i]?[/i]

main:
  If timeout = 0 Then
    Pulsout c.0, 100
  Else
    timeout = timeout - 1
  End If
  serin[500,main],RX,baud,b1
  timeout = 10
The only question there is whether the 'timeout=10' adversely affects the timing of subsequent commands and whether the code remains fast enough to get back to the SERIN for the next data.

If it is a problem then an alternative is to duplicate the code so you have a 'main' loop which pulses every 500ms, and a 'more' loop which waits 5 seconds after the last data was received ...

Code:
main:
  Pulsout c.0, 100
  serin[500,main],RX,baud,b1
  [i]handle byte received, goto more[/i]
more:
  serin[5000,main],RX,baud,b1
  [i]handle byte received, goto more[/i]
 
@ hippi

Thanks for your help. Actually i am very begenner in microcontroller world. Can you please explain about this line (handle byte recived) and (symble timeout = b? ) what is b stand for?
 

westaust55

Moderator
Regarding "handle byte received"

When the SERIN receives a byte if data the program must then analyze to ascertain if it is a command or ASCII character.
One the data type is known the program must set the appropriate signal control lines and forward the data to the LCD/OLED display
All this takes a small but finite time and must be completed in the short time before the next byte is received by the SERIN command.
If the program does not return to the SERIN command fast enough data coming in will be missed/lost.
 
Top