Multifunction PORT on ATMEGA

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Can i setup in a port a multible functions? For example: i want to enable SPI and use the other pins normally as a GPIO pins. or, to enable UART and using other rest pins as GPIO.
How can i do that?

Last Edited: Fri. Nov 28, 2014 - 10:53 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes you can.  You don't have to do anything special.  Each pin in a port is independent of the others, and each pin's alternate functions are clearly described in the datasheet.

 

Which AVR?

Which language (C?  ASM?)

Which toolchain/IDE?

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

joeymorin wrote:

Yes you can.  You don't have to do anything special.  Each pin in a port is independent of the others, and each pin's alternate functions are clearly described in the datasheet.

 

Which AVR?

Which language (C?  ASM?)

Which toolchain/IDE?

 

- ATMEGA32L

- C

- Atmel Studio 6.2

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Just configure your peripheral (SPI, USART, whatever) as recommended by the datasheet, and configure the remaining bits on the same port.

 

For example, if you wanted to use the USART, configure it with UCSRA, UCSRB, and UCSRC.  The RXD and TXD pins are on port D, bits 0 and 1, respectively (PD0 and PD1).

 

You may then wish to use PD2 as an output, and PD3 as an input with internal pullup:

DDRD |= (1<<PD2);   // PD2 as output
DDRD &= ~(1<<PD3);  // PD3 as input...
PORTD |= (1<<PD3);  // ... with internal pullup

If all of this is new to you, stop by the Tutorial Forum and look for tutorials on bit manipulation.
 

"Experience is what enables you to recognise a mistake the second time you make it."

"Good judgement comes from experience.  Experience comes from bad judgement."

"Wisdom is always wont to arrive late, and to be a little approximate on first possession."

"When you hear hoofbeats, think horses, not unicorns."

"Fast.  Cheap.  Good.  Pick two."

"We see a lot of arses on handlebars around here." - [J Ekdahl]