What C++ code (in Atmel studio) lets you set a Shared IO port on ATTINY eval kit for your own use?

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

I've got the ATTINY 104 evaluation kit (http://ww1.microchip.com/downloa...).  See section 1.2

 

I am very happily using the available Target I/O ports.  I'm configuring them for input (DDRB |= 1<<DDRB0;) and turning on LEDs that I've connected to the evaluation board (PORTB |= (1<<PORTB0);)

 

When I try to repeat this with a Shared I/O port, nothing happens.  I assume I need to add more code beyond DDRx and PORTx to configure/use the port, but I can't find what to write. 

 

Thanks for pointers.

 

 

 

 

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

I do not understand what you mean by "shared I/O Port"?

 

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

Ah - so it's not just me, then!

 

frown

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

westfw wrote:
what you mean by "shared I/O Port"?

 

Are we talking "shared" in this context - the right-hand column:

 

 

That's just telling you what features on the board are wired to the AVR's pins;

 

eg, the on-board LED is connected to PA[5]

 

These are just hard wired - see the schematic - there is nothing to do in software to "select" them.

 

 

EDIT

 

ATtiny104 Xplained Nano

 

ATTINY104-XNANO

 

Looks a neat little kit:

 

http://www.atmel.com/tools/attiny104-xnano.aspx

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...
Last Edited: Fri. Dec 1, 2017 - 08:44 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
Ah - so it's not just me, then!
Did either of you look at the 1.2 he mentioned? It says:

 

Having said that I'm still not clear what it is he's hoping to achieve with the "shared IO"? Is it simply to use PA0..PA2, PA5, PB1..PB3 as GPIO or did he mean to use the "alternate functions" on those pins?

 

I haven't read the datasheet in detail but for PA2 specifically I assume the default state is _RESET and not an IO and that there's some kind of RSTDISBL ?

 

EDIT: yup RSTDISBL is bit 0 of Config Byte 0.

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

I just received this from David via PM:

 

via PM, David M wrote:
Have just spent 30 minutes trying to work out why AVRFreaks isn't recognising my sign-in when I write back to your thoughtful response, yet is letting me sign in on community.atmel.com...:

Perhaps a Moderator can help with that?

 

I thought I'd ask you the question over a private message instead - perhaps you could respond to the original post in the forum?

Here we go...

 

My particular goal is to reprogram one of the edge connectors (let's say PA0 which is connector 2) so that I can use it as a regular I/O port (as I'd like to connect a simple LED to that particular port).  By default, it is hard wired to the TPI Clock function, but I'm assuming the fact that the evaluation kit has 16 available edge connectors means that I can set a bit somehow to turn off the TPI Clock

Sadly, that is not the case - they are just hardwired.

 

sad

 

This is a general "issue" with all the XPlained boards: https://community.atmel.com/comm...

 

There do appear to be some links that you can remove to isolate the debugger - but then, of course, you lose all debug (and programming?) capability.

 

Check the schematic and/or user manual to see if the other features can be similarly "disconnected".

 

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

clawson wrote:
Did either of you look at the 1.2 he mentioned?

Not initially - but see #4

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

I'll add more context:

 

Currently I've connected a PIR sensor and 4 LED circuits to ports PA3, PA4, PB0, PA7 and PA6.  I've a simple state machine to turn those LEDs on and off with various delays.  I can program this just fine.

 

I need to add another 4 LED circuits to the device I'm building.  I'd like to use the 4 of the 6 ports PB1, PB2, PB3 and PA0, PA1, PA2 in the exact same way as the 5 edge connectors above.  However, they seem to be configured in a state where the capability in the "Shared Functionality" column in the table above is enabled, and thus the 6 ports aren't responding to being programmed.

 

I think what awneil is saying is that I use RSTDISBL to flip the state so that I can use PA0 as a regular IO port and edge connector which I can attach an LED to (and thus disable/ignore the TPI Clock shared function that this input port  is hooked up to by default)

 

Is there a good article, reference documentation or sample of the particular command I write in C++ to do this?  I've a hunch that I'm looking for a 1 line C++ statement to achieve this but I'm not sure where to look.

 

Thanks a ton for your help,

David

 

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

David M2 wrote:
However, they seem to be configured in a state where the capability in the "Shared Functionality" column in the table above is enabled, and thus the 6 ports aren't responding to being programmed.
Are you programming in some "environment" where maybe there is some other code that runs alongside yours that is already configuring the peripherals? Or is this just plain C, C++ or Asm? If the latter then the device will be in exactly the state at program starts as it says in the datasheet and a cursory glance through the chapter on IO does not reveal anything to suggest that you cannot just use all the GPIO "normally".

 

The one pin you can't use is PA2 because it is the reset pin. You can switch off the reset function to then use it as GPIO by switching the state of RSTDISBL. *HOWEVER* while I don't know tiny102/104 (so called 'Xtiny') the fact is that for most AVRs the _Reset pin is involved in the device reprogramming interface so for most (all?) that have RSTDISBL you actually turn off the ability to be able to reprogram the chip if you activate RSTDISBL so it's something you should only ever do as the very last resort when all other pins on the device are used up and you have no where else to go and you are happy this may the very last time you ever get to reprogram it.

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

RSTDISBL just controls whether the PA0 PA2 pin within the microcontroller acts as RESET or not - it has no effect on any of the connections outside the chip on the board.

 

It is a Fuse - I don't think it can be changed by your code?

 

As clawson says, If you do disable it, you will never be able to program the chip again!!

 

As for (some of) the other "shared" pins, there are links to be removed to physically disconnect them from the "shared" function; but this is a physical modification - not a software control.

 

And, again, once they are removed you won't be able to program or debug.

 

EDIT

 

typo

 

EDIT 2

 

Corrected: Reset on PA2 not PA0. - see #11

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...
Last Edited: Fri. Dec 1, 2017 - 10:23 AM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

awneil wrote:
RSTDISBL just controls whether the PA0
Umm PA2 not PA0

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

corrected

 

blush

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

Thanks all for the help your gave previously.  I did considerably more playing around with the ATTiny104 Nano Evaluation kit this weekend. 

 

I discovered a couple of things:

1) All but the PA2 port are programmable as I/O ports - this gives 11 programmable ports without any physical rewiring of the Nano Kit.

2) BUT - if you have any wires between the evaluation kit and a breadboard or other circuitry then when you use Atmel studio on the PC to program the device via the USB connection, it can yield errors saying the device could not be programmed. 

 

When I disconnected the wires from the eval kit, plugged out the device from the PC and plugged it back in again, I found I was able to program it just fine.  I needed to repeat this unwiring/unplugging routine to program the 11 ports.

 

David

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

David M2 wrote:
 if you have any wires between the evaluation kit and a breadboard or other circuitry then when you use Atmel studio on the PC to program the device via the USB connection, it can yield errors saying the device could not be programmed. 

Of course it will!

 

As mentioned previously, (some of) the "shared" pins are used by the programming process;  so, if you wire other stuff to them, you will most likely interfere with the programming process - which would cause errors!

 

EDIT

 

The ATtiny104 Xplained Nano USER GUIDE - linked in the OP - wrote:

5.1. Tiny Program Interface

 

The Tiny Program Interface (TPI) uses two pins to communicate with the target.

 

Table 5-1. shows the TPI Connections:

 

  • PA0  = TPI clock
  • PA1  = TPI data 

 

 

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...
Last Edited: Mon. Dec 4, 2017 - 11:23 AM