attiny 816 read pins problem

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

Hi all,

Sorry for stupid question but I have no ideas... It is my first experience with attiny series 1

I need to read 4 pins in interrupt (the same problem outside of interrupt handler). When I read it I get zeros for all or some pins. But when I do it in debugger I get correct values.

This is initialization:

static volatile uint8_t rcCommand;

{
	PORTA.DIRCLR = PIN1_bm;
	PORTA.OUTCLR = PIN1_bm;
	PORTA.PIN1CTRL = PORT_ISC_RISING_gc; // set interrupt PORT_ISC_RISING

	PORTA.DIRCLR = PIN4_bm | PIN5_bm | PIN6_bm | PIN7_bm;
}

This is interrupt handler:

ISR(PORTA_PORT_vect)
{
	rcCommand = 0;
	if (PORTA.IN & PIN4_bm)
		rcCommand |= 0b0001;
	if (PORTA.IN & PIN5_bm)
		rcCommand |= 0b0010;
	if (PORTA.IN & PIN6_bm)
		rcCommand |= 0b0100;
	if (PORTA.IN & PIN7_bm)
		rcCommand |= 0b1000;

	PORTA.INTFLAGS |= PORT_INT1_bm;
}

I have tried to read PORTA.IN or VPORTA.IN completely - the same result.

 

Thanks in advance

Slava

 

 

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

Did you enable  all interrupts somewhere (gives sei command)? 

Where is your debouncing? By the time the IRQ is processed, the switch could be "open".  I can't remember if this micro has a pin change IRQ flag to show which pin change IRQ is being called...that is the info you need, or you must debounce the inputs.  Even if the specific flag exists, you almost must debounce, since the bounce can last for 15ms & you'll be getting many IRQs when a button is pressed. 

When in the dark remember-the future looks brighter than ever.   I look forward to being able to predict the future!

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

By default all interrupts for the pins are disabled. I have enable one for pin1. And it works correct - I have interrupt by this pin only and have it just in time. Not sure about debounce - values comes bot from buttons but from other chip.

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

From what I understand pin1 is connected to some kind of button or trigger. So, what is connected to pins 4/5/6/7 that you are reading from?

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

To pins 1, 4, 5, 6, 7 connected RC chip - by pin1 I get interrupt about RC command received and by rest pins command code.

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

Looks like I've understand the problem - in moment when interrupt occurs, data pins has not values yet. I have add a delay for 20msec and now all ok.

 

Special thanks to  avrcandies  - his question about debounce helps me to understand the problem!