Program hanging/resetting after a number of LCD com3 string outputs

Started by charliem101101 October 8, 2003
Hi all,

I am having trouble with a program and any help would be very
welcome. My program jumps between subroutines that represent
different options on a menu. Each subroutine puts a string on the LCD
using com3.

The problem I get is that after an exact number of LCD updates the
program either just hangs or resets itself. The number of updates
varies from about 8 to 21 and seems to be affected by the size of
queue defined for com3out. If you take a different path through my
menu the problem still occurs after the same number of updates.

I am writing to the LCD using putqueuestr(com3out, ...).

I have tried the following - with no effects whatsoever on the
problem;

1. Flushing and priming com3 before writing to it (using some code I
found in the files section on this site)

2. Sticking in delays and sleeps before/after com3 commands

Am I overloading a buffer ?

Thanks for any help you can give me,

CharlieM



You might want to look at another part of your program. If you are using a
lot of subroutines and they call each other then you may be running out of
stack space and that would cause the program to hang. Just a thought.
Harry

-----Original Message-----
From: charliem101101 [mailto:]
Sent: Wednesday, October 08, 2003 6:38 AM
To:
Subject: [BasicX] Program hanging/resetting after a number of LCD com3
string outputs Hi all,

I am having trouble with a program and any help would be very
welcome. My program jumps between subroutines that represent
different options on a menu. Each subroutine puts a string on the LCD
using com3.

The problem I get is that after an exact number of LCD updates the
program either just hangs or resets itself. The number of updates
varies from about 8 to 21 and seems to be affected by the size of
queue defined for com3out. If you take a different path through my
menu the problem still occurs after the same number of updates.

I am writing to the LCD using putqueuestr(com3out, ...).

I have tried the following - with no effects whatsoever on the
problem;

1. Flushing and priming com3 before writing to it (using some code I
found in the files section on this site)

2. Sticking in delays and sleeps before/after com3 commands

Am I overloading a buffer ?

Thanks for any help you can give me,

CharlieM
">http://docs.yahoo.com/info/terms/



Hi Guys
I am experiencing exactly the same problem. I have a
device with two seriial LCDs and a RS485 link, so I am using three
different com3 ports. Likewise I've tried numerous fixes but still get
a rest about 2-3 times a day. I don't have any tasking or interrupts,
and nowhere do I call a subroutine from within another subroutine. My
prgram consists of a main loop, which calls a number of subroutines.
the problem is definetly in the swapping between conm3 ports and writing
to com3, but at this atge I'm not sure where. In order to wiat until a
queue was empty I used :
dowhile statusqueue (outwardbuffer)
loop
but this made things worse, which puzzled me. i now have a short delay
after each coms routine, but that's clumsy. Shall we swap code Charlie
and compare?
neil
Harry J. White wrote:

> You might want to look at another part of your program. If you are
> using a
> lot of subroutines and they call each other then you may be running out of
> stack space and that would cause the program to hang. Just a thought.
> Harry
>
> -----Original Message-----
> From: charliem101101 [mailto:]
> Sent: Wednesday, October 08, 2003 6:38 AM
> To:
> Subject: [BasicX] Program hanging/resetting after a number of LCD com3
> string outputs > Hi all,
>
> I am having trouble with a program and any help would be very
> welcome. My program jumps between subroutines that represent
> different options on a menu. Each subroutine puts a string on the LCD
> using com3.
>
> The problem I get is that after an exact number of LCD updates the
> program either just hangs or resets itself. The number of updates
> varies from about 8 to 21 and seems to be affected by the size of
> queue defined for com3out. If you take a different path through my
> menu the problem still occurs after the same number of updates.
>
> I am writing to the LCD using putqueuestr(com3out, ...).
>
> I have tried the following - with no effects whatsoever on the
> problem;
>
> 1. Flushing and priming com3 before writing to it (using some code I
> found in the files section on this site)
>
> 2. Sticking in delays and sleeps before/after com3 commands
>
> Am I overloading a buffer ?
>
> Thanks for any help you can give me,
>
> CharlieM >
> ">http://docs.yahoo.com/info/terms/ >
> <http://ashnin.com/clk/muryutaitakenattogyo?YH707890&yhad95053" target="_blank" rel="nofollow">http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S06554205:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogyo?YH707890&yhad95053 >
> ">http://docs.yahoo.com/info/terms/>.



