09-11-2010 07:40 AM
I am having difficulty using some of the Xilinx provided GPIO functions and examples. I traced the issue and found that the data register for a GPIO isn't being read when it is configured as an output.
The Xilinx functions XGpio_DiscreteSet() and XGpio_DiscreteClear() read the data register and modify only the bits specified by a mask. These functions fail to work properly for me and any read from a GPIO output returns a 0, regardless of the state of the output.
In the GPIO data sheet (v2.00.a, DS569 Apr 19, 2010) it specifically says on pg 10, Table 6, Note 2, that "When a GPIO pin is configured as an output, the corresponding data register bit is write only, it cannot be read."
Either I am doing something wrong or the Xilinx provided examples and functions should be modified to reflect the functionality of the hardware. The code segment below produces the faulty behavior.
int status, i;
status = XGpio_Initialize(&LEDs, XPAR_LEDS_8BIT_DEVICE_ID);
if(status != 0)
XGpio_SetDataDirection(&LEDs, 1, 0);
XGpio_DiscreteWrite(&LEDs, 1, 0xff);
// Correctly lights all LEDs
i = XGpio_DiscreteRead(&LEDs, 1);
xil_printf("Read 0x%x from GPIO\n", i);
// Reads 0x0 from GPIO, even though all LEDs are lite
XGpio_DiscreteClear(&LEDs, 1, 0x1);
// Turns off all LEDs, not just the LSB
09-12-2010 09:23 AM
So is the issue that calling a read function against a register that cannot be read is giving an incorrect value?
If thats the case, I'd expect this behavior to be normal. What are you expecting to occur?
09-13-2010 12:21 PM
The issue is that, as far as I can tell, the GPIO hardware does not support reading from an output while the Xilinx-supplied driver functions XGpio_DiscreteSet and XGpio_DiscreteClear require that the GPIO hardware support read-modify-write for outputs.
Thus, these functions and the SDK examples that use them do not work correctly.