cancel
Showing results for 
Search instead for 
Did you mean: 

Can this be done with a STM32F103ZE

dubedat68
Associate II
Posted on March 16, 2015 at 13:17

Hello,

I have no experience at all with micro controllers & only brief experience with wiring up electronics / & some low-level programming, so please accept my apologies up-front.

I have a need to create a device that:

     a.  Has ONE (1) incoming RS232 port

     b.  Has FOUR (4) separate outgoing RS232 ports

     c.  ''reads'' an incoming RS232 stream,

     d.  look at the first 2 Bytes of info

     e.  check for the ''address'' (2nd byte)

      f.  if it is addressed ''FF 01 .........'', forward the complete original data out PORT 1 ONLY

     g.  if it is addressed ''FF 02 .........'' re-address the data to ''FF 01 ........'' and forward the complete data out PORT 2 ONLY

     h.  if it is addressed ''FF 03 .........'' 

re-address the data to ''FF 01 ........'' and forward the complete data out PORT 3 ONLY

      i.  if it is addressed ''FF 04 .........'' 

re-address the data to ''FF 01 ........'' and forward the complete data out PORT 4 ONLY

Here is a drawing of this for those who are more ''visual'' like me.

https://communities.intel.com/servlet/JiveServlet/showImage/2-284311-243094/PelcoD---prototype.jpg

The baud rate is 9600, 8, N, 1 (no flow control), if that helps.

Is this possible with the STM32F103ZE?

If so, would anyone be willing to ''tutor'' me in learning how to get this done?

If not, would anyone be able to suggest a more suitable platform to achieve it?

Many thanks in advance,

duBe

28 REPLIES 28
Posted on March 16, 2015 at 16:16

Looks to be something an STM32 part could do

You might want to refine your understanding of the protocol because ''

forward the complete data out

'' is only going to make sense if you can better quantify the length of the data coming in, which you protocol doesn't seem to convey.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dubedat68
Associate II
Posted on March 16, 2015 at 22:19

Thanks Clive1,

sorry, I'm really not au fait with this stuff, but I'm trying to understand it as best I can to hopefully get this device made (if possible).

So, to get the idea of what I wanted out there (without bogging down into the nitty-gritty straight-up), I thought it might be expedient to just explain, in rough terms, what I was trying to achieve with the device.

Here's what I know about the protocol (thanks to

http://www.commfront.com/RS232_Examples/CCTV/Pelco_D_Pelco_P_Examples_Tutorial.HTM

