ATTINY102 simple IO program not working

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

Hello. I am using an ATMEL ICE and Microchip Studio to program an ATTINY102. It programs fine, according to the ICE, and I can read data in the memory. But the I/O pins simply are not doing anything, and I can't figure out why. I have cut it down to a very simple code at this point, just trying to turn on 2 of the pins as output. I am providing the code and the memory which is read from the chip. I don't really know how to interpret the memory readout but I hoped it might be helpful. I had no problem with the ATTINY10. Is there something special about the 102/104 that I must do to use these pins? I've scoured the datasheet and register guides.

 

Thank you..

 

#include <xc.h>
#include <avr/io.h>
#include <avr/interrupt.h>


int main(void)
{
    DDRB = 0x12;
    PORTB = 0;
    PUEB = 0;
    
    while(1)
    {
            PORTB = 0x12;
    }
}

 

 

Attachment(s): 

This topic has a solution.
Last Edited: Thu. Nov 18, 2021 - 05:39 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Greetings

 

What actually happens and what do you expect to happen? It looks to me like you are setting PB1 and PB4 low, then high and never changing them after that.

 

Until Black Lives Matter, we do not have "All Lives Matter"!

 

 

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


Correct, but I believe this should be PB2 and PB3. The registers show PORTB[0:3], but in reality, there is no PB0 pin on the attiny102, I assume this exists for use in the attiny104 so I believe that in practice, only bits [1:3] are used.

 

Anyway, I expect these pins to be output high. They are both low.

 

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

dallathaun wrote:

            PORTB = 0x12;

Bit 4 is not available, perhaps you meant 0x0A;

or perhaps 0x0C;  Your DDRB value is also wrong...

 

Fly over Jim

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

Lets go Brandon!

Last Edited: Thu. Nov 18, 2021 - 05:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

*Facepalm* Yeah that was dumb of me. It was a long night of me trying to figure out what was going on and I can't believe I did that. It should be 0x0C.

 

HOWEVER. I still have this problem using 0x04. So while I am a complete and total idiot, that does not seem to be the issue.

Last Edited: Thu. Nov 18, 2021 - 05:32 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

dallathaun wrote:

*Facepalm* Yeah that was dumb of me. It was a long night of me trying to figure out what was going on and I can't believe I did that.

 

HOWEVER. I still have this problem using 0x04. So while I am a complete and total idiot, that does not seem to be the issue.

Like we all have not done that!   No sweat...

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

Lets go Brandon!

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

Hey guys....So....I had originally started with another longer program and when it didn't work the way I wanted, I had gone through many iterations of paring it down to what I just posted. Well, I've never programmed directly through MC Studio before, in the past I normally built it and then loaded the hex file. Apparently what happened was that it did not occur to me that even though I'm doing it directly through MC Studio, I still have to, um...BUILD THE PROGRAM after each change before I can load it. Duh. Lord knows what I was loading onto this chip. Sorry to have bothered you guys!

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


dallathaun wrote:
, and I can't figure out why.
port B is mapped differently

dallathaun wrote:
I have cut it down to a very simple code at this point, just trying to turn on 2 of the pins as output.
One output pin in Atmel's blinky on tiny104 Xplained Nano.

 


ATtiny102/ATtiny104 Complete

 

Pin Functionality Difference | Differences between ATtiny4/5/9/10 and ATtiny102/104

 

AT12489: Getting Started with Atmel ATtiny102 and ATtiny104

[bottom of page 10]

"Dare to be naïve." - Buckminster Fuller

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

dallathaun wrote:
, I still have to, um...BUILD THE PROGRAM after each change before I can load it.

Ah, yes, not like the Arduino IDE where the ^ upload button, builds and uploads........    Glad you got it figured out, that would have been tough to diagnose remotely! 

Keep having fun!

 

Keys to wealth:

Invest for cash flow, not capital gains!

Wealth is attracted, not chased! 

Income is proportional to how many you serve!

Lets go Brandon!