Do i need to set anyhting to make a port TX or RX

Forum for problems or queries regarding Flowcode Comms Components. Eg LIN, I2C, SPI, RS232, CAN, IrDA etc

Moderators: Benj, Mods

Post Reply
IAB48
Posts: 13
Joined: Wed Feb 18, 2009 3:24 am
Contact:

Do i need to set anyhting to make a port TX or RX

Post by IAB48 »

Hi
how to i tell a port that it is being used for RS232 comms rather than a standard digital port. although this is a generic question the chip I am using at present is the 16F627.

Thanks
Ian B

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: Do i need to set anyhting to make a port TX or RX

Post by Sean »

Hi Ian,

If you are using Flowcode, all the necessary port configuration code is included when the RS232 component (or any other component) is added to the flowchart. You should avoid any additional program control of the associated i/o pins (RB1 and RB2 on the 16F627, and the flow control pins if hardware handshaking has been enabled).

Reading or writing the other Port B pins should be done with the single bit versions of the i/o commands, or the mask property used to exclude RB1 and RB2 - preventing them from being affected.

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: Do i need to set anyhting to make a port TX or RX

Post by jadiflow »

Hi Sean or Ben,

This is exactly the question I also have. To confirm, if i have an RS232 component attached using hardware flow control, I should not even try to read any of the pins TX, RX, CTS, RTS to check status?

Jan Didden

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: Do i need to set anyhting to make a port TX or RX

Post by Sean »

There should be no problems reading pins that are already configured as inputs by other components.

Attempting to read pins that need to be configured as outputs will cause problems. Flowcode will re-configure the pin as an input by writing to the TRIS (PIC) or DDR (AVR) register before reading the PORT (PIC) or PIN (AVR) register, and will leave the pin as an input after the instruction has been completed.

It is possible to read the state of an output pin by accessing the PORT or PIN register directly using C code and avoiding any writes to the associated TRIS/DDR register.

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: Do i need to set anyhting to make a port TX or RX

Post by Benj »

The RS232 operation is fairly transparent and you can use the component by simply using the component macros. Things like flow control and pin setup are performed automatically for you (as long as the pins are defined correctly inside the component connections property page).

jadiflow
Flowcode v5 User
Posts: 273
Joined: Thu Apr 17, 2008 9:59 am
Has thanked: 19 times
Been thanked: 16 times
Contact:

Re: Do i need to set anyhting to make a port TX or RX

Post by jadiflow »

Ahhh yes, but I use the UART to communicate with a transcoder component (for a wireless link). The setup of the transcoder to make it enter a defined serial I/O state is to manipulate some of the UART pins as follows (and the order is important):

- assert TX
- assert RTS
- delay 50mS (transcoder enters serial mode @ 9600bd)
- send serial bytes/command: fc sendbyte macro
- delay 1mS (processing)
- negate RTS (to make the transcoder emit ack/response)
- read ack/response: fc readbyte macro
...

So you see I need to manipulate those pins, and then do the component macro. It seems that for this to work, the component macro should (re)configure the UART pins with each call to readbyte or sendbyte. Any idea how to solve this?

Edit: I just looked at the .c code generated for the uart macro and it appears that RTS and TX are only used as an output throughout. Does that mean that I can assert/negate them at will without interfering with the uart operation?

Jan Didden

Post Reply