xmega pull up / pull down resistors for the entire port at once?

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

Perhaps I'm missing out on something but I can not find the way to set pull up or pull down resistors on the xmega.

 

Let's say I want to configure port B to have all pins as inputs and pull them low. Let's assume they pins are not inputs by default

PORTB.DIRCLR = 0xFF; // Set all pins to inputs

If I would like to set a pull down resistor on a specific pin, say 2, I would do this:

PORTB.PIN2CTRL = PORT_OPC_PULLDOWN_gc;

But let's say I want to pull down all the port. How can I do that?

 

This topic has a solution.
Last Edited: Sun. Oct 30, 2016 - 08:56 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

On the xmegas, you have to do it for each pin on the port individually. So you need 8 lines of code for that.

"Some people die at 25 and aren't buried until 75." -Benjamin Franklin

 

What is life's greatest illusion?"  "Innocence, my brother." -Skyrim

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try this in C......

; Setup Port C
	ser		temp
	ldi		temp1, PORT_OPC_PULLUP_gc		; Turn on pull up resistors
	STORE	PORTCFG_MPCMASK, temp			; PORTC inputs with pull up resistors
	STORE	PORTC_PIN0CTRL, temp1

EDIT Oh joy! Look I found some in C

	PORTCFG_MPCMASK = (1<<PIN7_bp | 1<<PIN6_bp | 1<<PIN5_bp | 1<<PIN4_bp | 1<<PIN1_bp);
	PORTA_PIN0CTRL = PORT_OPC_PULLDOWN_gc;		// Turn on pull down resistors

// Setup Port C
	PORTCFG_MPCMASK = (1<<PIN7_bp | 1<<PIN6_bp | 1<<PIN5_bp | 1<<PIN4_bp | 1<<PIN3_bp | 1<<PIN2_bp); // Port C inputs with pull up resistors
	PORTC_PIN0CTRL = PORT_OPC_PULLUP_gc;
	PORTC_DIR = (1<<PIN1_bp | 1<<PIN0_bp);		// Output pins for frequency signals

 

John Samperi

Ampertronics Pty. Ltd.

https://www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

Last Edited: Sun. Oct 30, 2016 - 08:35 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I am not sure how does MPCMASK + PINnCTRL interact? I can see you define a mask for the pins you would like to pull up, but how does

 

PORTC_PIN0CTRL = PORT_OPC_PULLUP_gc;

Change all the pins on that port when you are setting the register holding settings for bit 0?

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

Wow, thanks John!

 

I have been using the xmegas for quite some time now and didn't know about this amazing feature!

So did I understand this correctly? One can set up this MPCMASK register and once one writes to any of the PINxCTRL registers, all settings will be applied to all of the pins?

 

-Patrick

"Some people die at 25 and aren't buried until 75." -Benjamin Franklin

 

What is life's greatest illusion?"  "Innocence, my brother." -Skyrim

 

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

found it in the xmega-au manual

"Some people die at 25 and aren't buried until 75." -Benjamin Franklin

 

What is life's greatest illusion?"  "Innocence, my brother." -Skyrim

 

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

Fantastic!!!

 

Thanks mates.

Last Edited: Sun. Oct 30, 2016 - 08:57 PM