Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] How to enable alternate function of port pin in ATmega32?

Status
Not open for further replies.

Embedded_Geek

Full Member level 6
Joined
Jul 5, 2010
Messages
342
Helped
58
Reputation
116
Reaction score
56
Trophy points
1,318
Location
Germany
Activity points
2,974
Could anyone please tell me as to how the alternate function of port pin are enabled in ATmega32?
 

Could anyone please tell me as to how the alternate function of port pin are enabled in ATmega32?
There is no certain register that controls port pins functionality. Instead, each peripheral connects or disconnects itself to the corresponding port pin.
Take PWM as an example.



To set PWM 1 in fast mode, you need to connect it to port pins using the four high bits of TCCR1A. TCCR1A is a dedicated register to timer 1 and not a general pin selection register.

Hope it is more clear for you now.
Alexandros
 
My doubts are given below in detail

As we know SPI is multiplexed with the normal gpio pin. So, in order to use it as gpio pin I have to only modify the Direction register and the corresponding port pins. What if I want to use SPI instead of gpio?
 
Last edited:

Embedded_Geek said:
What if I want to use SPI instead of gpio?

The following part of code is given inside ATmega32 datasheet.

Code:
void SPI_MasterInit(void)
{
  /* Set MOSI and SCK output, all others input */
  DDR_SPI = (1<<DD_MOSI)|(1<<DD_SCK);
  /* Enable SPI, Master, set clock rate fck/16 */
  SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR0);
}

After this part, examples for master transmit and slave receive are also given.
SPCR's bit6 controls this function:

• Bit 6 – SPE: SPI Enable
When the SPE bit is written to one, the SPI is enabled. This bit must be set to enable
any SPI operations.

View attachment ATmega32.pdf
 
Okay. This means that enabling and configuring SPI will enable the alternate function (SPI). So whatever peripherals are muliplexed we have to only enable and configure the peripheral without bothering about whether it is multiplexed or not right???

I was wondering how to do it since in cortex M3 processors we have to enable the alternate function separately so thought it would be similar in case of AVR also.
 

Embedded_Geek said:
So whatever peripherals are muliplexed we have to only enable and configure the peripheral without bothering about whether it is multiplexed or not right???
Correct. To be honest, it never happened to me to multiplex alternate functions in a single pin. To be accurate I avoid it.
Recently it happened to have a PWM running and when it was stopped, the pin was staying at high state. I had to disconnect PWM from its pin every time the PWM was stopped.
AVRs have a simple architecture and this is one aspect of it.
I have also worked with MCUs that had a pin selection register, I think it was better in this way. But as with all things in life, you get used to it! :smile:
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top