Connecting new devices to unused pins Topic is solved

Sub forums for various specialist XMOS applications. e.g. USB audio, motor control and robotics.
User avatar
xlordofpainx
Active Member
Posts: 62
Joined: Thu Mar 08, 2018 2:44 pm

Connecting new devices to unused pins

Postby xlordofpainx » Mon May 14, 2018 10:11 am

I am trying to understand the concept of using ports and pins. I understood that smaller bit ports have priority that if the idea is driving a single device which needs 1 line I should take a 1 bit port as higher bit ports will send/receive data on more than 1 physical pins of the chip. Normally I need just 3 free single bit ports (I am integrating parts of the xcore200 MC Audio board with another device), but it got me interested and I thought:"hmmm if I understand this I could add a couple of headers connected to free pins, in case I decide to connect something in the future". Besides the regular unused pins from on the schematic I got rid of the ethernet, DAC, ADC, MIDI, the USB A, and complicated clock scheme ( using just a single oscillator now meaning there is no PLL select, no MCLK_FSEL). As I was freeing pins I noticed for example this:
X0D28 4F0 8C2 16B2 USB_SEL0
X0D29 4F1 8C3 16B3 USB_SEL1
X0D30 4F2 8C4 16B4 VBUS_OUT_EN
X0D31 4F3 8C5 16B5 PLL_SELECT

So 4 pins are physically connected to 2 different devices sending different signals. But it is a 4-bit port...... and all of these require just a single 0 or 1. How did they make this work. Or am I misunderstanding how ports and pins are used?
View Solution
User avatar
mon2
XCore Legend
Posts: 1162
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Postby mon2 » Mon May 14, 2018 1:31 pm

If I understand your question correctly:

You have a 4 bit port that can be referenced as 4F block. The port pins do not care where they are connected but access to each pin can be as follows:

if you output a "0" to bit0 of 4F then X0D28 will be logic low.
if you output a "1" to bit0 of 4F then X0D28 will be logic high.

if you output a "0" to bit1 of 4F then X0D29 will be logic low.
if you output a "1" to bit1 of 4F then X0D29 will be logic high.

if you output a "0" to bit2 of 4F then X0D30 will be logic low.
if you output a "1" to bit2 of 4F then X0D30 will be logic high.

if you output a "0" to bit3 of 4F then X0D31 will be logic low.
if you output a "1" to bit3 of 4F then X0D31 will be logic high.

To isolate each and configure each port bit, there are many solutions and the methods are common to C programming. As my prof used to say, and probably still does, do not be fancy with the coding but make it work correctly.

Take for example these manipulations:

Code: Select all

make_bit0_low = value_to_save & 0x0e; // mask off Bit0 (ie. remove the lowest bit value) (1110b) - where there is a 0 -> kill that bit if using &
P4F <:= make_bit0_low;

make_bit1_low = value_to_save & 0x0d; // mask off Bit1 (1101b)
P4F <:= make_bit1_low;

make_bit2_low = value_to_save & 0x0b; // mask off Bit2 (1011b)
P4F <:= make_bit2_low;

make_bit3_low = value_to_save & 0x07; // mask off Bit3 (0111b)
P4F <:= make_bit3_low;


====

Code: Select all

make_bit0_high = value_to_save | 0x01; // OR the value with a "1" at that bit weight to make that bit "1" (high)
P4F <:= make_bit0_high;

make_bit1_high = value_to_save | 0x02; // OR the value with a "1" at that bit weight to make that bit "1" (high)
P4F <:= make_bit1_high;

make_bit2_high = value_to_save | 0x04; // OR the value with a "1" at that bit weight to make that bit "1" (high)
P4F <:= make_bit2_high;

make_bit3_high = value_to_save | 0x08; // OR the value with a "1" at that bit weight to make that bit "1" (high)
P4F <:= make_bit3_high;



The following library may be of use as well to simplify the port access:

https://github.com/xmos/lib_gpio
User avatar
xlordofpainx
Active Member
Posts: 62
Joined: Thu Mar 08, 2018 2:44 pm

Postby xlordofpainx » Mon May 14, 2018 1:54 pm

Okay so I guess- using this library would allow to easily use a multiple-bit port's pins separately. That would mean that I could potentially connect all unused pins to headers (stress goes on "potentially"). So at whatever part of the code I am and whatever the current statues of the bit stream is, for example 1100, if i send the order
"P4F <:= make_bit0_high;" - the output on the port would become 1101, keeping the other pins intact. That would be quite amazing.
User avatar
mon2
XCore Legend
Posts: 1162
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Postby mon2 » Mon May 14, 2018 2:25 pm

I have not reviewed the GPIO library but suspecting that is the intent...to make bit level manipulation easier for the user.

In summary, you always start with a global value for that port and then either mask off a bit or bits to force that bit or bits to 0. Respectively you take the original global value and OR the proper bit weight to turn ON that bit. Yes, you should be fine to consider that library and review the example supplied with that download. It should be pretty straightforward to do your own but will save some brain cells and at least a few hours of coding to use a proven to work library.
User avatar
xlordofpainx
Active Member
Posts: 62
Joined: Thu Mar 08, 2018 2:44 pm

Postby xlordofpainx » Mon May 14, 2018 3:24 pm

Awesome.
Image

Who is online

Users browsing this forum: No registered users and 11 guests