Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Native blinking LED help


  • Please log in to reply
9 replies to this topic

#1 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 26 January 2011 - 04:08 PM

Hullo,

I'm trying to create a small native blinking LED sample for the Netduino. It shouldn't be that difficult. :rolleyes:

I'm using the Atmel driver package: http://www.atmel.com...sp?tool_id=3759
And I've based the sample on the "getting-started" sample.

The code is simply:
/// Burn off some cpu time
void Wait(unsigned long delay)
{
	volatile unsigned long c = 0;
	volatile unsigned long dummy = 0;
	while( c < delay*1000)
	{
		dummy++;
	}
}

int main(void)
{
    //configure led
    LED_Configure(0);
    
    // Main loop
    while (1)
    {
    	//write
        LED_Toggle(0);

        //wait
        Wait(1000);
    }
}

Where the LED-functions come from Atmel.

I've changed the led-0 to point at PB24. (The LED!)
I've changed the optimization to O0. (Just in case.)(I've also tried Os though.)
I've changed the chip to at91sam7x512.
(That should do it.)
I've tried with the YAGARTO4.4, YAGARTO4.5, CodeSourcery4.2 and CodeSourcery4.4 without succes.


Have anyone tried out the Atmel package or do someone have a small sample for a blinking LED? Or can anyone see the fatal mistake in my code?

Perhaps I need to enable the "peripheral clock" or something???

I've attached the complete project.

Attached Files



#2 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 26 January 2011 - 04:11 PM

It would be really helpful to have a small sample that works. :)

#3 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 26 January 2011 - 04:13 PM

Btw, the code compiles just fine with all compilers.

#4 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 26 January 2011 - 05:36 PM

Or can anyone see the fatal mistake in my code?

Is the LED always on? If yes, are you sure Wait(1000) waits long enough? It takes only 2 instructions to execute the while loop (1 + 3 clock cycles for add/sub and branch), so at 48 MHz it is like 83 ms for the whole Wait(1000).

#5 CW2

CW2

    Advanced Member

  • Members
  • PipPipPip
  • 1592 posts
  • LocationCzech Republic

Posted 26 January 2011 - 05:47 PM

/// Burn off some cpu time
void Wait(unsigned long delay)
{
	volatile unsigned long c = 0;
	volatile unsigned long dummy = 0;
	while( c < delay*1000)
	{
		dummy++;
	}
}

Or can anyone see the fatal mistake in my code?

I've just realized the loop is wrong, variable c never changes - there is missing increment.

#6 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 26 January 2011 - 06:02 PM

LOL, that's a rather n00bish error. I started out with a timer based wait function. This one was just a feeble attempt to do something. I think I'll completly remove the wait and main loop. If I can just make the LED turn off ...

#7 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 26 January 2011 - 06:42 PM

Perhaps I should loose the nice Atmel package at first.

This ought to turn off the LED:
#define LED_A (1 << 24)
/* Configure the pins as outputs */
AT91C_BASE_PIOA->PIO_OER = LED_A;
/* Enable PIOC control on the pins*/
AT91C_BASE_PIOA->PIO_PER = LED_A;
/* Disable pull-ups */
AT91C_BASE_PIOA->PIO_PPUDR = LED_A;
/* Turn LED off */
AT91C_BASE_PIOA->PIO_SODR = LED_A;

Alas, my board is not within reach right now.

#8 Chris Walker

Chris Walker

    Secret Labs Staff

  • Moderators
  • 7767 posts
  • LocationNew York, NY

Posted 26 January 2011 - 07:22 PM

Illishar, Be sure to use PB23 for the LED, not PB24. PB24 is the AREF_SOURCE_CONTROL. PB23 is the LED. In your code sample (one post above this one), be sure to use PIOB and not PIOA :) Chris P.S. this post makes me grateful for how easy it is to get an LED blinking with C# and .NET MF.

#9 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 27 January 2011 - 07:42 AM

Be sure to use PB23 for the LED



DOH!

#10 Illishar

Illishar

    Advanced Member

  • Members
  • PipPipPip
  • 146 posts

Posted 27 January 2011 - 09:13 AM

Thanks for the help. I've posted a small Blinking native project: http://forums.netdui...kingled-native/




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.