Page 1 of 2

Mixed I/O and bit masking on Xmos ports

Posted: Fri Aug 05, 2011 9:52 am
by mynameisdev
Morning,

I get the feeling this is a really simple question - which is covered in the documentation - but for the life of me I can't figure it out. This is my first time out in the real world with XMOS - it has been -er- interesting.

Is it possible, on an XMOS, to configure the individual bits of a port as Input or Output, rather then the entire port.

I know there are one-bit port available for this sort of thing but in the scenario I am currently facing that isn't going to help me.

For those of you who have not had a play, the GPIO header on an XC-3 is laid out like this:
Image

More details here, on page 7

Now - as far as I can see, these pins can only be configured as 4- or 8-wide ports.

At the moment, I can blink my LEDs and so on with no trouble and - I can blink some LEDs and read a button input and blink some LEDs if I set the thing up as two 4-wide ports and have some LEDs on one and an input on the other.

Even using the 2x4-wide ports option I miss either some of my inputs or some of my outputs, depending on the configuration.

Coming from PIC/Atmel I'm perplexed as to how I cannot configure individual pins as I or O (mmm TRIS registers...). I understand though that XMOS doesn't play the same sort of ball... In my experience if a port has mixed I/O you can use an XOR mask when reading/writing to the port to make sure you don't affect any of the other pins. Is that a plausible method in this instance?

Anyway - any pointers would be much appreciated

Best
D

Re: Mixed I/O and bit masking on Xmos ports

Posted: Fri Aug 05, 2011 12:11 pm
by Bianco
mynameisdev wrote:Morning,

Is it possible, on an XMOS, to configure the individual bits of a port as Input or Output, rather then the entire port.

...

Best
D
No

Re: Mixed I/O and bit masking on Xmos ports

Posted: Tue Aug 09, 2011 7:55 am
by ale500
You can use ports as bidirectional and thus try to mitigate that there are less 1 bit ports free. (Depending on the device you have and board, there are many 1 bit ports not all of them free). If you application requires low speed switching, an IO expander may be a solution to consider (reading switches, flashing leds), even a shift register can provide such a mechanism.

Re: Mixed I/O and bit masking on Xmos ports

Posted: Tue Aug 09, 2011 3:29 pm
by Heater
This is a conundrum that has been bothering me for a while.

Assuming we are talking about just a LED indicator and a button on a 4 bit port one can get around it by:

1) Having the port as output driving the LED most of the time.
2) Use it as an input to briefly read the button
3) Immediately output the LED state again.

So basically the LED might flicker on or off for the time it takes to read the port. This will be very short and hopefully not visible.

Now of of course this is not much use if you have some device driven by the pins that will respond badly to the pins going high impedance as you turn it around to be an input.

In that case you might be able to get away with using the port in a kind of half-duplex mode. So for example you enable the pins internal pull up (or down) resistors so that when turned as an input the attached device is in a happy inactive state.

No idea how well any of these suggestions may work as I have never tried them but should be worth exploring.

Re: Mixed I/O and bit masking on Xmos ports

Posted: Tue Aug 09, 2011 3:47 pm
by ale500
It all depends on what is connected to the port. If leds flicker for few us it will not be noticed. Anything high-speed will probably demand constant attention.

Re: Mixed I/O and bit masking on Xmos ports

Posted: Fri Aug 12, 2011 9:26 am
by mynameisdev
@heater flickering LEDs is not an issue for me in this instance. There is nothing too sophisticated hanging from the GPIO port so running it in half duplex is not really an issue. I guess I would just need to fine tune the routine to "poll" the port on a cycle time sensible enough to not miss any button presses.

@ale500 - how can you configure XMOS ports to be bi-directional. I totally missed that when reading through the tutorials/documentation

Thanks guys!

Re: Mixed I/O and bit masking on Xmos ports

Posted: Fri Aug 12, 2011 11:48 am
by leon_heller
Ports can be bidirectional, according to this doc:

XS1-Ports-Specification(1.02).pdf

See section 3.3.

Re: Mixed I/O and bit masking on Xmos ports

Posted: Sun Aug 14, 2011 12:42 am
by MaxFlashrom
A simple latch could be used e.g. NC7SZ175, 74LCX574 to provide output lines;this would require an extra output line for a clock. The port would be used in a bidirectional mode, with the inputs just being wired straight to the XMOS. If you're going to be driving several output bits, needing an external chip, then a more sophisticated shift register or I2C IO expander may be a better choice as it can be driven serially, minimising port usage.

Something like this http://focus.ti.com/docs/prod/folders/p ... 6408a.html looks suitable.
Max.

Re: Mixed I/O and bit masking on Xmos ports

Posted: Sun Aug 14, 2011 3:26 pm
by Heater
Mynameisdev,
Just declare your port without any in/out qualifiers. Do not use buffered.
Then you can just use input and output as you like in your code, :> and <: . The port will get turned around.

At least this compiles for me and generates in and out instructions as I might expect. I have not tested it.

Let us know how you get on with it.

Re: Mixed I/O and bit masking on Xmos ports

Posted: Mon Aug 15, 2011 11:18 am
by Heater
mynameisdev,

WARNING:

Forgot to say, be careful when using a single port as input and output alternately else something might get damaged.

For example when using LEDs and switches on a 4 bit port, normally the thing is in output mode driving the LEDs. That means it might be fighting against switches that are providing a short circuit to ground or Vcc when pressed. Not good.

Same applies to driving a port as output to any other device that may be outputting at the same time.

Perhaps a few resistors on the port pins is all it takes keep currents under control and make it safe.