cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
joancab
Teacher
Teacher
506 Views
Registered: ‎05-11-2015

I cannot read from AXI GPIO input pins

I'm using the AXI GPIO, I have a port with a mix of inputs and outputs. They are not connected to the outside with buffers but to internal signals. I have a VIO connected to these signals. Whenever my software puts some value in the outputs the VIO shows the signals change, but when an input signal changes to 1, software reads 0.

These are the functions I use:

 

// Initialize GPIO
Status = XGpio_Initialize(&XGpioInst0, GPIO_0_ID);
// Set data direction
XGpio_SetDataDirection(&XGpioInst0, 1, 0x80);			// bit 7 input
...
// wait for done high
while(0x80 != (0x80 & XGpio_DiscreteRead(&XGpioInst0, 1) ));

 

The last line never ends even if that IO is high.

This is how I wire up the AXI GPIO, inputs to I, O to outputs, tri-state output not used

joancab_0-1625733118702.png

 

Tags (2)
0 Kudos
7 Replies
joancab
Teacher
Teacher
483 Views
Registered: ‎05-11-2015

I checked the result of    XGpio_DiscreteRead    and it contains the output bits, it looks like reading back from the output register, so how can I read from the input register?

My understanding of how it works is that the GPIO_DATA (the only data register) contains the output data for the output pins and the reading from inputs for the pins configured as inputs, but this doesn't seem to happen even if I have input pins defined at both the IP and afterwards in software.

joancab_0-1625735529208.png

 

0 Kudos
joancab
Teacher
Teacher
440 Views
Registered: ‎05-11-2015

Unless I'm missing something, I would say that the AXI GPIO 2.0 does not support a mix of inputs and outputs in one port.

I had an 8-bit port, 7 working (checked with VIO) outputs and 1 input that could not be read.

I changed that input to another all-input port and sorted.

0 Kudos
No_Air_On_Mars
Contributor
Contributor
402 Views
Registered: ‎05-17-2021

 

I tried it, and it seems to be working (if i understand your description).

 

I have a vcu118 board, with Vivado 2019 (and SDK). And made a similar desing (see the bd pictue)  (edit: i had to add two VIOs in order to get both In/Out ports on the VIO to show up in the HW manager)

No_Air_On_Mars_0-1625846259573.png

 

 

 

I am connecting the hardware manager in vivado to the VIOs, and (using the button option) am toggling the bit that is an input to the GPIO (it's an output on the VIO) (see the hardware manager pic).

No_Air_On_Mars_1-1625846377280.png

 

 

 

And I tried this code, which prints to the uart every time the vio value changes (edit: added some writes to the GPIO output)

 

int main() {
	int Status;
	u8 oldVal = 0x80;
	u32 temp = 123;
	u8 writeVal = 0xA5;
	XGpio XGpioInst0;
	init_platform();
	Status = XGpio_Initialize(&XGpioInst0, GPIO_0_ID);
	if (Status != XST_SUCCESS) {
		xil_printf("Gpio Initialization Failed\r\n");
		return XST_FAILURE;
	}

	// Set data direction
	XGpio_SetDataDirection(&XGpioInst0, 1, 0x80);			// bit 7 input

	temp = XGpio_DiscreteRead(&XGpioInst0, 1);
	oldVal = 0x80 & XGpio_DiscreteRead(&XGpioInst0, 1);
	// wait for done high
	while (1) {  
                //read the input 3 times, waits until i click the button in the HW Manager
		for (int i = 0; i < 3; i++) {
			while (oldVal == (0x80 & XGpio_DiscreteRead(&XGpioInst0, 1))) { //wait til change
			};

			temp = XGpio_DiscreteRead(&XGpioInst0, 1);
			oldVal = 0x80 & XGpio_DiscreteRead(&XGpioInst0, 1);
			xil_printf("The oldVal changed, now its 0x%2x \n\r", oldVal);
		};


                //write some bits, which are visible in the HW Manger
		for (int i = 0; i < 3; i++) {
			XGpio_DiscreteWrite(&XGpioInst0, 1, writeVal);
			writeVal++;
			for (int j = 0; j < LED_DELAY; j++) {
				//wait for a few seconds
			}
		}

	}//end while(1)

	cleanup_platform();
	return 0;
}

 

 

Also, here is the IP settings for the AXI GPIO.  i have the tri state mask set to allow all 8 bits to be output.

No_Air_On_Mars_2-1625846778654.png

 

watari
Professor
Professor
395 Views
Registered: ‎06-16-2013

Hi @joancab 

 

Would you change mapping ? You can not read correct data, if you connect same bit number.

I guess, althogu you have to consider tri-state, you don't connect properly these signals.

 

ex.

# Only output : 8bit

Use gpio_io_o[7:0]

Use gpio_io_t[7:0] and set proper value.

 

# Only input : 8bit

Use gpio_io_i[15:8]

Use gpio_io_t[15:8] and set proper value.

 

# bi-direction : 8bit

Use gpio_io_o[23:16]

Use gpio_io_o[23:16]

Use gpio_io_t[23:16] and set proper value.

 

Hope this helps.

 

Best regards,

0 Kudos
joancab
Teacher
Teacher
327 Views
Registered: ‎05-11-2015

@watari do you mean that for every 8-bit word the direction can be input or output but not mixed and in a 16 or 32 bit word there can be a mix of in and out 8-bit words?

0 Kudos
joancab
Teacher
Teacher
327 Views
Registered: ‎05-11-2015

@No_Air_On_Mars Interesting, I need to reproduce that and research more. For the time being is sorted out and don't have much time.

 

0 Kudos
watari
Professor
Professor
262 Views
Registered: ‎06-16-2013

Hi @joancab 

 

>@watari do you mean that for every 8-bit word the direction can be input or output but not mixed and in a 16 or 32 bit word there can be a mix of in and out 8-bit words?

 

No. 

It's an example.

You can control it from 1bit.

 

Best regards,

0 Kudos