:(

The format of Pelco-D

Pelco-D command string examples

Pelco-D consists of 7 hexadecimal bytes (all byte data used in this page are in Hexadecimal format unless otherwise specified).

Byte 1

Byte 2

Byte 3

Byte 4

Byte 5

Byte 6

Byte 7

Sync

Camera Address

Command 1

Command 2

Data 1

Data 2

Checksum

  • Byte 1 (Sync) - the synchronization byte, fixed to FF
  • Byte 2 (Camera Address) - logical address of the camera being controlled (Address 1 is 01)
  • Byte 3 & 4 (Command 1 and 2) are shown below
  • Byte 5 (Data 1) - pan speed, range from 00 (stop) to 3F (high speed) and FF for ''turbo'' speed (the maximum pan speed that the device can go)
  • Byte 6 (Data 2) - tilt speed, range from 00 (stop) to 3F (maximum speed)
  • Byte 7 (Checksum) - sum of bytes (excluding the synchronization byte), then modulo 100 (Decimal code: 256)
  • Command 1 and 2 details

     

    Bit 7

    Bit 6

    Bit 5

    Bit 4

    Bit 3

    Bit 2

    Bit 1

    Bit 0

    Command 1

    Sense

    Reserved

    Reserved

    Auto / Manual Scan

    Camera On/Off

    Iris Close

    Iris Open

    Focus Near

    Command 2

    Focus Far

    Zoom Wide

    Zoom Tele

    Tilt Down

    Tilt Up

    Pan Left

    Pan Right

    Fixed to 0

    Example (Command 2):

Pan Left - 0 0 0 0 0 1 0 0, which equals to 04 (both hexadecimal and decimal)

Some other commands

Command

Byte 3

Byte 4

Byte 5

Byte 6

Go to Preset

00

07

00

01 to FF

Set Zoom Speed

00

25

00

00 to 33

Set Focus Speed

00

27

00

00 to 33

Alarm Ack.

00

19

00

Alarm no.

The format of Pelco-D

Pelco-D command string examples

Camera Address: 1

Pan Left at high speed: 

FF 01 00 04 3F 00 44

Pan Right at medium speed: 

FF 01 00 02 20 00 23

Tilt Up at high speed:

FF 01

00 08 00 20 AF 27

Tilt Down at medium speed: 

FF 01 00 10 20 00 31

Stop all actions (Pan/Tilt/Zoom/Iris etc.): 

FF 01 00 00 00 00 01

Note: there will be no response from cameras in Pelco-D protocol

So, as the I was only really interested in ''interrogating'' the ''Camera Address'' for the purpose of re-addressing & re-sending out different ports, that's why I only mentioned the first 2 bytes, as that's where the ''Camera Address''.

I realise you need more info to make informed opinions, sorry about that.

Many thanks,

duBe

Posted on March 16, 2015 at 23:30

That looks reasonably straight forward.

Little state machine to know if it's in/out of sync.

Wait for the sync byte, check the overall framing, ie sync thru checksum

Sequence through bytes as received, redirect to appropriate output port, change ID, and goose the checksum as that goes out to reflect the change in ID earlier.

So from 2 to 1, add -1 to the sum, 3 to 1 add -2, etc

Not sure what pin count device you're using, should have 5 usart/uart.

9600 baud shouldn't be a problem.

 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dubedat68
Associate II
Posted on March 16, 2015 at 23:56

Thanks Clive1,

I'm not going to lie, I think I understand, but I'm REALLY dumb with these things.

Whilst I'm fairly confident I understand the ''concept'' of what you've described (seems to accord with what I thought would need to occur), I really don't know where to begin to understand how to achieve the outcome.

From what I gather from your previous response, this might be actually something I could learn & apply in a reasonable time frame.

I originally did a Google search for a 5 UART micro-controller & that is what led me to this forum, in particular the STM32F103ZE.

Do you think this micro-controller will do the job?

Or is it even ''over-kill'' for this kind of project?

I see this micro-controller is only $20 or so, & that's not a problem, unless there are HEAP of other things I need as well to get it done that blows it out to hundreds of dollars.

Thanks again in advance,

duBe

Posted on March 17, 2015 at 01:16

In quantity this should be a sub $5 part.

3x MAX3232 or equivalent past for the RS232/CMOS conversion chips

http://pdfserv.maximintegrated.com/en/ds/MAX3222-MAX3241.pdf

The STM32F1 should be more than adequate. As you say the trick is to get the 5 UART you need, and the microprocessor control. You don't have to clock it at 72 MHz if power/heat is a consideration.

Software complexity, a roughly working prototype might take me several hours. 

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
dubedat68
Associate II
Posted on March 17, 2015 at 01:57

Sooooooo,

would that be something you would be interested in teaching me how to achieve?

Bearing in mind I really don't know ANYTHING about electronics / programming.

Or, would you be interested in designing it as a ''rough prototype'' with NOOBIE explanations for me to follow to hopefully be able to build, program, commission & understand how it works?

I don't know how much that kind of thing would cost me, but I'm up for paying you (of course I may not be able to afford your time - that's my biggest concern - I don't want to offend you if I can't afford it).

I guess, despite the practical outcome of the device itself, my biggest wish is to learn how this is done & to go on to design other stuff in the future myself.  So that's where I'm at really.

Cheers,

duBe

Danish1
Lead II
Posted on March 17, 2015 at 11:27

In my opinion that's really something that's better done face-to-face rather than over the internet.

An example of why is that there are occasional problems which are very much easier to diagnose with (relatively) expensive equipment such as oscilloscopes.

And face-to-face you could borrow my (or whoever's) oscilloscope, or I could do the test myself and identify and tell you the problem. This can quickly show if e.g. a bad-looking solder joint is actually misbehaving.

Since you say you don't have a lot of electronics experience, I will say that STM32 (or any for the ARM families from different manufacturers) is not the easiest thing to get started with simply because it is very powerful, and with that power there's quite a lot you have to get right before anything seems to work. But I think your requirement of 5 RS232 ports means that you will have to end up using a fairly powerful microcontroller.

There are several things to get your system working:

The hardware platform (either your own circuit board, or a demo board from one of the electronic component suppliers)

The program (which you write, specific to your needs)

The programming/debugging environment (compiler/editor running on your PC, interface onto the hardware platform)

A problem is that they all have to be right in order for anything to usefully happen. So it's great if there's a ''known-good'' system to swap with yours. And again that can be done face-to-face.

I did not see where you are based. Have you looked on the internet to see if there is a nearby electronics / computing club you might join? Have you visited Maker fairs or similar?

As to your intended problem, 5 RS232 ports (also known as UARTs or USARTs) is more than you often find on a demo board. Yes the microcontroller might have that many ports, but very often the pins that can be used for RS232, are also shared with another function (for example USB) and the demo board will only have 2 or 3 of the ports wired up to be RS232 and the remainder wired as USB.

A different possible approach would be to only use TWO UARTs, and have the microcontroller also output control signals that switch the output UART to whichever camera it currently wants to talk to. This is a technique known as Multiplexing, and it is relatively easy to do this in e.g. the prototyping area of a demo board such as https://www.olimex.com/Products/ARM/ST/STM32-P103/ (there are ''analog switch'' ICs).

I do have a few years experience, but for every new board I design, the first goal is simply to get one LED on the board to flash under my program's control. And that's not always easy for me.

Hope this helps,

Danish

dubedat68
Associate II
Posted on March 17, 2015 at 12:34

Thanks Danish,

I know you're right about ''face-to-face'', my biggest problem there is I live in a remote area of Victoria Australia and with work and a handicapped daughter to look after, I really don't get much time for these kind of pursuits.

So, if I can't get it done myself or with help from awesome forums like this, I really struggle to get ''hands-on'' help.

That being that, I'm trying my best to find a solution to this whilst I'm at home with my daughter.  It's manageable for me to keep an eye on the forums & do a little bit of reading here & there when I'm at home.

Do I really need to ''multiplex'' the RS-232? (I'm pretty sure I have no idea what that really means in electronics / software, other than the common vernacular meaning)

I thought the STM32 had five (5) UARTs.

I thought I could use one (1) for ''reading IN'' the original RS-232 & the remaining four (4) for ''sending OUT'' the converted RS-232 to the appropriate camera.

Cheers,

duBe

francescatodiego
Associate II
Posted on March 17, 2015 at 14:58

How

danish

says

if

your

serial ports use

only

 

tx

/

rx lines you

can do

a simple

multiplex

.

Here

we are

in the forum

ST

and isn't the correct

place to

talk about it

but

I suggest you

look up information on

CPLD

/

FPGA

and

VHDL

.

In my opinion

you can do

a thing

very easily

even with a

CPLD

.

With this type of

component

you

can

create

a hardware switch

that switches

on the basis

of the address

received

.

I used

Xilinx

that

provide

a free tool

for development but also Altera or more others offer a wide solutions range