Neil,

In addition to just waiting for the queues to empty, you also have to wait
for the UART to finish pushing the byte out and down the wire before you
float that com port away to another pin. I'll bet your reset is due to
that. You move that com3 three away before transmission is completed fully.

I have some code I will post. See if it fits your needs.
It works for any pin, any queue.
Give me a bit to pull from CD and strip out unrelated code.

.db. -----Original Message-----
From: Neil Jepsen [mailto:]
Sent: Wednesday, October 08, 2003 12:43 PM
To:
Subject: Re: [BasicX] Program hanging/resetting after a number of LCD com3
string outputs Hi Guys
I am experiencing exactly the same problem. I have a
device with two seriial LCDs and a RS485 link, so I am using three
different com3 ports. Likewise I've tried numerous fixes but still get
a rest about 2-3 times a day. I don't have any tasking or interrupts,
and nowhere do I call a subroutine from within another subroutine. My
prgram consists of a main loop, which calls a number of subroutines.
the problem is definetly in the swapping between conm3 ports and writing
to com3, but at this atge I'm not sure where. In order to wiat until a
queue was empty I used :
dowhile statusqueue (outwardbuffer)
loop
but this made things worse, which puzzled me. i now have a short delay
after each coms routine, but that's clumsy. Shall we swap code Charlie
and compare?
neil
Harry J. White wrote:

> You might want to look at another part of your program. If you are
> using a
> lot of subroutines and they call each other then you may be running out of
> stack space and that would cause the program to hang. Just a thought.
> Harry
>
> -----Original Message-----
> From: charliem101101 [mailto:]
> Sent: Wednesday, October 08, 2003 6:38 AM
> To:
> Subject: [BasicX] Program hanging/resetting after a number of LCD com3
> string outputs > Hi all,
>
> I am having trouble with a program and any help would be very
> welcome. My program jumps between subroutines that represent
> different options on a menu. Each subroutine puts a string on the LCD
> using com3.
>
> The problem I get is that after an exact number of LCD updates the
> program either just hangs or resets itself. The number of updates
> varies from about 8 to 21 and seems to be affected by the size of
> queue defined for com3out. If you take a different path through my
> menu the problem still occurs after the same number of updates.
>
> I am writing to the LCD using putqueuestr(com3out, ...).
>
> I have tried the following - with no effects whatsoever on the
> problem;
>
> 1. Flushing and priming com3 before writing to it (using some code I
> found in the files section on this site)
>
> 2. Sticking in delays and sleeps before/after com3 commands
>
> Am I overloading a buffer ?
>
> Thanks for any help you can give me,
>
> CharlieM >
> ">http://docs.yahoo.com/info/terms/ >
>
<http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
o?YH707890
<http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
o?YH707890&yhad95053> &yhad95053>
> ">http://docs.yahoo.com/info/terms/>.
<http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
o?YH707890&yhad95053> Click Here!

<http://us.adserver.yahoo.com/l?M$4522.3707890.4968055.1261774/D=egroupmai
l/S=:HM/A95053/rand5759174>

">http://docs.yahoo.com/info/terms/> .




Yeah I'm aware of that Dan but I'm only sending a few bytes, and I have
tried a delay after the dowhile loop to empty the uart which seemed
not to help too much. If I jerk the com3 away too quickly, then
characters appear on the wrong LCD but it doesn't cause a crash.
However I hope you are right .
I presume the bit of code you refer to is
do while ( rampeek(cuInt(Com3Status))and
bx0100_0000)=bx0100_0000)
loop
I'll try it.
neil Dan Bielecki wrote:

