Atmel website | ARM Community | AVR freaks | Technical Support
Banner
 FAQ •  Search •  Register •  Login 

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Using a bunch of PIO lines as an output port.
PostPosted: Thu Nov 18, 2010 3:42 pm 
Offline

Joined: Mon Nov 01, 2010 12:14 am
Posts: 4
Hi all,

I have an AT91SAM7S-EK and am trying to use a group of 8 PIO lines as a bus to communicate with another micro, through a buffer.

I understand how to set them up as outputs and understand the seperate SET/RESET registers for configuring them, but I can't seem to get things working.

My current code is :

[code]

#define BusPins ( AT91C_PIO_PA24 | AT91C_PIO_PA25 | AT91C_PIO_PA26 | AT91C_PIO_PA27 | \
AT91C_PIO_PA28 | AT91C_PIO_PA29 | AT91C_PIO_PA30 | AT91C_PIO_PA31)

#define BusShifts 24

const Pin BusPinsOut =
{
BusPins,
AT91C_BASE_PIOA,
AT91C_ID_PIOA,
PIO_OUTPUT_1,
PIO_PULLUP
};

volatile unsigned char bus_out = 0;

void Configure_BusPins(void)
{
PIO_Configure(&BusPinsOut,1);
}

void Write_BusPins(unsigned char ToWrite)
{
unsigned int WriteVal;

// Calculate value to actually write
WriteVal=((unsigned int)ToWrite << BusShifts) & BusPins;

// Set 1 bits high
AT91C_BASE_PIOA->PIO_SODR=WriteVal;

// Set 0 bits low
WriteVal=(~WriteVal) & BusPins;
AT91C_BASE_PIOA->PIO_CODR=WriteVal;
}

[/code]

In my main I make a call to Configure_BusPins() to configure the pins.
I have a timer that flashes the onboard LEDs periodically, and then calls WriteBusPins(bus_out++) to output the value to the pins and increment it.

However as soon as the first write takes place the LEDs stop updating.
I temporaly put printf statements in WriteBusPins() and they seem to have the correct values being written from 0x00000000 to 0xFF000000, note the lower six digits are always 0 as expected.

Does anyone know what I am doing wrong ??

Cheers.

Phill.


Top
 Profile  
 
 Post subject: Re: Using a bunch of PIO lines as an output port.
PostPosted: Wed Dec 08, 2010 5:03 am 
Offline

Joined: Fri Nov 19, 2010 8:46 pm
Posts: 9
[quote="PhillHS"]I have an AT91SAM7S-EK and am trying to use a group of 8 PIO lines as a bus to communicate with another micro, through a buffer.

[code]
void Configure_BusPins(void)
{
PIO_Configure(&BusPinsOut,1);
}
[/code]
In my main I make a call to Configure_BusPins() to configure the pins.[/quote]

Sorry for the late reply; you probably found out how to do things by now.
I think you're missing some configuration, otherwise things look ok to me.

[quote]I have a timer that flashes the onboard LEDs periodically, and then calls WriteBusPins(bus_out++) to output the value to the pins and increment it.

However as soon as the first write takes place the LEDs stop updating.
I temporaly put printf statements in WriteBusPins() and they seem to have the correct values being written from 0x00000000 to 0xFF000000, note the lower six digits are always 0 as expected.

Does anyone know what I am doing wrong ??[/quote]

You should probably consider the following, in (approximately) this order...
[code]AT91F_PIO_Enable(...);
AT91F_PIO_OutputEnable(...);
AT91F_PIO_CfgPullup(...);
AT91F_PIO_ClearOutput(...);
AT91F_PIO_SetOutput(...);[/code]

...I will suggest, for your use, that you consider the following...
[code]AT91F_PIO_CfgDirectDrive(...); /* this allow you to write the values _directly_ instead of using set/clear */[/code]
...you can then write the values using...
[code]AT91F_PIO_ForceOutput(...);[/code]

...instead of using...
[code]AT91F_PIO_SetOutput(...)[/code]
...and...
[code]AT91F_PIO_ClearOutput(...)[/code]
...I believe, in your case, that would be much faster.
The parameter for CfgDirectDrive is the bitmask that you will 'write at once'. All other bits are left unchanged, and can still be changed by AT91F_PIO_SetOutput/AT91F_PIO_ClearOutput. (same as AT91C_BASE_PIOA->PIO_CODR and AT91C_BASE_PIOA->PIO_SODR)

Your routine could then be reduced to the following:
[code]void Write_BusPins(unsigned char ToWrite)
{
unsigned int WriteVal;

// Calculate value to actually write
WriteVal=((unsigned int)ToWrite << BusShifts) & BusPins;

AT91C_BASE_PIOA->PIO_ODSR=WriteVal;
}
[/code]


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: