Newbie Questioin about Serial I/O

Started by itisnt March 21, 2004
Hi

I just bought a BasicX-24 to replace the
BasicStamp on my HexCrawler Robot (www.crustcrawler.com).

Now i realised that i cannot use every I/O Pin as a RS/232
Connection as on the BasicStamp.

Is that true ?

I need a serial Connection to my Mini-SSC (Servo-Controller)
and to my LCD.

Can i use Com1 in parallel with my PC and the LCD for example ?
Of course without "Debug.print" Commands.
Are there any Code-Fragments around for such a setup ?

Thanks for every Answer

Daniel



itisnt wrote:

> Hi
>
> I just bought a BasicX-24 to replace the
> BasicStamp on my HexCrawler Robot (www.crustcrawler.com).
>
> Now i realised that i cannot use every I/O Pin as a RS/232
> Connection as on the BasicStamp.
>
> Is that true ?
> NO YOU CAN USE AS MANY AS YOU LIKE
> I need a serial Connection to my Mini-SSC (Servo-Controller)
> and to my LCD.
>
> Can i use Com1 in parallel with my PC and the LCD for example ?

YES BUT I'D USE COM23 ON TWO DIFFERENT I/O PINS

> Of course without "Debug.print" Commands.
> Are there any Code-Fragments around for such a setup ?
> HEAPS
> Thanks for every Answer
>
> Daniel >
> *
> <http://ashnin.com/clk/muryutaitakenattogyo?YHE21611&yhad50447" target="_blank" rel="nofollow">http://rd.yahoo.com/SIGcoiar9s/M&8585.4521611.5694062.1261774/D=egroupweb/S06554205:HM/EXP79982533/A50447/R=0/SIG45hvqf1/*http://ashnin.com/clk/muryutaitakenattogyo?YHE21611&yhad50447 >
>
> *>.




--- In , "itisnt" <itisnt@y...> wrote:
> I need a serial Connection to my Mini-SSC (Servo-Controller)
> and to my LCD.

Is your LCD serial in the sense of RS-232 (i.e. baud, start bits,
stop bits, etc.) or does it have a clock and data line? If the
latter is the case, any pin can be used for serial I/O (by way of
ShiftIn() and ShiftOut() calls).

If you need to communicate via COMn, you can multiplex the serial
output easily enough. Doing so for serial input is a little more
difficult unless you have some control over when the devices will be
sending (as is probably the case with the LCD at least).


--- In , "itisnt" <itisnt@y...> wrote:
> Hi
>
> I just bought a BasicX-24 to replace the
> BasicStamp on my HexCrawler Robot (www.crustcrawler.com).
>
> Now i realised that i cannot use every I/O Pin as a RS/232
> Connection as on the BasicStamp.
>
> Is that true ?
>
No.

First I assume you mean serial comm in general as neither chip have
RS232 levels at more than one port.

If I remember BS correctly you can use any pin, but as BS doesn't
have buffering or background tasks you can only use one pin at a
time and then only for input or output.

BX can use two ports simultainously and in full duplex as the comm
is handled in the background (or interupt driven).

I.e. If you want to use your BX as you used the BS, communicating
with one device at a time, you can do it on any pin, just by
redefine the COM3 pin to be used. Just a few lines of extra code.

Rgds
Ingvar



Yes i think you are right, i mean serial comm not necessarily
with RS232 Levels.

The reason i switched to BX is the Multitasking. I have
to "serial" Devices:
- Serial LCD+ from Netmedia
- Mini SSC II Serial Servo Controller (controls 12 Servos)

The rest is one Ultrasonic Sensor and two IR-Sensors, all three
are not serial Devices.

What i would like to implement is one Task for the
"Walking" and another Task for the Sensor-Scanning.
The Main-Programm runs in Loop, checks Button-Activity,
displays System-status, Sensor-Values .....

On a BasicStamp, the command to the Mini SSC looks like this:
SEROUT Pin, Baud, [254, NumberOfServo, Position]
That mean, i have to send one sync Byte (254), the number of the
Servo and the position of the servo.

So i think sharing COM3 with both Devices wouldn't be a good
idea.

