Setting PortB pins disables PortA pins on ATtiny26? (help)

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

I'm stuck trying to figure out why writing '1' to some PortB output pins, seems to disable PortA output pins (apparently makes them low no matter what I try). I have LEDs on 5 PortA pins and 3 PortB pins. I can turn on the PortA LEDs by making the pins high, but as soon as I turn on a PortB LED, all the PortA LEDs go out and I can't get them to work anymore.

I've looked into the other functions on PortB, but can't see how any of them are causing this problem.

Some sample code is below. I've tried writing to different pins after delays so I can see what happens.

I'm sorry to turn to the forum for this, but I've read throught the datasheets, tried some searches, and I'm pulling my hair out. I've tried all the logical things I can think of and have even stooped to dumb things, like second guessing if PortA |= 0b11110000 is really the same as PortA = PortA | 0b11110000 (you'll see the later still in the code below).

Any help would be most appreciated!

Thanks,
Tim

#include 
#include 
#include  
#define F_CPU 8000000UL

#include 

int main(void)
{

    cli(); //turn off all interrupts - tried this in desperation

    //configure pins
    DDRA =  0b11111100;	//make A.2-7 output, others input
    DDRB =  0b01111111;	//make B.0-6 output, B.7 is reset

    PORTA = PORTA | 0b00110000;
    _delay_ms(1000.0);
    PORTA = PORTA | 0b11111000;
    _delay_ms(1000.0);

    PORTB = PORTB | 0b01000000;  //PORTA LEDs go out!
    _delay_ms(1000.0);
    PORTB = PORTB | 0b01110000;
    _delay_ms(1000.0);

    PORTA = PORTA | 0b01110000;

    while(1)
    {
    }

    return 0;
}
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

are all power and ground pins hooked up, and at proper levels?

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

I think you saved me!! I only had VCC (pin 5) and one GND pin (pin 16) connected. I just quickly tried it with the AVCC and the other GND pins also connected, and it looks like the AVCC pin did the trick. It makes sense now that I read the datasheet:

Quote:

AVCC is the supply voltage pin for Port A and the A/D Converter (ADC). It should be externally connected to VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a low-pass filter...

Dumb mistake, and one I'm not sure I ever would have found.

Many thanks!
-Tim

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

Well, unconnected pins float, and on AVRs there is some leakage from one side to the other (digital & analog). In your situation, there could be paths via protection diodes and the like.

The BOD will trigger when EITHER Vcc or AVcc is below level. In your case it seems the symptoms are backward but who knows with the sneak paths.

Lee

You can put lipstick on a pig, but it is still a pig.

I've never met a pig I didn't like, as long as you have some salt and pepper.

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

Hopefully I won't make that mistake again! Thanks again for asking the the right question!

Tim