Deactivate RS232 component for a while

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Deactivate RS232 component for a while

Post by bercioiu »

Hi guys!

I am working to a project with a lot of pins... It is an stepper controller for 6 motors. Beside the motor I have some sw, leds and an LCD. Because the number of pins are 40, i decide to split the project in two parts with two mcu 18F26k20. First pic is for LCD, sw, leds and the second is for motors. The settings are made in the first pic and send the variables to the second pic, via RS 232. Now, I have a situation: After the transmission is done, I need the two pins (RX/TX) for the motors but "the line" is up because of RS232 component. My question is: how can I deactivate the RS232 component after the transmission to use those pins?
Thank you again!

Puiu

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Deactivate RS232 component for a while

Post by medelec35 »

Hi bercioiu,
I will have more of a play tomorrow but one thing to try is a c code block with

Code: Select all

clear_bit(rcsta,7);
It may not properly work with just the above, but will see what i can sort out.

Note:
you must use:

Code: Select all

set_bit(rcsta,7);

To re-enable RS232

Martin
Martin

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Deactivate RS232 component for a while

Post by medelec35 »

Hi bercioiu,,
Just confirmed that

Code: Select all

clear_bit(rcsta,7);
does release both TX and RX so they can be both used as an output.
Attached is a flowchart that I tested with.
it does two things.
1) increment a count and send the number via RS232 to hyperterminal
2) toggle RX and TX pins 5 times, then jumps back to 1.
Although tested on 16F877A, the same register is used on 18F26k20, so It should work OK?

Martin
Attachments
Usart test1.fcf
(9 KiB) Downloaded 353 times
Martin

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: Deactivate RS232 component for a while

Post by bercioiu »

Thank you very much! I will try this and give you a feedback!

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: Deactivate RS232 component for a while

Post by bercioiu »

Your Flowchart is working just fine but mine not :oops:
I`m not sure how to "synchronize" the transmission of bits with the receive of them. I have tried a lot of modalities with now reasonable result. The only way with success was to put in the loops all steps of the "transmission", step by step and the program was flowing through all loops but I don`t like it...

Thank you again Martin!

Here are my files.
Attachments
Slave_test.fcf
(28.49 KiB) Downloaded 347 times
Master_test.fcf
(21.7 KiB) Downloaded 346 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Deactivate RS232 component for a while

Post by medelec35 »

Hi Puiu,
You're welcome.

Just looked at Slave_test.fcf
What I find works really well is the RX interrupt.
If using a loop to received RX then chars can be so easily missed.
My latest project used RX interrupt for receiving constantly transmitting characters (several integers, each separated by a space evey 1 second) and not 1 single character is missed!

Martin
Martin

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: Deactivate RS232 component for a while

Post by bercioiu »

I alter my Slave_test with RX_INT but nothing happens. When I send the bytes, the receive window on the Slave_test is black but if I push erase button (at received bytes), in the buffer window of the Slave, appear all the bytes and stay there.
I can`t put the file here today (don`t know why), i put it on my server, for download, just right click on the link and save link as:

http://www.ferodouriauto.com/electronica/Slave_test.fcf

Thank you!

Puiu

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: Deactivate RS232 component for a while

Post by bercioiu »

I still have not managed to use the RX interrupt.
Any help is welcome.
Thank you!

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Deactivate RS232 component for a while

Post by Benj »

Hello,

Just to confirm are you running the final version of Flowcode v5? should say v5.5 in Help -> About.

If you want to sanity check the C code that is being produced then it should look like this.

Code: Select all

    //Interrupt
    //Interrupt: Enable RXINT
    st_bit(intcon, GIE);
    st_bit(intcon, PEIE);
    st_bit(pie1, RCIE);
It is possible that the UART can become locked by an error on the bus prior to enabling the interrupt so might be worth doing a couple of receive macros with a timeout parameter of 0 or 1 before enabling the interrupt just to clear out any potential errors.

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: Deactivate RS232 component for a while

Post by bercioiu »