Any Idea what the best Hardware-Layout would be ?

Daniel

--- In , "Ingvar Esk" <ingvar.esk@s...> wrote:
> --- In , "itisnt" <itisnt@y...> wrote:
> > Hi
> >
> > I just bought a BasicX-24 to replace the
> > BasicStamp on my HexCrawler Robot (www.crustcrawler.com).
> >
> > Now i realised that i cannot use every I/O Pin as a RS/232
> > Connection as on the BasicStamp.
> >
> > Is that true ?
> >
> No.
>
> First I assume you mean serial comm in general as neither chip have
> RS232 levels at more than one port.
>
> If I remember BS correctly you can use any pin, but as BS doesn't
> have buffering or background tasks you can only use one pin at a
> time and then only for input or output.
>
> BX can use two ports simultainously and in full duplex as the comm
> is handled in the background (or interupt driven).
>
> I.e. If you want to use your BX as you used the BS, communicating
> with one device at a time, you can do it on any pin, just by
> redefine the COM3 pin to be used. Just a few lines of extra code.
>
> Rgds
> Ingvar




From: itisnt <>

> [...]
> I have to "serial" Devices:
> - Serial LCD+ from Netmedia
> - Mini SSC II Serial Servo Controller (controls 12 Servos)
> [...]
> the command to the Mini SSC looks like this:
> SEROUT Pin, Baud, [254, NumberOfServo, Position]
> That mean, i have to send one sync Byte (254),
> the number of the Servo and the position of the
> servo.
>
> So i think sharing COM3 with both Devices
> wouldn't be a good idea.

It's not difficult at all. To get started, probably the easiest
solution might be to use the LCD+ example code built into the
V2.1 compiler. Module LCDPlusSerialPort can be used as-is by the
servo controller.

High level code might look something like this:

Call SetSSCPort

Call LCDPutByte(SyncByte)
Call LCDPutByte(NumberOfServo)
Call LCDPutByte(Position)

Call SetLCDPort

Whenever the program needs to move the servo, SetSSCPort closes
Com3 and re-opens it with the SSC pins and baud rate. When you're
through with the servo, SetLCDPort closes Com3 again, and
re-opens it with the LCD pins and baud rate.

I haven't tested it, but the idea is to replace the LCD+ main
module with the code shown below.

Not as simple as SEROUT, but much more powerful and flexible.

-- Frank Manning
-- NetMedia, Inc.

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

Private Const PortNumber As Byte = 3
Private Const LCDInputPin As Byte = 16
Private Const LCDOutputPin As Byte = 17
Private Const LCDBaud As Long = 9600
'------------------
Public Sub Main()

Dim Column As Byte

Call LCDInitialize( _
PortNumber, LCDBaud, LCDInputPin, LCDOutputPin)

Call LCDMoveCursor(2, 1)
Call LCDPutStr(" LCD Plus")

Do
For Column = 1 To MaxColumn
Call LCDMoveCursor(1, Column)
Call LCDPutStr("=")
Call LCDMoveCursor(4, Column)
Call LCDPutStr("=")
Call Delay(0.02)
Next
For Column = 1 To MaxColumn
Call LCDMoveCursor(1, Column)
Call LCDPutStr(" ")
Call LCDMoveCursor(4, Column)
Call LCDPutStr(" ")
Call Delay(0.02)
Next

Call MoveServo(1, 128)
Loop

End Sub
'------------------
Private Sub MoveServo( _
ByVal NumberOfServo As Byte, _
ByVal Position As Byte)

Const SyncByte As Byte = 254

Call SetSSCPort

Call LCDPutByte(SyncByte)
Call LCDPutByte(NumberOfServo)
Call LCDPutByte(Position)

Call SetLCDPort

End Sub
'------------------
Private Sub SetLCDPort()

' This procedure switches Com3 to the LCD Plus.

Call LCDCloseSerialPort

Call LCDOpenSerialPort(PortNumber, LCDBaud, _
LCDInputPin, LCDOutputPin)

End Sub
'------------------
Private Sub SetSSCPort()

' This procedure switches Com3 to the SSC board.

