What is the normal state of the input ports
-
- Member++
- Posts: 21
- Joined: Tue Oct 24, 2023 11:16 am
What is the normal state of the input ports
Hello. May I ask an one question? I Didn't see anywhere a clear description about it. What is the default state of the input ports? For example I defined 4 bit port XU208 as the input, and I going to change the states of the bits using jumpers. How can I do it? I read in describtions about the internal pullup and pulldwn resistors. How can I assign them to the input port? Are there an opportunity to use them?
-
- XCore Addict
- Posts: 234
- Joined: Mon Jan 08, 2018 4:14 pm
Hi,
you have to use the builtin function (xs1.h)
void peek(void port p);
to read the port value (direct voltage on the pins)
to enable pull_up/down you have to use
void set_port_pull_up(void port p);
void set_port_pull_down(void port p);
but each have the side effect to configure the port in drive low or drive high respectively, so be sure that the port is set to all 0 or 1 before.
so a sequence like this to read the button, IF they are connected to GND should be ok
you have to use the builtin function (xs1.h)
void peek(void port p);
to read the port value (direct voltage on the pins)
to enable pull_up/down you have to use
void set_port_pull_up(void port p);
void set_port_pull_down(void port p);
but each have the side effect to configure the port in drive low or drive high respectively, so be sure that the port is set to all 0 or 1 before.
so a sequence like this to read the button, IF they are connected to GND should be ok
Code: Select all
myport <: 0; set_port_pull_up(myport);
unsigned old, buttons;
while (1) {
buttons = peek(myport);
if (buttons != old) printf("buttons=0x%X\n");
old = buttons; }
-
- Member++
- Posts: 21
- Joined: Tue Oct 24, 2023 11:16 am
Thank You. I've got it!
-
Verified
- Experienced Member
- Posts: 80
- Joined: Sun Dec 13, 2009 1:12 am
No need to use peek if it's an input only port.
on tile[0]: in port p_but = XS1_PORT_4E;
unsigned input_but_val;
p_but :> input_but_val;
The default is to have no pullup or pulldown. If you want to enable the weak internal pullup or pulldown then you can use the function as fabriceo says:
set_port_pull_up(p_but);
on tile[0]: in port p_but = XS1_PORT_4E;
unsigned input_but_val;
p_but :> input_but_val;
The default is to have no pullup or pulldown. If you want to enable the weak internal pullup or pulldown then you can use the function as fabriceo says:
set_port_pull_up(p_but);
XMOS hardware grey beard.
-
- Member++
- Posts: 21
- Joined: Tue Oct 24, 2023 11:16 am
Thank you. I've understood where I can find it (xs1.h)