Usable Libraries

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

As a newbie to the AVR Studio 7 world, I was wondering if there are any existing library repository for SPI, I2C, etc libraries for ATTiny 85 and 88 devices.

Thanks

Dan Powell

This topic has a solution.
Last Edited: Fri. Oct 4, 2019 - 02:37 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi!

 

Welcome to AVRFreaks, the answer to your question is yes, the following link has the DFP (Device Packs) that would allow you to use the SPI, I2C...etc:

 

http://packs.download.atmel.com/

 

What you are looking for is exactly the

Atmel ATtiny Series Device Support (1.3.229)

 

However, if you are using Atmel Studio 7, then this can done automatically through Tools --> Device Pack Manager ---> Update

 

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


 

For reference....

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

Peter Fleury's libraries are often recommended here:

 

http://homepage.hispeed.ch/peterfleury/avr-software.html

 

The Arduino, of course, was originally all AVR - so you can always look at Arduino code.

Atmel Studio can import Arduino "sketches".

 

Always check-out the Product Page for the chip in question for Application Notes and example code.

 

For finding source code, try a search at Github ...

 

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

dpcons wrote:
As a newbie to the AVR Studio 7 world, I was wondering if there are any existing library repository for SPI, I2C, etc libraries for ATTiny 85 and 88 devices.
There's no official source for a complete set of peripheral libraries for tiny/mega AVRs. Some of the AVR compilers (Codevision and Imagecraft) do come with code generators that can produce template code for the peripherals (not sure how they are with complex peripherals like CAn and USB but I guess that doesn't matter for 85/88 devices). The compiler that comes with AS7 is the GNU avr-gcc compiler. It does NOT have such a template code generator. So in theory there is nothing.

 

However a few things that might help:

 

1) Over the years various luminary engineers for avr-gcc have shared some of their work. Peter Fleury has been mentioned above. Others to Google for are Pascal Stand and Martin Thomas. Both have done a lot of work with avr-gcc and shared stuff. However their work generally dates from 10+ years ago so may not "know" more modern AVR devices

 

2) Atmel created Atmel Software Framework (ASF) to provide peripheral support for some of their devices but the original versions (ASF1 to ASF3) only really targetted Xmega, UC3 and ARM. They had nothing for the simple micros like tiny and mega. In the latter stages of ASF3 and as it moved to online as ASF4/Start they did start to add a small amount of tiny/mega support but this is mainly for the devices released in just the last 2..3 years. There's still very little for "legacy"

 

3) As also mentioned the mega8 and then mega88/168/328 were the core processors in the whole development of Arduino so tons of support code was written for those. It's in C++ and higher level work is reliant on lower level functions so if you use a peripheral driver from that you may end up pulling in quite a lot of other support. But if you are not confident in writing peripheral drivers of your own this is a potential source and, as mentioned, AS7 can "import" Arduino projects so you just set up the simplest project in Arduino that only just mentions the peripherals you are interested in - then import that and it will bring in all you need.

 

To be honest, if you are not happy to program "bare metal" then a compiler like Codevision with a CodeWizard to generate code for you might actually be the most efficient way to proceed. I forget how much it is but it's around the €100 mark.

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

Personally,   I think it is unwise to start with Tiny85 or Tiny88.

 

You will make more progress with Mega328P as used in Arduino Uno.

 

You can prototype quickly with Arduino.

Then replace sections with bare-metal C, ASM, C++, ... if that appeals to you.

 

There are lots of traditional App Notes that show how to use SPI, UART, I2C, ... on regular Mega

And other App Notes that show how to emulate SPI, UART, I2C, ... on the small Tiny

 

The newer Mega4809 or Tiny817 have better peripherals that are "similar" to Xmega peripherals.

There are App Notes.

 

Incidentally,  many projects for Arduino boards can be ported to the "smaller" Tiny85 or Tiny88

Third Party Arduino Cores and libraries are available for Tiny85, Tiny88

 

David.

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

david.prentice wrote:
Personally,   I think it is unwise to start with Tiny85 or Tiny88.

Agreed.

And, in general, I would say that it's always unwise to start with the smallest chip you can find - you will spend all your time fighting the limitations, which will severely hamper your learning experience!

 

As the old saying goes,

Premature optimisation is a route of all kinds of evils

 

It is the same reason that many recommend not learning 'C' on a microcontroller - do that on a PC, then move on to the microcontroller when you're up-to-speed on the language.

 

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

dpcons wrote:
As a newbie to the AVR Studio 7 world

Do you have experience with any other IDE(s) ?

 

Do you have experience with any other microcontroller(s) ?

 

Do you have experience with 'C' (or C++) programming in general ?

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

