Solved: ATtiny85 with AVRstudio 7+Proteus wrong Port for I2C

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

Hi,

 

I have configured my portB of ATtiny85 in AVRstudio7 for 3 leds like this:

 

int main(void)
{

DDRB |= (1<<PB1)| (1<<PB3) |(1<<PB4);

PORTB &=~ (1<<PB1)| (1<<PB3) |(1<<PB4);

while (1) 

    {

PORTB ^=(PB4);

_delay_ms(30);

PORTB ^=(PB4);

PORTB ^=(PB1);

_delay_ms(30);

PORTB ^=(PB1);

PORTB ^=(PB3);

_delay_ms(30);

PORTB ^=(PB3);

    }

}

 

Something  are wrong in my small project, because this only happen with attiny85 MCU Device.

The led that blink is the LED2 connected PB1 pin 6 of ATtiny85, others two wont blink.

I tried to build some in I2C, but for now I have this kind of issue.

I’ve tried to call intx5.h library, but I have a error "Include <avr/io.h> instead of this file."

So I include <avr/io.h>.

Other test I have made is: change the DDRB|=0xFF, and the PORTB |=0xFF,

It’s works,

but for my work couldn’t be like this, because I have to change some specific bits to hight and Low everytime.

I have two gif to show the issue.

Any suggestion?

 

Attachment(s): 

Last Edited: Sat. Apr 21, 2018 - 02:20 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I'm so sorry, About this silly topic, can you delete then?

 

I found the problem,

 

simple :

PORTB ^=(1<<PB4);

_delay_ms(30);

PORTB ^=(1<<PB4);

PORTB ^=(1<<PB1);

_delay_ms(50);

PORTB ^=(1<<PB1);

PORTB ^=(1<<PB3);

_delay_ms(40);

PORTB ^=(1<<PB3);

 

Grrr...

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

norlinux wrote:
can you delete then?

No, but you can mark the solution - see Tip #5

Top Tips:

  1. How to properly post source code - see: https://www.avrfreaks.net/comment... - also how to properly include images/pictures
  2. "Garbage" characters on a serial terminal are (almost?) invariably due to wrong baud rate - see: https://learn.sparkfun.com/tutorials/serial-communication
  3. Wrong baud rate is usually due to not running at the speed you thought; check by blinking a LED to see if you get the speed you expected
  4. Difference between a crystal, and a crystal oscillatorhttps://www.avrfreaks.net/comment...
  5. When your question is resolved, mark the solution: https://www.avrfreaks.net/comment...
  6. Beginner's "Getting Started" tips: https://www.avrfreaks.net/comment...
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Why would you do something so ambiguously???

DDRB |= (1<<PB1)| (1<<PB3) |(1<<PB4);
PORTB &=~ (1<<PB1)| (1<<PB3) |(1<<PB4);

So now you will have no idea how all of your port pins are set up???  Is PB0 set to input or output, can' tell here.  Something as important as IO configuration should be made crystal clear (of course there is some initialization happening somewhere that we might assume) Why would you not simply set them to what you want?  Reduce your risk of error whenever you can.

DDRB=your settings
PORTB=your settings

DDRB= (1<<PB1) | (1<<PB3) | (1<<PB4);
PORTB= 0

 

When in the dark remember-the future looks brighter than ever.

Last Edited: Sat. Apr 21, 2018 - 03:41 PM