From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 7245 invoked by alias); 2 Oct 2007 11:40:11 -0000 Received: (qmail 7237 invoked by uid 22791); 2 Oct 2007 11:40:10 -0000 X-Spam-Check-By: sourceware.org Received: from nf-out-0910.google.com (HELO nf-out-0910.google.com) (64.233.182.190) by sourceware.org (qpsmtpd/0.31) with ESMTP; Tue, 02 Oct 2007 11:40:07 +0000 Received: by nf-out-0910.google.com with SMTP id b21so2595449nfd for ; Tue, 02 Oct 2007 04:40:05 -0700 (PDT) Received: by 10.78.149.13 with SMTP id w13mr4353293hud.1191325205001; Tue, 02 Oct 2007 04:40:05 -0700 (PDT) Received: by 10.78.191.20 with HTTP; Tue, 2 Oct 2007 04:40:04 -0700 (PDT) Message-ID: Date: Tue, 02 Oct 2007 11:40:00 -0000 From: "Rasmus Stougaard" To: "Rasmus Stougaard" , ecos-discuss@ecos.sourceware.org In-Reply-To: <20071001142828.GA22379@lunn.ch> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <20071001142828.GA22379@lunn.ch> Mailing-List: contact ecos-discuss-help@ecos.sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: ecos-discuss-owner@ecos.sourceware.org Subject: Re: [ECOS] Problem reading buttons on AT91sam7s-ek X-SW-Source: 2007-10/txt/msg00021.txt.bz2 On 10/1/07, Andrew Lunn wrote: > On Mon, Oct 01, 2007 at 02:27:32PM +0200, Rasmus Stougaard wrote: > > Hi > > > > I am trying to read the state of the buttons on a AT91sam7s-ek > > evaluation kit from atmel. > > > > I figure that something like: > > > > cyg_uint32 value; > > HAL_ARM_AT91_GPIO_CFG_DIRECTION(AT91_GPIO_PA20, AT91_PIN_IN); > > HAL_ARM_AT91_GPIO_CFG_PULLUP(AT91_GPIO_PA20, AT91_PIN_PULLUP_ENABLE); > > HAL_ARM_AT91_GPIO_GET(AT91_GPIO_PA20, value); > > trace(" AT91_GPIO_PA20 %d\n", value); > > > > Should configure the pin for input and print the current state of the > > of the pin. > > In general that looks O.K. Have you tried the other 3 switches? > > One idea i have. Is the clock to the GPIO device enabled? Check bit > AT91_PMC_PCER_PIOA in AT91_PMC_PCER. Without a clock you can do > output. But to do input you need the clock enabled. > > Andrew > > Hi Andrew Thanks a lot, that solved it :-) Here is my code for later reference (probably to myself) int get_pin_state(int gpio_pin) { int value; // Enable the clock to the GPIO (enable input sampling) HAL_WRITE_UINT32(AT91_PMC + AT91_PMC_PCER, AT91_PMC_PCER_PIOA); HAL_ARM_AT91_GPIO_CFG_DIRECTION(gpio_pin, AT91_PIN_IN); HAL_ARM_AT91_GPIO_GET(gpio_pin, value); return value; } Cheers Rasmus -- Before posting, please read the FAQ: http://ecos.sourceware.org/fom/ecos and search the list archive: http://ecos.sourceware.org/ml/ecos-discuss