I/O Bi-directional port, SOLVED!
-
- Junior Member
- Posts: 7
- Joined: Mon Oct 02, 2017 2:00 pm
I/O Bi-directional port, SOLVED!
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!
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!
You do not have the required permissions to view the files attached to this post.
Last edited by proiectsoftcontrol on Sun Oct 08, 2017 9:27 am, edited 1 time in total.
-
- Respected Member
- Posts: 365
- Joined: Wed May 31, 2017 6:55 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
The port will go into a high-impedance condition when you use it as an input:
And it will become an output when you use it as an output
See the xmos document Introduction to XS1 ports for more information about ports.
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;
Code: Select all
uint8_t x;
p :> x; // port is now an input
Code: Select all
uint8_t y = 0x55;
p <: y; // port is now an output
-
- Junior Member
- Posts: 7
- Joined: Mon Oct 02, 2017 2:00 pm
I try next code and not work ok:
If change line
with
it's ok input state!!!
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;
Code: Select all
on tile[0] : in port pin_test = XS1_PORT_8A;//it's ok input state
-
- Respected Member
- Posts: 365
- Joined: Wed May 31, 2017 6:55 pm
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.
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);
}
-
- Junior Member
- Posts: 7
- Joined: Mon Oct 02, 2017 2:00 pm
This code it's ok!!!
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...
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
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...
-
- Respected Member
- Posts: 365
- Joined: Wed May 31, 2017 6:55 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.
-
- Junior Member
- Posts: 7
- Joined: Mon Oct 02, 2017 2:00 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!
I'll try other ports!
-
- XCore Legend
- Posts: 1913
- Joined: Thu Jun 10, 2010 11:43 am
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;
}
-
- Junior Member
- Posts: 7
- Joined: Mon Oct 02, 2017 2:00 pm
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!
-
- Junior Member
- Posts: 7
- Joined: Mon Oct 02, 2017 2:00 pm
Trying with XS1_PORT_8B works well...