Thank you for your reply!
Yes I have the last ver. of Flowcode (5.5.2.1)
And Yes, I check the C code and all that lines are there ...
Strange, if I push the erase button on the received or sent bytes, the bytes appear in the queue window...

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Deactivate RS232 component for a while

Post by medelec35 »

Hi Puiu,
The Fowcode simulator will not simulate RX interrupt.
What you will need to do to test is either place a temporary call RX macro.
or use a switch to call RX macro
Don't forget to disable either methods prior to sending to hex or target device.

Martin
Martin

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: Deactivate RS232 component for a while

Post by bercioiu »

Aha, so this was the mystery, it cannot be simulate... I`ll try in pic :-)
Thanks Martin!

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Deactivate RS232 component for a while

Post by medelec35 »

You're welcome Puiu,
Hope tests go your way.

Martin
Martin

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: Deactivate RS232 component for a while

Post by bercioiu »

I give up ! Can' t "catch" all bytes... I think that I will return to my loops...

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Deactivate RS232 component for a while

Post by medelec35 »

It should capture every byte, but it the time taken to process the byte that could cause missing bytes?

Still you use the method which suits you best. :)
Martin

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: Deactivate RS232 component for a while

Post by bercioiu »

I have 26 bytes to send and receive. I made an macro for RX_INT where is an RS232 receive macro component and the received bytes are return value in the RX variable. In the Main macro, I have an decision and when RX <> 255, then, to the yes answer, increment an counter and after that, is an switch case "counter" and copy the content of the RX variable in to the varX variable (x correspond with the case of the switch case, according to the counter. To the exit of the switch case, I put an calculation and reset the RX variable (RX=255). Don't know if I have made clear... I can not attach files...

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Deactivate RS232 component for a while

Post by medelec35 »

bercioiu wrote: I can not attach files...
So when you click on reply, the Upload attachment tab is missing?
Attachement tab.png
(94.06 KiB) Downloaded 10401 times
If that is the case then you could try PM DavidA has I believe he is responsible for the forums.
As soon as you can post the flowchart, I will see if there is anyway I can improve it.

Martin
Martin

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: Deactivate RS232 component for a while

Post by bercioiu »

I have all the buttons but when I push the "Add the file", the answer is "The extension is not allowed.". The file is *.FCV
I can not access the forum directly from the browser and I use an proxy server to access here, it is a problem with my IP class or something, don`t know...

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Deactivate RS232 component for a while

Post by medelec35 »

bercioiu wrote:he answer is "The extension is not allowed.". The file is *.FCV
That's not your server since .fcv files are not allowed, I guess because the normal flowcode extension is .fcf and not fcv
If you need to post something where the extension is not allowed then you can try placing the file within a zip file.

How comes your file is .fcv?
FCV is normally used when assigning a flowcode variable to say a register within a C code Block
Martin

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: Deactivate RS232 component for a while

Post by bercioiu »

Sorry, it was a typo... *.fcf tried to upload... I can not upload archives too.

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: Deactivate RS232 component for a while

Post by bercioiu »

I think that I find the way out :-)
But, There is only one problem, for the very first time, when I receive the bits, I lost the first byte. If I made "Counter=255" at the beginning of the program, I catch the first byte. Why is that?
In the example I have made only for 5 variable, but I have 26 to RX-TX, there is a simple way to do that?
Thank you!
I see that today I can attach files on the forum.

Puiu
Attachments
Slave_test.fcf
(18.52 KiB) Downloaded 271 times
Master_test.fcf
(16.54 KiB) Downloaded 254 times

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Deactivate RS232 component for a while

Post by medelec35 »

Hi Puiu,
bercioiu wrote:Sorry, it was a typo... *.fcf tried to upload.
No probs,
Happens to the most of us (myself including).
I will put a flowchart together to see if we can capture every single event.
Is there a minimum time in between full sets (26) of transmissions?
bercioiu wrote:In the example I have made only for 5 variable, but I have 26 to RX-TX, there is a simple way to do that?
Yes i would use a variable array.
When you create a new variable E.g Step.
What you do is add variable called Step[26]
Then when assigning a variable with a value you use Step[0]=56
Step[1]=32
.....
Step[25]=32