Const SSCInputPin As Byte = 0 ' Dummy pin.
Const SSCOutputPin As Byte = 12
Const SSCBaud As Long = 2400

Call LCDCloseSerialPort

Call LCDOpenSerialPort( _
PortNumber, SSCBaud, SSCInputPin, SSCOutputPin)

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



Hi

Thanks for the Code, my small test-prog has the same
idea behind.
The problem is that in a walking robot the task who controls
the walking-gait creates a lot of servo-commands.
So i would have to stop the robot, display something and
let it walk again. Not realy what i want.

What about the idea of Don Kinzer ? With the shiftout() Command.
Sounds good, i think i'll try this the next night (0:46 am in
Switzerland....)

Regards

--- In , "Frank Manning" <fmanning@n...> wrote:
> From: itisnt <itisnt@y...>
>
> > [...]
> > I have to "serial" Devices:
> > - Serial LCD+ from Netmedia
> > - Mini SSC II Serial Servo Controller (controls 12 Servos)
> > [...]
> > the command to the Mini SSC looks like this:
> > SEROUT Pin, Baud, [254, NumberOfServo, Position]
> > That mean, i have to send one sync Byte (254),
> > the number of the Servo and the position of the
> > servo.
> >
> > So i think sharing COM3 with both Devices
> > wouldn't be a good idea.
>
> It's not difficult at all. To get started, probably the easiest
> solution might be to use the LCD+ example code built into the
> V2.1 compiler. Module LCDPlusSerialPort can be used as-is by the
> servo controller.
>
> High level code might look something like this:
>
> Call SetSSCPort
>
> Call LCDPutByte(SyncByte)
> Call LCDPutByte(NumberOfServo)
> Call LCDPutByte(Position)
>
> Call SetLCDPort
>
> Whenever the program needs to move the servo, SetSSCPort closes
> Com3 and re-opens it with the SSC pins and baud rate. When you're
> through with the servo, SetLCDPort closes Com3 again, and
> re-opens it with the LCD pins and baud rate.
>
> I haven't tested it, but the idea is to replace the LCD+ main
> module with the code shown below.
>
> Not as simple as SEROUT, but much more powerful and flexible.
>
> -- Frank Manning
> -- NetMedia, Inc.
>
> '------------------
> Option Explicit
>
> Private Const PortNumber As Byte = 3
> Private Const LCDInputPin As Byte = 16
> Private Const LCDOutputPin As Byte = 17
> Private Const LCDBaud As Long = 9600
> '------------------
> Public Sub Main()
>
> Dim Column As Byte
>
> Call LCDInitialize( _
> PortNumber, LCDBaud, LCDInputPin, LCDOutputPin)
>
> Call LCDMoveCursor(2, 1)
> Call LCDPutStr(" LCD Plus")
>
> Do
> For Column = 1 To MaxColumn
> Call LCDMoveCursor(1, Column)
> Call LCDPutStr("=")
> Call LCDMoveCursor(4, Column)
> Call LCDPutStr("=")
> Call Delay(0.02)
> Next
> For Column = 1 To MaxColumn
> Call LCDMoveCursor(1, Column)
> Call LCDPutStr(" ")
> Call LCDMoveCursor(4, Column)
> Call LCDPutStr(" ")
> Call Delay(0.02)
> Next
>
> Call MoveServo(1, 128)
> Loop
>
> End Sub
> '------------------
> Private Sub MoveServo( _
> ByVal NumberOfServo As Byte, _
> ByVal Position As Byte)
>
> Const SyncByte As Byte = 254
>
> Call SetSSCPort
>
> Call LCDPutByte(SyncByte)
> Call LCDPutByte(NumberOfServo)
> Call LCDPutByte(Position)
>
> Call SetLCDPort
>
> End Sub
> '------------------
> Private Sub SetLCDPort()
>
> ' This procedure switches Com3 to the LCD Plus.
>
> Call LCDCloseSerialPort
>
> Call LCDOpenSerialPort(PortNumber, LCDBaud, _
> LCDInputPin, LCDOutputPin)
>
> End Sub
> '------------------
> Private Sub SetSSCPort()
>
> ' This procedure switches Com3 to the SSC board.
>
> Const SSCInputPin As Byte = 0 ' Dummy pin.
> Const SSCOutputPin As Byte = 12
> Const SSCBaud As Long = 2400
>
> Call LCDCloseSerialPort
>
> Call LCDOpenSerialPort( _
> PortNumber, SSCBaud, SSCInputPin, SSCOutputPin)
>
> End Sub
> '------------------





