Page 1 of 2

I/O Bi-directional port, SOLVED!

Posted: Mon Oct 02, 2017 2:03 pm
by proiectsoftcontrol
Hello, I have XP-SKC-L2 KIT, and I need 8bites (one port with 8bites) bi-directional example:
Put OUTPUT state this port and PORTX = any value, and after put INPUT state port and read data from this port. How it's possible???
Thanks in advance!
IMG-20170929-WA0007.jpeg

Re: I/O Bi-directional port

Posted: Mon Oct 02, 2017 4:41 pm
by CousinItt
Hi,

it's easy to use ports in bidirectional mode. I'm assuming you mean an 8-bit port. Just decide which port you want to use, say

Code: Select all

port p = XS1_PORT_8A;
The port will go into a high-impedance condition when you use it as an input:

Code: Select all

uint8_t x;

p :> x; // port is now an input
And it will become an output when you use it as an output

Code: Select all

uint8_t y = 0x55;

p <: y; // port is now an output
See the xmos document Introduction to XS1 ports for more information about ports.

Re: I/O Bi-directional port

Posted: Mon Oct 02, 2017 8:43 pm
by proiectsoftcontrol
I try next code and not work ok:

Code: Select all

#include <xs1.h>
#include <platform.h>
#include <gpio.h>

on tile[0] : port pin_test = XS1_PORT_8A;

uint8_t p_read;
void Test(){
    while(1){
        pin_test <: 0x00;//Led ON (GPIO-Slice)
        delay_milliseconds(500);
        pin_test :> p_read;
        delay_milliseconds(500);
    }
}

int main() {
par{
 on tile[0] : Test();
}
    return 0;
}

If change line

Code: Select all

on tile[0] : port pin_test = XS1_PORT_8A;
with

Code: Select all

on tile[0] : in port pin_test = XS1_PORT_8A;//it's ok input state
it's ok input state!!!

Re: I/O Bi-directional port

Posted: Tue Oct 03, 2017 10:23 am
by CousinItt
When you say the code doesn't work, what do you mean?

If you are connecting the GPIO slice to the star slot of the slicekit board, you should be able to drive the LEDs using port 8A.

Note the LED lines are active high, so writing 0 to the output will do nothing.

Also remember that switching the port to an input will not change the voltage on the pin in zero time. You may have to sample the input a second time, after switching to input mode, before you will see valid pin states.

Code: Select all

void Test(){
    while(1){
        pin_test <: 0x01;//Led ON (GPIO-Slice) 
        delay_milliseconds(500);
        pin_test :> p_read; // pin possibly still high when you read it
        delay_microseconds(1);
        pin_test :> p_read; // pin probably valid now
        delay_milliseconds(500);
    }

Re: I/O Bi-directional port

Posted: Tue Oct 03, 2017 2:22 pm
by proiectsoftcontrol
This code it's ok!!!

Code: Select all

        
pin_test :> p_read; // pin possibly still high when you read it
delay_microseconds(1);
pin_test :> p_read; // pin probably valid now
With 0x00 write to port LED ON, I can try step by step in debug mode and stop after write 0x00 to port and led turn ON.
Now I see that is fine, but pins 0: X0D06, 0: X0D07 are always 0 although I put pull-up with vcc resistance on them...

Re: I/O Bi-directional port

Posted: Tue Oct 03, 2017 4:24 pm
by CousinItt
Are you using the GPIO slice with the slicekit? If yes, which slot is it connected to? What port is your LED on? You need to provide more information to get help.

Re: I/O Bi-directional port

Posted: Tue Oct 03, 2017 6:46 pm
by proiectsoftcontrol
Sorry for broken english and many informations, I use "GPIO-Slice" to STAR port connected, and I try without "GPIO-Slice" and I have problem with 0:X0D06, 0:X0D07 pins is always 0 logic, I put pull-up resistor to pin and nothing...
I'll try other ports!

Re: I/O Bi-directional port

Posted: Sat Oct 07, 2017 11:55 pm
by mon2
What is the result on X0D06 and X0D07 if you write a value of 0xff ?

Code: Select all

#include <xs1.h>
#include <platform.h>
#include <gpio.h>

on tile[0] : port pin_test = XS1_PORT_8A;

uint8_t p_read;
void Test(){
    while(1){
        pin_test <: 0xFF; //Led ON (GPIO-Slice)
        delay_milliseconds(500);
        pin_test :> p_read;
        delay_milliseconds(500);
    }
}

int main() {
par{
 on tile[0] : Test();
}
    return 0;
}

Image



Image

Re: I/O Bi-directional port

Posted: Sun Oct 08, 2017 7:31 am
by proiectsoftcontrol
X0D06 and X0D07 have +2.28V, and other pins from XS1_PORT_8A have +3.33V. In schematic do not see other connection on XS1_PORT_8A!

Re: I/O Bi-directional port

Posted: Sun Oct 08, 2017 7:51 am
by proiectsoftcontrol
Trying with XS1_PORT_8B works well...