> Neil,
>
> In addition to just waiting for the queues to empty, you also have to wait
> for the UART to finish pushing the byte out and down the wire before you
> float that com port away to another pin. I'll bet your reset is due to
> that. You move that com3 three away before transmission is completed
> fully.
>
> I have some code I will post. See if it fits your needs.
> It works for any pin, any queue.
> Give me a bit to pull from CD and strip out unrelated code.
>
> .db. > -----Original Message-----
> From: Neil Jepsen [mailto:]
> Sent: Wednesday, October 08, 2003 12:43 PM
> To:
> Subject: Re: [BasicX] Program hanging/resetting after a number of LCD com3
> string outputs > Hi Guys
> I am experiencing exactly the same problem. I have a
> device with two seriial LCDs and a RS485 link, so I am using three
> different com3 ports. Likewise I've tried numerous fixes but still get
> a rest about 2-3 times a day. I don't have any tasking or interrupts,
> and nowhere do I call a subroutine from within another subroutine. My
> prgram consists of a main loop, which calls a number of subroutines.
> the problem is definetly in the swapping between conm3 ports and writing
> to com3, but at this atge I'm not sure where. In order to wiat until a
> queue was empty I used :
> dowhile statusqueue (outwardbuffer)
> loop
> but this made things worse, which puzzled me. i now have a short delay
> after each coms routine, but that's clumsy. Shall we swap code Charlie
> and compare?
> neil >
> Harry J. White wrote:
>
> > You might want to look at another part of your program. If you are
> > using a
> > lot of subroutines and they call each other then you may be running
> out of
> > stack space and that would cause the program to hang. Just a thought.
> > Harry
> >
> > -----Original Message-----
> > From: charliem101101 [mailto:]
> > Sent: Wednesday, October 08, 2003 6:38 AM
> > To:
> > Subject: [BasicX] Program hanging/resetting after a number of LCD com3
> > string outputs
> >
> >
> > Hi all,
> >
> > I am having trouble with a program and any help would be very
> > welcome. My program jumps between subroutines that represent
> > different options on a menu. Each subroutine puts a string on the LCD
> > using com3.
> >
> > The problem I get is that after an exact number of LCD updates the
> > program either just hangs or resets itself. The number of updates
> > varies from about 8 to 21 and seems to be affected by the size of
> > queue defined for com3out. If you take a different path through my
> > menu the problem still occurs after the same number of updates.
> >
> > I am writing to the LCD using putqueuestr(com3out, ...).
> >
> > I have tried the following - with no effects whatsoever on the
> > problem;
> >
> > 1. Flushing and priming com3 before writing to it (using some code I
> > found in the files section on this site)
> >
> > 2. Sticking in delays and sleeps before/after com3 commands
> >
> > Am I overloading a buffer ?
> >
> > Thanks for any help you can give me,
> >
> > CharlieM
> >
> >
> >
> >
> >
> >
> > ">http://docs.yahoo.com/info/terms/
> >
> >
> >
> >
> >
> >
> >
> <http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
> 05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
> o?YH707890
> <http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
> 05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
> o?YH707890&yhad95053> &yhad95053>
> >
> >
> >
> > ">http://docs.yahoo.com/info/terms/>. >
> <http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
> 05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
> o?YH707890&yhad95053> Click Here!
>
> <http://us.adserver.yahoo.com/l?M$4522.3707890.4968055.1261774/D=egroupmai
> l/S=:HM/A95053/rand5759174>
>
> ">http://docs.yahoo.com/info/terms/> . >
>
> Yahoo! Groups Sponsor
> <http://hits.411web.com/cgi-bin/autoredir?campU6&lineid614674&prop=egroupweb&pos=HM" target="_blank" rel="nofollow">http://rd.yahoo.com/M%9395.3614674.4902533.1261774/D=egroupweb/S06554205:HM/A24963/R=0/SIGo885gmo/*http://hits.411web.com/cgi-bin/autoredir?campU6&lineid614674&prop=egroupweb&pos=HM >
> ">http://docs.yahoo.com/info/terms/>.



Very similar.
But I have a call to DELAY in there so that the BX task-swaps and the bxOS
has a chance to do its thing during that time. I will post it tonight.

.db.

-----Original Message-----
From: Neil Jepsen [mailto:]
Sent: Wednesday, October 08, 2003 6:53 PM
To:
Subject: Re: [BasicX] Program hanging/resetting after a number of LCD com3
string outputs Yeah I'm aware of that Dan but I'm only sending a few bytes, and I have
tried a delay after the dowhile loop to empty the uart which seemed
not to help too much. If I jerk the com3 away too quickly, then
characters appear on the wrong LCD but it doesn't cause a crash.
However I hope you are right .
I presume the bit of code you refer to is
do while ( rampeek(cuInt(Com3Status))and
bx0100_0000)=bx0100_0000)
loop
I'll try it.
neil Dan Bielecki wrote:

