UART COMM

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

User avatar
achillis1
Posts: 347
Joined: Thu Oct 09, 2008 9:19 am
Has thanked: 92 times
Been thanked: 8 times
Contact:

UART COMM

Postby achillis1 » Fri Aug 07, 2015 6:16 pm

Hello,

I have a board that communicates through UART but has 4 pins - RXD , TXD , CTS , RTS .
Can I communicate with it with flowcode?
If I use the RS232 component will I be able to control CTS & RTS?
As far as I know RS232 component uses only TX, RX so what about CTS, RTS?
What is the TX,RX voltage output?


Also If I want to connect it via SPI, which PIC 18F877A pins correspond to MOSI, MISO, SCK, SS ?

Thank you,

Best Regards,

Andreas Achilleos

siwo278
Posts: 39
Joined: Tue Feb 12, 2013 9:07 am
Has thanked: 4 times
Been thanked: 5 times
Contact:

Re: UART COMM

Postby siwo278 » Sun Aug 09, 2015 9:41 am

Hello

So you will be able to communicate. The 232 properties FLOWCODE set the hardware flow control (disabled by default). Then you can choose the pins responsible for the RTS and CTS. Remember that uP operate on 5V or 3V3, and the standard RS232C typically at 12V. Therefore, the communication between PC and uP need a converter such as .: MAX232


Witam

Tak można będzie się komunikować. W właściwościach RS232 flowcode ustawiasz sprzętową kontrolę transmisji (domyślnie wyłączona). Wtedy można wybrać piny odpowiedzialne za RTS i CTS. Pamiętaj o tym iż uP operują na napięciu 5V lub 3V3, a standard RS232C typowo na napięciu 12V. Dlatego też do komunikacji pomiędzy PC a uP potrzebny jest konwerter np.: MAX232
These users thanked the author siwo278 for the post:
achillis1 (Sun Aug 09, 2015 2:26 pm)
Rating: 5.26%
 

User avatar
achillis1
Posts: 347
Joined: Thu Oct 09, 2008 9:19 am
Has thanked: 92 times
Been thanked: 8 times
Contact:

Re: UART COMM

Postby achillis1 » Sun Aug 09, 2015 2:26 pm

Hello siwo278,

Thank you for replying, the board I have can be connected directly to an MCU/PIC so it is not necessary to convert it to RS232, how ever as you say; I can choose the RTS & CTS through the component's properties, yes?

Do you know the SPI pins MOSI, MISO, SCK, SS how they correspond to the PIC 18F877A?

Thank you

siwo278
Posts: 39
Joined: Tue Feb 12, 2013 9:07 am
Has thanked: 4 times
Been thanked: 5 times
Contact:

Re: UART COMM

Postby siwo278 » Sun Aug 09, 2015 10:06 pm

Hello

Yes RTS and CTS select the properties of the component. (for pictures). when it comes to SPI interface I am far not figured him. Far enough for me to RS232 and RS485.

Witam

Tak RTS i CTS wybieramy przez właściwości komponentu. (na obrazkach). jeśli chodzi o interfejs SPI to narazie do niego nie doszłam. Narazie wystarcza mi RS232 i RS485.
Attachments
rstest2.jpg
rstest2.jpg (330.53 KiB) Viewed 11436 times
rstest1.jpg
rstest1.jpg (311.48 KiB) Viewed 11436 times
These users thanked the author siwo278 for the post:
achillis1 (Mon Aug 10, 2015 6:38 am)
Rating: 5.26%
 

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

Re: UART COMM

Postby Benj » Mon Aug 10, 2015 10:54 am

Hello,

Do you know the SPI pins MOSI, MISO, SCK, SS how they correspond to the PIC 18F877A?


877A.jpg
877A.jpg (83.89 KiB) Viewed 11425 times


MOSI = SDO = RC5
MISO = SDI = RC4
SCK = RC3
SS = Slave RA5 / Master Any Free I/O

More info: http://www.matrixtsl.com/blog/simplifie ... c-and-spi/
These users thanked the author Benj for the post:
achillis1 (Mon Aug 10, 2015 1:28 pm)
Rating: 5.26%
 

User avatar
achillis1
Posts: 347
Joined: Thu Oct 09, 2008 9:19 am
Has thanked: 92 times
Been thanked: 8 times
Contact:

Re: UART COMM

Postby achillis1 » Mon Aug 10, 2015 3:09 pm

Thank you a lot Ben!

I have a question though and I quote from the http://www.matrixtsl.com/blog/simplifie ... c-and-spi/ link you gave me
One of the great upsides of the I²C bus is that it can do voltage level shifting for you. For example say we have a Master running at 5V but a slave running at 3V3. The I²C pullup resistors are connected between the signals and 3V3 allowing the bus to float at 3V3. The Master can still recognise the 3V3 input voltage as a logic one and no nasty 5V is allowed to reach and potentially damage the slave.