From: itisnt <>

> Thanks for the Code, my small test-prog has the
> same idea behind.
> The problem is that in a walking robot the task
> who controls the walking-gait creates a lot of
> servo-commands. So i would have to stop the
> robot, display something and let it walk again.
> Not realy what i want.

Well, is SEROUT is fast enough?

I haven't measured it, but I'd be very surprised if switching
Com3 was slower. I'd guess Com3 can switch pins much faster than
SEROUT.

> What about the idea of Don Kinzer ? With the
> shiftout() Command.

If you're using the LCD+, I don't think ShiftOut would work,
since you need a separate clock pin.

-- Frank Manning
-- NetMedia, Inc.



--- In , "itisnt" <itisnt@y...> wrote:
> What about the idea ... [w]ith the shiftout() Command.

Since the LCD that you said you are using requires an RS-232 bit
sequence and timing, I don't think that that will work.

You could, however, use a parallel interface LCD instead. Many of
them can work in either 4-bit or 8-bit mode. Using it in 4-bit
parallel mode would require 7 I/O pins. If you add shift registers
to do the serial to parallel conversion you can get it down to 5 pins
or fewer. Some of these lines can be shared with other external
circuits, especially if you have other parallel devices that you need
to connect to.

I used a parallel interface LCD on my BX-24 Ethernet interface. The
Ethernet controller chip also has a parallel interface so much of the
circuitry is shared between the two. You can view the schematics on
the web page for it:
http://www.kinzers.com/don/BX24/Ethernet
> Sounds good, i think i'll try this the next night (0:46 am in
> Switzerland....)
>
> Regards
>
> --- In , "Frank Manning" <fmanning@n...>
wrote:
> > From: itisnt <itisnt@y...>
> >
> > > [...]
> > > I have to "serial" Devices:
> > > - Serial LCD+ from Netmedia
> > > - Mini SSC II Serial Servo Controller (controls 12 Servos)
> > > [...]
> > > the command to the Mini SSC looks like this:
> > > SEROUT Pin, Baud, [254, NumberOfServo, Position]
> > > That mean, i have to send one sync Byte (254),
> > > the number of the Servo and the position of the
> > > servo.
> > >
> > > So i think sharing COM3 with both Devices
> > > wouldn't be a good idea.
> >
> > It's not difficult at all. To get started, probably the easiest
> > solution might be to use the LCD+ example code built into the
> > V2.1 compiler. Module LCDPlusSerialPort can be used as-is by the
> > servo controller.
> >
> > High level code might look something like this:
> >
> > Call SetSSCPort
> >
> > Call LCDPutByte(SyncByte)
> > Call LCDPutByte(NumberOfServo)
> > Call LCDPutByte(Position)
> >
> > Call SetLCDPort
> >
> > Whenever the program needs to move the servo, SetSSCPort closes
> > Com3 and re-opens it with the SSC pins and baud rate. When you're
> > through with the servo, SetLCDPort closes Com3 again, and
> > re-opens it with the LCD pins and baud rate.
> >
> > I haven't tested it, but the idea is to replace the LCD+ main
> > module with the code shown below.
> >
> > Not as simple as SEROUT, but much more powerful and flexible.
> >
> > -- Frank Manning
> > -- NetMedia, Inc.
> >
> > '------------------
> > Option Explicit
> >
> > Private Const PortNumber As Byte = 3
> > Private Const LCDInputPin As Byte = 16
> > Private Const LCDOutputPin As Byte = 17
> > Private Const LCDBaud As Long = 9600
> > '------------------
> > Public Sub Main()
> >
> > Dim Column As Byte
> >
> > Call LCDInitialize( _
> > PortNumber, LCDBaud, LCDInputPin, LCDOutputPin)
> >
> > Call LCDMoveCursor(2, 1)
> > Call LCDPutStr(" LCD Plus")
> >
> > Do
> > For Column = 1 To MaxColumn
> > Call LCDMoveCursor(1, Column)
> > Call LCDPutStr("=")
> > Call LCDMoveCursor(4, Column)
> > Call LCDPutStr("=")
> > Call Delay(0.02)
> > Next
> > For Column = 1 To MaxColumn
> > Call LCDMoveCursor(1, Column)
> > Call LCDPutStr(" ")
> > Call LCDMoveCursor(4, Column)
> > Call LCDPutStr(" ")
> > Call Delay(0.02)
> > Next
> >
> > Call MoveServo(1, 128)
> > Loop
> >
> > End Sub
> > '------------------
> > Private Sub MoveServo( _
> > ByVal NumberOfServo As Byte, _
> > ByVal Position As Byte)
> >
> > Const SyncByte As Byte = 254
> >
> > Call SetSSCPort
> >
> > Call LCDPutByte(SyncByte)
> > Call LCDPutByte(NumberOfServo)
> > Call LCDPutByte(Position)
> >
> > Call SetLCDPort
> >
> > End Sub
> > '------------------
> > Private Sub SetLCDPort()
> >
> > ' This procedure switches Com3 to the LCD Plus.
> >
> > Call LCDCloseSerialPort
> >
> > Call LCDOpenSerialPort(PortNumber, LCDBaud, _
> > LCDInputPin, LCDOutputPin)
> >
> > End Sub
> > '------------------
> > Private Sub SetSSCPort()
> >
> > ' This procedure switches Com3 to the SSC board.
> >
> > Const SSCInputPin As Byte = 0 ' Dummy pin.
> > Const SSCOutputPin As Byte = 12
> > Const SSCBaud As Long = 2400
> >
> > Call LCDCloseSerialPort
> >
> > Call LCDOpenSerialPort( _
> > PortNumber, SSCBaud, SSCInputPin, SSCOutputPin)
> >
> > End Sub
> > '------------------