> Neil,
>
> In addition to just waiting for the queues to empty, you also have to wait
> for the UART to finish pushing the byte out and down the wire before you
> float that com port away to another pin. I'll bet your reset is due to
> that. You move that com3 three away before transmission is completed
> fully.
>
> I have some code I will post. See if it fits your needs.
> It works for any pin, any queue.
> Give me a bit to pull from CD and strip out unrelated code.
>
> .db. > -----Original Message-----
> From: Neil Jepsen [mailto:]
> Sent: Wednesday, October 08, 2003 12:43 PM
> To:
> Subject: Re: [BasicX] Program hanging/resetting after a number of LCD com3
> string outputs > Hi Guys
> I am experiencing exactly the same problem. I have a
> device with two seriial LCDs and a RS485 link, so I am using three
> different com3 ports. Likewise I've tried numerous fixes but still get
> a rest about 2-3 times a day. I don't have any tasking or interrupts,
> and nowhere do I call a subroutine from within another subroutine. My
> prgram consists of a main loop, which calls a number of subroutines.
> the problem is definetly in the swapping between conm3 ports and writing
> to com3, but at this atge I'm not sure where. In order to wiat until a
> queue was empty I used :
> dowhile statusqueue (outwardbuffer)
> loop
> but this made things worse, which puzzled me. i now have a short delay
> after each coms routine, but that's clumsy. Shall we swap code Charlie
> and compare?
> neil >
> Harry J. White wrote:
>
> > You might want to look at another part of your program. If you are
> > using a
> > lot of subroutines and they call each other then you may be running
> out of
> > stack space and that would cause the program to hang. Just a thought.
> > Harry
> >
> > -----Original Message-----
> > From: charliem101101 [mailto:]
> > Sent: Wednesday, October 08, 2003 6:38 AM
> > To:
> > Subject: [BasicX] Program hanging/resetting after a number of LCD com3
> > string outputs
> >
> >
> > Hi all,
> >
> > I am having trouble with a program and any help would be very
> > welcome. My program jumps between subroutines that represent
> > different options on a menu. Each subroutine puts a string on the LCD
> > using com3.
> >
> > The problem I get is that after an exact number of LCD updates the
> > program either just hangs or resets itself. The number of updates
> > varies from about 8 to 21 and seems to be affected by the size of
> > queue defined for com3out. If you take a different path through my
> > menu the problem still occurs after the same number of updates.
> >
> > I am writing to the LCD using putqueuestr(com3out, ...).
> >
> > I have tried the following - with no effects whatsoever on the
> > problem;
> >
> > 1. Flushing and priming com3 before writing to it (using some code I
> > found in the files section on this site)
> >
> > 2. Sticking in delays and sleeps before/after com3 commands
> >
> > Am I overloading a buffer ?
> >
> > Thanks for any help you can give me,
> >
> > CharlieM
> >
> >
> >
> >
> >
> >
> > ">http://docs.yahoo.com/info/terms/
> >
> >
> >
> >
> >
> >
> >
>
<http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
>
05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
> o?YH707890
>
<http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
>
05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
> o?YH707890&yhad95053> &yhad95053>
> >
> >
> >
> > ">http://docs.yahoo.com/info/terms/>. >
>
<http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
>
05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
> o?YH707890&yhad95053> Click Here! <http://us.adserver.yahoo.com/l?M$4522.3707890.4968055.1261774/D=egroupmai
> l/S=:HM/A95053/rand5759174>
>
> ">http://docs.yahoo.com/info/terms/> .
<http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
o?YH707890&yhad95053> Click Here!

<http://us.adserver.yahoo.com/l?M$4522.3707890.4968055.1261774/D=egroupmai
l/S=:HM/A95053/randT1078398>

">http://docs.yahoo.com/info/terms/> .



Neil, Heres what I use before I float away from the port:
***
'---
--------
' Project: AIUnit/OS
' AIUnit Operating System Library Object - WaitForTXC
' Version: 2.0
' Created: April 2001
' Revised: April 2002
' Author: Dan Bielecki
' Studio.db.
'
' Syntax: Call WaitForTXC(port_number, queue_name)
'
' This utility waits for serial data to clear from the output
' queue and transmit out of the UART before returns to the caller.
'
' Copyright 2002 by Studio.db. and Dan Bielecki
' All rights Reserved.
'
'---
---------
Attribute VB_Name = "WaitForTXC"
Option Explicit
'---
---------
Sub WaitForTXC(ByVal Parm1 As Byte, ByRef Parm2() As Byte)

