I have been messing with AVR's XMEGA line. They are pretty amazing microcontrollers. However, Atmel changed much with this new line. I am trying to detect a pin going low.
I have tried to set the PINnCTRL
register to every combination with no luck. I can detect the pin going HIGH but not the other way around. Below is the working code for turning on the LED on pin 5 when pin 6 goes high. However, I wanted to do the same thing, just instead of when pin 6 goes high, I would like to have pin 6 go low and turn on the LED on pin 5.
Anyhow, I have not seen a lot of XMEGA stuff on here, so I thought I would try.
I am using AVR Studio and the ATXmega256A3 microcontroller.
AVR PINnCTRL Configuration Register Table (at least for the pull sections 0b00xxx000) FULL DATASHEET HERE: http://www.atmel.com/dyn/resources/prod_documents/doc8077.pdf.
On page 131 (section 13.4) this lists the definition of all of table below. NOTE: the PINxCTRL register contains more than just the pullups for settings. The bits I am working with are these: 00xxx000 The x's correspond with the listing below.
Table 13-4. Output/Pull Configuration
Description
OPC[2:0] Group Configuration Output configuration Pull configuration
000 TOTEM Totempole (N/A)
001 BUSKEEPER Totempole Bus keeper
010 PULLDOWN Totempole Pull-down (on input)
011 PULLUP Totempole Pull-up (on input)
100 WIREDOR Wired OR (N/A)
101 WIREDAND Wired AND (N/A)
110 WIREDORPULL Wired OR Pull-down
111 WIREDANDPULL Wired AND Pull-up
#include <stdio.h>
#include <avr\io.h>
#define F_CPU 32000000UL
#include <util\delay.h>
void Config32MHzClock(void);
int main(void)
{
//Init stuff..
Config32MHzClock();
CLK.PSCTRL = 0x00; // No division on peripheral clock.
PORTCFG.CLKEVOUT = PORTCFG_CLKOUT_PE7_gc;
PORTA.DIR = (1 << 5); //Sets pin5 as an output (led)
//011 PULLUP Totempole Pull-up (on input) is what is set
PORTA.PIN6CTRL = (0x30); //Sets pullup on input on pin 6.
PORTA.OUT = (1<<5); //Turn on the LED
while(1){ //Never ending main loop.
if (PORTA.IN & (1<<6)) //If pin 6 goes HIGH.
PORTA.OUT = (0x00); //Turn off LED.
PORTA.OUT = (1 << 5); //Turn LED back on.
}
}
//Function to setup clock..
void Config32MHzClock(void)
{
CCP = CCP_IOREG_gc; //Security signature to modify clock
// Initialize clock source to be 32 MHz internal oscillator (no PLL).
OSC.CTRL = OSC_RC32MEN_bm; // Enable internal 32 MHz oscillator.
while(!(OSC.STATUS & OSC_RC32MRDY_bm)); // Wait for oscillator ready
CCP = CCP_IOREG_gc; //Security signature to modify clock
CLK.CTRL = 0x01; //Select sysclock 32 MHz oscillator
};