So if using and array of 26 elements
The range within brackets is between 0 & 25.
Or if you have another variable called Count you can use Step[Count]=RX_Value
That way you don't have to use 26 separately named variable only 1!

Also Can you post a sample of what all 26 bytes will look like when sent.
Do the bytes sent have a maximum number, e.g 0 to 7?
Reason for asking is if you want a number like 34 sending then they will be treated as two separate numbers.

I have added an example that will time out after 1 second, then display numbers on LCD.
Attachments
Slave_test V2.fcf
(18.59 KiB) Downloaded 250 times
Martin

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: Deactivate RS232 component for a while

Post by bercioiu »

I have 6 sets (6 motors) by 4 parameter and another 2 variable that represents hours and minutes of a timer. The 4 parameters of the motors are:
1) on/of (active -1, inactive - 0)
2) speed from 1 to 30
3) Cycle (how much steps to run, in fact, represents degree because the motors are connected to some planetary demultiplications gears ) and the value are from 1-180
4) And a ratio of transmission with the value between 2 and 10
So, I have:
6 variables with value 0-1
6 "-" 1 to 30
6 "-" 1 to 180
6 "-" 2 to 10
1 variable (for hours) 0-24
1 "-" (for minutes) 0-59

Total 26 variables. I need to transmit that values only one time (when one of them are changed from a menu at the master chip).

I`m looking at the "Slave_test v2", and I`m afraid that I don`t understand what you did it there :oops:

medelec35
Matrix Staff
Posts: 9520
Joined: Sat May 05, 2007 2:27 pm
Location: Northamptonshire, UK
Has thanked: 2585 times
Been thanked: 3815 times
Contact:

Re: Deactivate RS232 component for a while

Post by medelec35 »

I'm trying to get my head around this.

Suppose you just need to transmit say 12 in:
3) Cycle (how much steps to run, in fact, represents degree because the motors are connected to some planetary demultiplications gears ) and the value are from 1-180

The slave can distinguish a single 1 from the 12 by using a time out function
But how will the slave know if it's for how many steps to run for example or its for speed 1 to 30?

Are you transmitting anything to distinguish?

Perhaps you can post a typical set of values as the master will transmit them?

There will be a set of one, two or three digit numbers and we need to separate them so it changes the vale of the correct variable.

Perhaps one way is to send an 'a' then value for the 1st set, 'b' then value for the second set etc?
Unless you already have it worked out?
bercioiu wrote: I`m looking at the "Slave_test v2", and I`m afraid that I don`t understand what you did it there :oops:
No worries, once we have a solution we can then go over the flowchart in more details.
Martin

bercioiu
Posts: 161
Joined: Sun Feb 25, 2007 10:56 am
Location: bucharest, romania
Has thanked: 90 times
Been thanked: 34 times
Contact:

Re: Deactivate RS232 component for a while

Post by bercioiu »

The goal of this "controller" is to run 6 stepper motors in a loop a while (the timer is set in master too).
Once all settings are transmitted, the slave wait a start command (a sw). All it have to do is to run all 6 motors with the parameters transmitted in cycle, when the number of steps in one direction is done, slave send to the drivers of motors dir 0 and then the motors run backwards (to "home") with the same speed and the same number of steps. When "home" is touched, send dir 1 and the motors run forward again, until the timer will expire. Number of steps is calculated depending on how long the "race" should be.

About the parameters:
1) on/off >> this will activate/deactivate a motor if I don`t want to use it in a cycle
2) speed >> this represent the value of the delay between two steps
3) cycle >> this is the "journey" of the motor in one direction (I think that I don`t choose a good name for it :D ), After some calculation will be the number of steps. It depends how is the ratio and how long I want to run the motor
4) ratio >> this represent the ratio of transmission (if I change some gear in the de-multiplication system E.g 1:4)

In the mean time, I manage to send my variable (in my way :roll: ) and everything looks good so far. I don`t understand "coding", therefore I use Flowcode, I`m good in "paint" code :D.
Thank you for your help again, I understand how to use INT_RX, how to activate/deactivate RS232 and this is important for my project.

Post Reply