' WAIT FOR QUEUE TO EMPTY
Do While StatusQueue(Parm2) 'If data on the queue
Call Delay(0.00) 'Let other tasks run
Loop 'Until no data left on
queue

' WAIT FOR DATA TO BE PUSHED OUT THE bxPORT UART
Select Case Parm1 'Select the port number
Case 1 'COM1 Port
Do Until ((Register.USR And bx01000000) = bx01000000) 'bytes in
UART?
Call Delay(0.00) 'Let other tasks run
Loop
Case 2 'COM2 Port
Do While ((Register.TIMSK And bx01000000) = bx01000000) 'bytes
in UART?
Call Delay(0.00) 'Let other tasks run
Loop
Case 3 'Com3 Port
Do While ((RAMpeek(CuInt(21)) And bx01000000) = bx01000000)
'Bytes in UART?
Call Delay(0.00) 'Let other tasks run
Loop
End Select

End Sub

*************
Hope this helps!

.db.

-----Original Message-----
From: Neil Jepsen [mailto:]
Sent: Wednesday, October 08, 2003 6:53 PM
To:
Subject: Re: [BasicX] Program hanging/resetting after a number of LCD com3
string outputs Yeah I'm aware of that Dan but I'm only sending a few bytes, and I have
tried a delay after the dowhile loop to empty the uart which seemed
not to help too much. If I jerk the com3 away too quickly, then
characters appear on the wrong LCD but it doesn't cause a crash.
However I hope you are right .
I presume the bit of code you refer to is
do while ( rampeek(cuInt(Com3Status))and
bx0100_0000)=bx0100_0000)
loop
I'll try it.
neil Dan Bielecki wrote:

> Neil,
>
> In addition to just waiting for the queues to empty, you also have to wait
> for the UART to finish pushing the byte out and down the wire before you
> float that com port away to another pin. I'll bet your reset is due to
> that. You move that com3 three away before transmission is completed
> fully.
>
> I have some code I will post. See if it fits your needs.
> It works for any pin, any queue.
> Give me a bit to pull from CD and strip out unrelated code.
>
> .db. > -----Original Message-----
> From: Neil Jepsen [mailto:]
> Sent: Wednesday, October 08, 2003 12:43 PM
> To:
> Subject: Re: [BasicX] Program hanging/resetting after a number of LCD com3
> string outputs > Hi Guys
> I am experiencing exactly the same problem. I have a
> device with two seriial LCDs and a RS485 link, so I am using three
> different com3 ports. Likewise I've tried numerous fixes but still get
> a rest about 2-3 times a day. I don't have any tasking or interrupts,
> and nowhere do I call a subroutine from within another subroutine. My
> prgram consists of a main loop, which calls a number of subroutines.
> the problem is definetly in the swapping between conm3 ports and writing
> to com3, but at this atge I'm not sure where. In order to wiat until a
> queue was empty I used :
> dowhile statusqueue (outwardbuffer)
> loop
> but this made things worse, which puzzled me. i now have a short delay
> after each coms routine, but that's clumsy. Shall we swap code Charlie
> and compare?
> neil >
> Harry J. White wrote:
>
> > You might want to look at another part of your program. If you are
> > using a
> > lot of subroutines and they call each other then you may be running
> out of
> > stack space and that would cause the program to hang. Just a thought.
> > Harry
> >
> > -----Original Message-----
> > From: charliem101101 [mailto:]
> > Sent: Wednesday, October 08, 2003 6:38 AM
> > To:
> > Subject: [BasicX] Program hanging/resetting after a number of LCD com3
> > string outputs
> >
> >
> > Hi all,
> >
> > I am having trouble with a program and any help would be very
> > welcome. My program jumps between subroutines that represent
> > different options on a menu. Each subroutine puts a string on the LCD
> > using com3.
> >
> > The problem I get is that after an exact number of LCD updates the
> > program either just hangs or resets itself. The number of updates
> > varies from about 8 to 21 and seems to be affected by the size of
> > queue defined for com3out. If you take a different path through my
> > menu the problem still occurs after the same number of updates.
> >
> > I am writing to the LCD using putqueuestr(com3out, ...).
> >
> > I have tried the following - with no effects whatsoever on the
> > problem;
> >
> > 1. Flushing and priming com3 before writing to it (using some code I
> > found in the files section on this site)
> >
> > 2. Sticking in delays and sleeps before/after com3 commands
> >
> > Am I overloading a buffer ?
> >
> > Thanks for any help you can give me,
> >
> > CharlieM
> >
> >
> >
> >
> >
> >
> > ">http://docs.yahoo.com/info/terms/
> >
> >
> >
> >
> >
> >
> >
>
<http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
>
05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
> o?YH707890
>
<http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
>
05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
> o?YH707890&yhad95053> &yhad95053>
> >
> >
> >
> > ">http://docs.yahoo.com/info/terms/>. >
>
<http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
>
05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
> o?YH707890&yhad95053> Click Here! <http://us.adserver.yahoo.com/l?M$4522.3707890.4968055.1261774/D=egroupmai
> l/S=:HM/A95053/rand5759174>
>
> ">http://docs.yahoo.com/info/terms/> .
<http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
o?YH707890&yhad95053> Click Here!