Can I apply this when I try to connect my MCU to a 3.3V board while communicating via TX/RX (UART)? OR should I use resistor/voltage divider (2kΩ/1KΩ)


Thank you,

Best Regards,

Andreas Achilleos

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

Re: UART COMM

Postby Benj » Tue Aug 11, 2015 9:59 am

Hello Andreas,

The UART is a driven bus meaning you don't rely on external pull up resistors to provide the logic 1 level.

Therefore yes you should probably use a resistor based voltage divider to reduce the TX voltage from 5V to 3V, your resistor values look perfect. The RX pin can be left as is as the output will be from the 3V3 side and should work ok with the 5V device.

Some 3V3 devices also have 5V tolerant pins so you could check this if you know what the device is.
These users thanked the author Benj for the post:
achillis1 (Tue Aug 11, 2015 6:52 pm)
Rating: 5.26%
 

User avatar
achillis1
Posts: 347
Joined: Thu Oct 09, 2008 9:19 am
Has thanked: 92 times
Been thanked: 8 times
Contact:

Re: UART COMM

Postby achillis1 » Tue Aug 11, 2015 7:15 pm

Ben one last thing...

I am currently testing the V6 flowcode, I was used to v4. I need some help with the RS232 macro properties.

1. If I need to receive a word such as: "hello" from my peer board talking to MCU, what would I choose; ( receiveChar or receiveString)?
2. What do I enter in the -Expression- field?
3. If I enter a variable in the expression field , then in order to print on screen the incoming data, should I use that variable or I should still select a return value and assign it to the aforementioned variable which was entered in the expression filed?
4. It seems that I cannot enter to a decision icon the following expression : Inchar>0 Variable Inchar is a string. I need to enter the decision when the return value or RS232 macro which is Inchar ; when is above 0. The error I receive:"incompatible operands for operation"
Thank you,

Best Regards

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

Re: UART COMM

Postby Benj » Wed Aug 12, 2015 9:45 am

Hello,

The receive string allows a number of bytes to be received and stored into a string variable. The receive byte only receives a single character.

You could receive a string and then use the string compare function in a decision to check for the word "hello".

Inchar = ReceiveString

Then you can add the following code into a decision icon.

Compare$(Inchar, "hello", 0) == 0

However there are problems with this approach. For example if the string you receive contains "xhello" or "hellox" then the comparison will return false.

I instead like to go down the route of using the RXINT interrupt to collect the databytes as they come in. Then use a circular buffer component to store the data. The circular buffer has search functions so you can do something like search for "hello" which will be a lot more reliable than the string comparison.

An example of this is available from here.
http://www.matrixtsl.com/wiki/images/6/ ... ridge.fcfx

More help on the circular buffer component is available from here.
http://www.matrixtsl.com/wiki/index.php ... Storage%29
These users thanked the author Benj for the post:
achillis1 (Thu Aug 13, 2015 5:07 pm)
Rating: 5.26%
 

User avatar
achillis1
Posts: 347
Joined: Thu Oct 09, 2008 9:19 am
Has thanked: 92 times
Been thanked: 8 times
Contact:

Re: UART COMM

Postby achillis1 » Sat Aug 15, 2015 9:55 am

Hello Ben,

Thank you for your response.

Can I use those flowcode examples with flowcode V4?

Thank you,

Best Regards

User avatar
achillis1
Posts: 347
Joined: Thu Oct 09, 2008 9:19 am
Has thanked: 92 times
Been thanked: 8 times
Contact:

Re: UART COMM

Postby achillis1 » Mon Aug 17, 2015 3:20 pm

Hello Ben,

1 . I have tried the "circular buffer" example on my MCU, and AS IT IS; it works just fine, I send data from android app, I get them on MCU and then I get the reply from MCU.
However I have noticed that if I take the routine and put it in a loop, in order to have constant communication between the devices , then the communication starts to have problems.
What I mean, when I receive reply data from MCU, the data that were received and are in the buffer; sometimes instead of getting ( 12345 ) I get (123.5), and peculiarly, almost always is the number 4 that is represented by a dot (.) !

2 . When I send data to the MCU and I send 6 bytes instead of 5 ( five macros are in the routine for storing data) then the sixth byte is being stored somewhere and then when I send again 5 bytes , I get as reply the redundant one and the first 4 of the last bytes: e.g. send > 123456, theMCU replies 12345, when I send again > 12345 the MCU replies 61234.

I get this even if I include a macro that says "flush buffer"


3 . I have noticed that if I let the routine run and go up to the end -without loop- and then hard reset the EB-006 then the communication is fine. So I have tried to enter the main routine to a loop and then have an interrupt to call the main routine in order to have a "fresh" run of the main routine but still I get errors in receiving data in the correct order.

> Is there a way instead of having the routine in a loop to auto reset the MCU?


Can you tell me how many bytes can be stored while receiving RS232 data?

Thank you,

Best Regards,

Andreas Achilleos