I/O Bi-directional port, SOLVED!

Technical discussions around xCORE processors (e.g. General Purpose (L/G), xCORE-USB, xCORE-Analog, xCORE-XA).
proiectsoftcontrol
Junior Member
Posts: 7
Joined: Mon Oct 02, 2017 2:00 pm

I/O Bi-directional port, SOLVED!

Postby proiectsoftcontrol » Mon Oct 02, 2017 2:03 pm

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
(1.88 MiB) Not downloaded yet
IMG-20170929-WA0007.jpeg
(1.88 MiB) Not downloaded yet
Last edited by proiectsoftcontrol on Sun Oct 08, 2017 9:27 am, edited 1 time in total.
CousinItt
Member++
Posts: 29
Joined: Wed May 31, 2017 6:55 pm

Postby CousinItt » Mon Oct 02, 2017 4:41 pm

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.
proiectsoftcontrol
Junior Member
Posts: 7
Joined: Mon Oct 02, 2017 2:00 pm

Postby proiectsoftcontrol » Mon Oct 02, 2017 8:43 pm

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!!!
CousinItt
Member++
Posts: 29
Joined: Wed May 31, 2017 6:55 pm

Postby CousinItt » Tue Oct 03, 2017 10:23 am

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);
    }
proiectsoftcontrol
Junior Member
Posts: 7
Joined: Mon Oct 02, 2017 2:00 pm

Postby proiectsoftcontrol » Tue Oct 03, 2017 2:22 pm

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...
CousinItt
Member++
Posts: 29
Joined: Wed May 31, 2017 6:55 pm

Postby CousinItt » Tue Oct 03, 2017 4:24 pm

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.
proiectsoftcontrol
Junior Member
Posts: 7
Joined: Mon Oct 02, 2017 2:00 pm

Postby proiectsoftcontrol » Tue Oct 03, 2017 6:46 pm

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!
User avatar
mon2
XCore Expert
Posts: 757
Joined: Thu Jun 10, 2010 11:43 am
Contact:

Postby mon2 » Sat Oct 07, 2017 11:55 pm

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
proiectsoftcontrol
Junior Member
Posts: 7
Joined: Mon Oct 02, 2017 2:00 pm

Postby proiectsoftcontrol » Sun Oct 08, 2017 7:31 am

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!
proiectsoftcontrol
Junior Member
Posts: 7
Joined: Mon Oct 02, 2017 2:00 pm

Postby proiectsoftcontrol » Sun Oct 08, 2017 7:51 am

Trying with XS1_PORT_8B works well...

Return to “Processors”