<http://us.adserver.yahoo.com/l?M$4522.3707890.4968055.1261774/D=egroupmai
l/S=:HM/A95053/randT1078398>

">http://docs.yahoo.com/info/terms/> .




They are the same. The important line is
Do While ((RAMpeek(CuInt(21)) And bx01000000) = bx01000000)

Dan Bielecki wrote:

> Neil, Heres what I use before I float away from the port:
> ***
> '---
> --------
> ' Project: AIUnit/OS
> ' AIUnit Operating System Library Object - WaitForTXC
> ' Version: 2.0
> ' Created: April 2001
> ' Revised: April 2002
> ' Author: Dan Bielecki
> ' Studio.db.
> '
> ' Syntax: Call WaitForTXC(port_number, queue_name)
> '
> ' This utility waits for serial data to clear from the output
> ' queue and transmit out of the UART before returns to the caller.
> '
> ' Copyright 2002 by Studio.db. and Dan Bielecki
> ' All rights Reserved.
> '
> '---
> ---------
> Attribute VB_Name = "WaitForTXC"
> Option Explicit
> '---
> ---------
> Sub WaitForTXC(ByVal Parm1 As Byte, ByRef Parm2() As Byte)
>
> ' WAIT FOR QUEUE TO EMPTY
> Do While StatusQueue(Parm2) 'If data on the queue
> Call Delay(0.00) 'Let other tasks run
> Loop 'Until no data
> left on
> queue
>
> ' WAIT FOR DATA TO BE PUSHED OUT THE bxPORT UART
> Select Case Parm1 'Select the port number
> Case 1 'COM1 Port
> Do Until ((Register.USR And bx01000000) = bx01000000) 'bytes in
> UART?
> Call Delay(0.00) 'Let other tasks run
> Loop
> Case 2 'COM2 Port
> Do While ((Register.TIMSK And bx01000000) = bx01000000)
> 'bytes
> in UART?
> Call Delay(0.00) 'Let other tasks run
> Loop
> Case 3 'Com3 Port
> Do While ((RAMpeek(CuInt(21)) And bx01000000) = bx01000000)
> 'Bytes in UART?
> Call Delay(0.00) 'Let other tasks run
> Loop
> End Select
>
> End Sub
>
> *************
> Hope this helps!
>
> .db. >
>
> -----Original Message-----
> From: Neil Jepsen [mailto:]
> Sent: Wednesday, October 08, 2003 6:53 PM
> To:
> Subject: Re: [BasicX] Program hanging/resetting after a number of LCD com3
> string outputs > Yeah I'm aware of that Dan but I'm only sending a few bytes, and I have
> tried a delay after the dowhile loop to empty the uart which seemed
> not to help too much. If I jerk the com3 away too quickly, then
> characters appear on the wrong LCD but it doesn't cause a crash.
> However I hope you are right .
> I presume the bit of code you refer to is
> do while ( rampeek(cuInt(Com3Status))and
> bx0100_0000)=bx0100_0000)
> loop
> I'll try it.
> neil > Dan Bielecki wrote:
>
> > Neil,
> >
> > In addition to just waiting for the queues to empty, you also have
> to wait
> > for the UART to finish pushing the byte out and down the wire before you
> > float that com port away to another pin. I'll bet your reset is due to
> > that. You move that com3 three away before transmission is completed
> > fully.
> >
> > I have some code I will post. See if it fits your needs.
> > It works for any pin, any queue.
> > Give me a bit to pull from CD and strip out unrelated code.
> >
> > .db.
> >
> >
> > -----Original Message-----
> > From: Neil Jepsen [mailto:]
> > Sent: Wednesday, October 08, 2003 12:43 PM
> > To:
> > Subject: Re: [BasicX] Program hanging/resetting after a number of
> LCD com3
> > string outputs
> >
> >
> > Hi Guys
> > I am experiencing exactly the same problem. I have a
> > device with two seriial LCDs and a RS485 link, so I am using three
> > different com3 ports. Likewise I've tried numerous fixes but still get
> > a rest about 2-3 times a day. I don't have any tasking or interrupts,
> > and nowhere do I call a subroutine from within another subroutine. My
> > prgram consists of a main loop, which calls a number of subroutines.
> > the problem is definetly in the swapping between conm3 ports and writing
> > to com3, but at this atge I'm not sure where. In order to wiat until a
> > queue was empty I used :
> > dowhile statusqueue (outwardbuffer)
> > loop
> > but this made things worse, which puzzled me. i now have a short delay
> > after each coms routine, but that's clumsy. Shall we swap code Charlie
> > and compare?
> > neil
> >
> >
> >
> > Harry J. White wrote:
> >
> > > You might want to look at another part of your program. If you are
> > > using a
> > > lot of subroutines and they call each other then you may be running
> > out of
> > > stack space and that would cause the program to hang. Just a thought.
> > > Harry
> > >
> > > -----Original Message-----
> > > From: charliem101101 [mailto:]
> > > Sent: Wednesday, October 08, 2003 6:38 AM
> > > To:
> > > Subject: [BasicX] Program hanging/resetting after a number of LCD com3
> > > string outputs
> > >
> > >
> > > Hi all,
> > >
> > > I am having trouble with a program and any help would be very
> > > welcome. My program jumps between subroutines that represent
> > > different options on a menu. Each subroutine puts a string on the LCD
> > > using com3.
> > >
> > > The problem I get is that after an exact number of LCD updates the
> > > program either just hangs or resets itself. The number of updates
> > > varies from about 8 to 21 and seems to be affected by the size of
> > > queue defined for com3out. If you take a different path through my
> > > menu the problem still occurs after the same number of updates.
> > >
> > > I am writing to the LCD using putqueuestr(com3out, ...).
> > >
> > > I have tried the following - with no effects whatsoever on the
> > > problem;
> > >
> > > 1. Flushing and priming com3 before writing to it (using some code I
> > > found in the files section on this site)
> > >
> > > 2. Sticking in delays and sleeps before/after com3 commands
> > >
> > > Am I overloading a buffer ?
> > >
> > > Thanks for any help you can give me,
> > >
> > > CharlieM
> > >
> > >
> > >
> > >
> > >
> > >
> > > ">http://docs.yahoo.com/info/terms/
> > >
> > >
> > >
> > >
> > >
> > >
> > >
> >
> <http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
> >
> 05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
> > o?YH707890
> >
> <http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
> >
> 05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
> > o?YH707890&yhad95053> &yhad95053>
> > >
> > >
> > >
> > > ">http://docs.yahoo.com/info/terms/>.
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> <http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
> >
> 05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
> > o?YH707890&yhad95053> Click Here!
> >
> >
> <http://us.adserver.yahoo.com/l?M$4522.3707890.4968055.1261774/D=egroupmai
> > l/S=:HM/A95053/rand5759174>
> >
> > ">http://docs.yahoo.com/info/terms/> .
> >
> >
> >
> >
> >
> >
> >
> >
>
> <http://rd.yahoo.com/M$4522.3707890.4968055.1261774/D=egroupweb/S065542
> 05:HM/A95053/R=0/SIG4gf29oe/*http://ashnin.com/clk/muryutaitakenattogy
> o?YH707890&yhad95053> Click Here!
>
> <http://us.adserver.yahoo.com/l?M$4522.3707890.4968055.1261774/D=egroupmai
> l/S=:HM/A95053/randT1078398>
>
> ">http://docs.yahoo.com/info/terms/> . >
>
> Yahoo! Groups Sponsor
> <http://hits.411web.com/cgi-bin/autoredir?campU6&lineid614674&prop=egroupweb&pos=HM" target="_blank" rel="nofollow">http://rd.yahoo.com/M%9395.3614674.4902533.1261774/D=egroupweb/S06554205:HM/A24963/R=0/SIGo885gmo/*http://hits.411web.com/cgi-bin/autoredir?campU6&lineid614674&prop=egroupweb&pos=HM >
> ">http://docs.yahoo.com/info/terms/>.



From: Harry J. White <>
>
> From: charliem101101 [mailto:]
>
>> The problem I get is that after an exact number of LCD
>> updates the program either just hangs or resets itself.
>> The number of updates varies from about 8 to 21 and
>> seems to be affected by the size of queue defined for
>> com3out. If you take a different path through my
>> menu the problem still occurs after the same number of
>> updates.
>>
>> I am writing to the LCD using putqueuestr(com3out, ...).

Well, if I were you I'd avoid using PutQueueStr unless there is a
very good reason to use it, such as communicate to another task,
or get the highest possible speed. PutQueueStr is expensive in
RAM.

> You might want to look at another part of your program.
> If you are using a lot of subroutines and they call
> each other then you may be running out of stack space
> and that would cause the program to hang. Just a thought.

This would be my guess, too. This problem (and Neil's) have the
symptoms of a stack overflow.

Flattening the call tree and avoiding local variables can
sometimes work, depending on the overall program structure.

More often, though, I think it makes more sense to minimize the
use of static variables and use local variables as much as
possible. As an example, if you have the new V2.1 IDE, try
creating a new serial LCD project (menu New Project --
SerialLCD2x16). Module LCDSerialPort handles all 3 BasicX com
ports and includes code that flushes the serial ports. It may be
easy to adapt to your needs.

The code also minimizes the use of static variables. The variables
take up 30 bytes, which leaves 371 bytes for the main stack. When
you call LCD code, maybe 88 bytes of that stack space is used.
That sounds like a lot, except that whenever you return from that
code, that leaves all 371 bytes available for whatever else you
need to do.

Listed below is an example program that illustrates how much stack
is used by the LCD code:

-- Frank Manning
-- NetMedia, Inc.

'-----------
Option Explicit

Private Const StackSize As Integer = 110
Private TaskStack(1 To StackSize) As Byte
Private Done As Boolean
'-----------
Public Sub Main()

Dim LimitFound As Boolean
Dim N As Integer

' This is an example value to load into the
' task stack. For completeness, this test
' should be repeated as required with
' different random values.
Const TestValue As Byte = 255

Done = False

For N = 1 To StackSize
TaskStack(N) = TestValue
Next

CallTask "Main2", TaskStack

Do Until (Done)
' Null
Loop

' This is in case the task isn't really done yet.
LockTask

Debug.Print
Debug.Print

Debug.Print "Stack use = ";

LimitFound = False
For N = StackSize To 1 Step -1
If (TaskStack(N) <> TestValue) Then
Debug.Print CStr(N) & " bytes"
LimitFound = True
Exit For
End If
Next

If (Not LimitFound) Then
Debug.Print "*** Error ***"
End If

Debug.Print
Debug.Print "Stack contents:"
Debug.Print
Debug.Print " Index Value"
Debug.Print

For N = 1 To StackSize
Debug.Print " "; CStr(N); " ";
Debug.Print CStr(TaskStack(N))
Next

Debug.Print

End Sub
'-----------
Private Sub Main2()

Const PortNumber As Byte = 1
Dim Column As Byte
Const Square As Byte = 219

Call LCDInitialize(PortNumber, 9600, 0, 0)

Call LCDMoveCursor(1, 1)
Call LCDPutStr(" LCD2x16")

For Column = 1 To MaxColumn
Call LCDMoveCursor(2, Column)
Call LCDPutByte(Square)
Call Delay(0.05)
Next
For Column = 1 To MaxColumn
Call LCDMoveCursor(2, Column)
Call LCDPutStr(" ")
Call Delay(0.05)
Next

Done = True

End Sub
'-----------


From: Dan Bielecki <>

> Very similar. But I have a call to DELAY in there
> so that the BX task-swaps and the bxOS has a chance
> to do its thing during that time.

I'd be surprised if that makes a difference, since Neil is not
using tasking.

-- Frank Manning
-- NetMedia, Inc.