PIND changes automatically

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

Dear partners,

I am changing some code of a program and I have a problem when I am debugging:
Firstly I define PORTD of my ATmega168, and then, when I define my PORTC value, PIND changes automatically.

Do you know what is happening when these are different ports C & D? Is it normal?

Thanks.

best regards.

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

No, it is not normal for changing one port to change a different one. It would be difficult to help much without seeing your code. If you are talking about PIND, I assume that you have set DDRD to be inputs?

There should be a 1 clock delay between the setting of PORTD and PIND reading that change. I suspect that you are setting PORTC directly after setting PORTD so the actual setting of PORTC has nothing to do with it, it's just the delay.

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

Quote:
Firstly I define PORTD of my ATmega168
What do you mean by this? PORTD is already defined in the io.h file, is it included in your project?

Have you selected the correct chip for the build?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

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

have you accidentally defined pind to be equal to the value of pinc? these should all be pre-defined.

regards
Greg

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

Thank you all for your help.

This issue is solved connecting a GND point, it was blinking PIND and executing the interruption PCINT2.

After that I have another problem. My program is a update of an old program where it entered in PCINT2 when the switch connected in PORTD7 was pushed. Now I want to enter in PCINT2 when any of 2 switches are pushed. This switches are connected to PORTD7 and PORTD5 (the new one) with external pull-up. To do that I have change some instructions:

In the initialization of the ports i had:
PORTD=0x84;
PCMSK2=0x80;

and now i have changed it to:
PORTD=0xA4;
PCMSK2=0x80;

But in this case my program enters in PCINT2 always.

Do you know why? May I have to do anything else?

Thank you.

Best regards

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

You need to change the PCMKS2 line as well to be:

PCMSK2=0xA0; 

or to make that more readable use:

PCMSK2 = (1<<PCINT23) | (1<<PCINT21);

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

Thank you Clawson,

I am sorry but yes, I put:
PCMSK2=0xA0;
and I have the same problem. The program enters in PCINT2 interruption always, without pushing any switch of PIND.
Then I can work with PCINT23, i haven´t that instruction defined, anyway I think is the same than other.
I have checked all PORTD inputs and no-one changes its value...
Do you have another idea?

Best regards.