A side note about some facts that MIGHT not be obvious from the great comments, above.

 

When people ask about libraries for a TinyXX or MegaXYZ, the answer is almost always yes, even though there is no library explicitly for that device. Why? It is because there is so much in common among them all. Yes, there are differences, most notably between older and newer chips and notably with a few of the Tiny devices that are virtually crippled (e.g. so few hardware peripherals or very little memory).

 

What this does require, however, is that the user needs to go through the library and find where the differences are. Generally, that might be a pretty daunting job. But, there is a simple way. Just add it to your project and BUILD it. The compiler will catch name differences. If you then search for those names in the library, it will show you where those are. Invariably, those spots are places where there are more problems than just names. For example, some of the chips name the UART data register UDR and others name it UDR0. If something like that is the case, then you know that ALL of the UART register names need to be changed. The smart programmer might then read (yes, actually READ) the spec sheet and verify that the control bits in your device do what the code expects.

 

It is, admittedly, a LOT harder if your device does not even have the peripheral that the library needs. If you are lucky, then the library (like FatFS, for example) will have a version of the code that implements that peripheral in software.

 

Now, the OP might retort "Well, but THAT is not what I was asking for. I really want a library that takes into account the quirks and limitations of a Tiny85!"  To which, many, here, will respond, "But, you will be better off learning those quirks and limitations now, OR you should pick a device without those quirks and limitations."

 

That is the way the ball bounces at Freaks!

 

Jim

Jim Wagner Oregon Research Electronics, Consulting Div. Tangent, OR, USA http://www.orelectronics.net

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

Hi there

Thanks for the response.

 

Yes, I've been working with microprocessors and microcomputers from the very beginning...well Intel 4004.  I worked with Intel, Motorola and TI processors in the past, as well as 6502, 8051, 80C2051, Dragonball, Z80 and many, many others.  I've used many development systems, both standalone and PC based.  I designed the embedded systems for the Barstow Solar Power Plant many years ago using M6801 microcontrollers as well as embedded systems used for medical, scientific and industrial applications...so as you can tell, I'm an oldtimer. 

I currently use the line of Arduino boards and Espressif ESP8266 and ESP32 devices on Linux and Windows PCs and do consulting in my spare time.  I got interested in the ATTiny family a couple of weeks ago for no particular reason.  I saw a YouTube video talking about the Atmel Studio 7 and it peaked my interest. Seemed like fun getting back to twiddling bits with the assembler and experimenting. I purchased some MH-Tiny boards  and thought I'd give it a go.  I'm using the AVR Pocket Programmer from Sparkfun.  (Sparkfun is about 3 miles away...very dangerous).  I had some I2C devices hanging around and I thought I'd write and asm app to talk to them.  I've used I2C since it was introduced but didn't want to make this that big an effort, so I was hoping a library routine was available somewhere...there usually is.  I wrote some trivial apps to diddle with the timers and bang out some I/O and the ATTiny88 works pretty nice.

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

Thank You for the reply

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

Thanks all for your replies. Much good info there.

Dan

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

You're welcome.

 

Now 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

dpcons wrote:
  I've used I2C since it was introduced but didn't want to make this that big an effort, so I was hoping a library routine was available somewhere...there usually is. 
If it's mainly TWI/I2C you need then Peter Fleury almost certainly is the solution. But you won't find support for many other peripherals from that source (his other major contribution is an excellent library for HD44780 LCD panels).

 

But the other thing you mentioned in #1 is SPI - I don't know of a well respected "library" for that but this is probably because SPI is so simple everyone just writes their own from scratch anyway. About the only complication of SPI is picking the right one of the 4 possible modes on the CPOL and CPHA bits.

Last Edited: Fri. Oct 4, 2019 - 08:40 AM
This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks all. It should be fun playing around.

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

clawson wrote:

dpcons wrote:
  I've used I2C since it was introduced but didn't want to make this that big an effort, so I was hoping a library routine was available somewhere...there usually is. 

If it's mainly TWI/I2C you need then Peter Fleury almost certainly is the solution. But you won't find support for many other peripherals from that source (his other major contribution is an excellent library for HD44780 LCD panels).

 

But the other thing you mentioned in #1 is SPI - I don't know of a well respected "library" for that but this is probably because SPI is so simple everyone just writes their own from scratch anyway. About the only complication of SPI is picking the right one of the 4 possible modes on the CPOL and CPHA bits.


And the trap of not setting the CS pin to be an output!
Jim

Click Link: Get Free Stock: Retire early! PM for strategy

share.robinhood.com/jamesc3274
get $5 free gold/silver https://www.onegold.com/join/713...