Frank
I often use several Com3 pins to talk to radios and Ser LCD
displays. Currently I am doing a project where I have a serial LCD+
and a serial UHF radio transceiver ( the master), with two out stations
a few miles away. The master station code puts new informtion to the
LCD once per second, and polls the out stations from time to time, about
every 5 seconds.
The PROBLEM that arises in that from time to time, an outstation will
give the master an uninitiated call, and the incoming data can screw up
the stack in the master. I have separate buffers for the LCD, radio
data-out and radio data-in. I've tried all sorts of tricks like
flushing buffers,do until empty, and turning com3 on and off, and
waiting for UARTs to finish etc, but its just not robust. The best I've
been able to do is update the LCD when I know there is a window of
opportunity when no radio data is likely to arrrive. But that's not
elegant.In fact its downright clumsy.
Any suggestions?

neil

Frank Manning wrote:

> From: itisnt <>
>
> > Thanks for the Code, my small test-prog has the
> > same idea behind.
> > The problem is that in a walking robot the task
> > who controls the walking-gait creates a lot of
> > servo-commands. So i would have to stop the
> > robot, display something and let it walk again.
> > Not realy what i want.
>
> Well, is SEROUT is fast enough?
>
> I haven't measured it, but I'd be very surprised if switching
> Com3 was slower. I'd guess Com3 can switch pins much faster than
> SEROUT.
>
> > What about the idea of Don Kinzer ? With the
> > shiftout() Command.
>
> If you're using the LCD+, I don't think ShiftOut would work,
> since you need a separate clock pin.
>
> -- Frank Manning
> -- NetMedia, Inc. > *
> <http://www.netflix.com/Default?mqso`178383&partidF73019" target="_blank" rel="nofollow">http://rd.yahoo.com/SIGcnmrqg3/M&7637.4673019.5833256.1261774/D=egroupweb/S06554205:HM/EXP80000010/A45638/R=0/SIGt2rh2cf/*http://www.netflix.com/Default?mqso`178383&partidF73019 >
>
> *>.