Reading from GPIO


I had the problem of not being able to read from the GPIO pins, managed to solve it with Ken’s help and figured others may benefit from the question and answer:

[color=#222222][size=small][font=arial, sans-serif]============[/font][/size][/color]

[color=#222222][size=small][font=arial, sans-serif][color=#333333][size=small][font=Tahoma, Verdana, Arial, sans-serif]I’ve been trying to read the values on the pins of the dw1000 on one of the boards we use to no avail. I’ve got a pull-up resistor on GPIO0 and GPIO1, depending on the individual dw1000 in order to identify them. Using the api I can set GPIO0 and 1 to be output, and to pull to gnd or set high. This is easily verifiable with a multimeter, they do pull down when set to output and 0 and raise the voltage from 3.05V to 3.34V when 1. [/font][/size][/color]

[color=#333333][size=small][font=Tahoma, Verdana, Arial, sans-serif]However, I’ve not found a way of having them set to input and then reading if there is a pull-up resistor connected or not. I thought it was as easy as reading the RAW register, like so: [/font][/size][/color]

[color=#333333][size=small][font=Tahoma, Verdana, Arial, sans-serif]uint8_t buf[4]={0,0,0,0};[/font][/size][/color]
[color=#333333][size=small][font=Tahoma, Verdana, Arial, sans-serif]dwt_readfromdevice(GPIO_CTRL_ID, GPIO_RAW_OFFSET,4,buf);[/font][/size][/color]

[color=#333333][size=small][font=Tahoma, Verdana, Arial, sans-serif]However, all I get (without applying the mask to the read value) is: [/font][/size][/color]
[color=#333333][size=small][font=Tahoma, Verdana, Arial, sans-serif]0xDE AD 00 00 [/font][/size][/color]
[color=#333333][size=small][font=Tahoma, Verdana, Arial, sans-serif]regardless if the GPIO is pulled high or not. The last 0x00 should have been showing something other than 0x00. No? [/font][/size][/color][/font][/size][/color]
[color=#222222][size=small][font=arial, sans-serif]======================[/font][/size][/color]

[color=#222222][size=small][font=arial, sans-serif][color=#222222][size=small][font=arial, sans-serif]Checked it here and the following code works fine … NOTE: remember to turn GPIO clocks ON.[/font][/size][/color]

[color=#222222][size=small][font=arial, sans-serif] /* 1st enable GPIO clocks */[/font][/size][/color]

[color=#222222][size=small][font=arial, sans-serif] pmsc_clock_ctrl = dwt_read32bitreg(PMSC_ID);[/font][/size][/color]

[color=#222222][size=small][font=arial, sans-serif] dwt_write32bitreg(PMSC_ID, pmsc_clock_ctrl | PMSC_CTRL0_GPCE | PMSC_CTRL0_GPRN) ;[/font][/size][/color]

[color=#222222][size=small][font=arial, sans-serif] /e.g. test GPIO 5 and 6 - set 5 as input and 6 as output - these as accessible on the EVB1000/[/font][/size][/color]

[color=#222222][size=small][font=arial, sans-serif] dwt_setgpiodirection(GxM6 | GxM5, GxP5);[/font][/size][/color]

[color=#222222][size=small][font=arial, sans-serif] [/font][/size][/color]

[color=#222222][size=small][font=arial, sans-serif] dwt_setgpiovalue(GxM6, GxP6); /* set GPIO6 high */[/font][/size][/color]

[color=#222222][size=small][font=arial, sans-serif] /* read GPIO 5 raw value */[/font][/size][/color]
[color=#222222][size=small][font=arial, sans-serif][color=#222222][size=small][font=arial, sans-serif] test32 = dwt_read32bitoffsetreg(GPIO_[/font][/size][/color][color=#222222][size=small][font=arial, sans-serif]CTRL_ID, GPIO_RAW_OFFSET);[/font][/size][/color][/font][/size][/color]

[color=#222222][size=small][font=arial, sans-serif][color=#222222][size=small][font=arial, sans-serif]where GPIO5 and GPIO6 have been shorted - hence the coupling. [/font][/size][/color][/font][/size][/color]

[color=#222222][size=small][font=arial, sans-serif][color=#222222][size=small][font=arial, sans-serif]And, the answer was that I had missed to turn on the GPIO clocks. [/font][/size][/color][/font][/size][/color]