Tiny AVR-0 family. Can you please help me on this family? - Page 1
Forum section: electronics / general

author: Moriambar
author_rank: Unknown
timestamp: April 20, 2019, 01:04:23 pm
content: Hi there,up until now I was an happy avr enthusiast (meaning that, in the past I easily found out how to program them and succeeded easily). Now I'm seeing these new mcus like the tiny avr 0-series (eg attiny202) and they seem quite interesting.I'm kinda a beginner regarding this, though, so I'm confused about this:- Can I use my trusty usbasp to program them, or should I get an expensive pickit or something to do it? I am used to put an icsp header onto the board and then use an usbasp to program my tinys… is this still viable?- I understand that the arduino IDE is not a feasible editor for these, and I installed MPLAB x on my mac, but I actually don't know where to look for existing libraries, like good ol' wire for arduino/attiny (Via core). Can anybody help me?Thanks

author: alan.green@gmail.com
author_rank: Unknown
timestamp: April 20, 2019, 09:02:32 pm
content: I can confirm that the new 0-series and 1-series ATTinys are cheap, cheerful and fun!My setup for programming standalone chips is Atmel Studio 7 + Atmel ICE debugger. I can recommend this to anyone who wants it to "just work". I've had no problems at all with ATTiny404, 1616 and 3217 chips.For an equivalent setup with MPLAB-X, you could try thePICkit-4 debuggeror theMPLab Snap. According tothis chartthey both offer "beta" support for AVR parts.Drawbacks of my setup are:Atmel Studio is Windows only.This StackExchange postmight be useful for you. (Spoiler: it's hard, do something else instead)The Atmel ICE debugger is relatively expensive. That said, I have saved so much time by being able to step through code and spot my mistakes that I consider it money well spent.I've also used theATTiny416 Xplained Nanoand it too, "just works" with Atmel Studio.If you're looking for something less expensive, there are other options you'll need something that works with the UPDI (Unified Program and Debug Interface) protocol.Pyupdilooks useful for programming. There is alsothis guideto re-purposing the debugger from an xplained kit, and, apparently itcan be made to work with UPDI.

author: Moriambar
author_rank: Unknown
timestamp: April 21, 2019, 08:24:33 am
content: thanks for your reply. I never used the debugging features, honestly, and although I see the huge advantage of it, I usually do small projects so I don't think I quite need it yet.I'm used to either program the chip directly (learned using Make: Avr programming book) or via arduino ide.So what I am trying to do is to replicate the same thing using a different programmer. The problem is that I don't know where to start. Your insightful post has given me some useful pointers, so I thank you again and plan to read it carefully and perhaps come back here later!

author: Simon
author_rank: Unknown
timestamp: April 21, 2019, 08:53:57 am
content: So microchip now own atmel and have now started to support atmel chips in their own MPLAB wich is based I think on beans IDE so it is probably cross platform.You will be very lucky to find any libraries that work outside of the stuff included with AVR-GCC because they are new and all of the register names are different but not only that. The register setup is now that every register appears as a struct variable so not everything will port directly across.I just looked at Peter Pleury's Hitachi LCD controller library and while I have not tested it yet I think i was successful in making the few edits required for it to work on the new mega 0-series. Now the problem with peters library was that it used adress offsets for the port registers. You told it the port you were using and by defaul say PORTA was also the address of the PORTA register and the PIN and DDR registers were specified as offsets from PORTA. Obviously on the new series this does not work but I checked the new register address ofsets and put them in so that it should work.Now I am looking at the adafruit graphical LCD library and it looks like you tell it each and every port name you are using so it should hopefully work but I have only just looked at it.

author: Simon
author_rank: Unknown
timestamp: April 21, 2019, 08:58:09 am
content: And of course it won't work because it talks serial with the display and all of that will be different.

author: Moriambar
author_rank: Unknown
timestamp: April 21, 2019, 09:00:34 am
content: Quote from: Simon on April 21, 2019, 08:53:57 amI would settle for the pin definitions, and a couple of basic library (eg, spi, i2c). But hey, I can still wait and use the old avr stuff, which does less and costs more, but at least I know how to use

author: Simon
author_rank: Unknown
timestamp: April 21, 2019, 09:04:07 am
content: Well I am at the start and have bumbled around so have decided that as I have nothing certain yet i may as well move in with the new stuff.

author: Moriambar
author_rank: Unknown
timestamp: April 21, 2019, 09:06:12 am
content: Quote from: Simon on April 21, 2019, 09:04:07 amYes I think you're right. I have been tinkering with micros for about 6 years now so the switch is kinda harder for me. I really hope a good book on the new avr will arrive asap as well as arduino support. The latter is definitely a game changer

author: Simon
author_rank: Unknown
timestamp: April 21, 2019, 09:12:15 am
content: Well I am not very experienced in them. I almost gave up on electronics because I could not get my head around it all. Books? forget that, no one writes any.i started to write my own wiki for the mega 0 series so that I can bring together all of the information that is sometimes spread around the datasheet into one place about each peripheral.If you know the legacy AVR then the new series are not too hard, it,s just that the register names have changed and you will have to write the low level stuff yourself or modify other libraries.

author: Moriambar
author_rank: Unknown
timestamp: April 21, 2019, 09:16:47 am
content: Quote from: Simon on April 21, 2019, 09:12:15 amWell it's a bit more than that, namely:find a suitable programmer or modify one (the tip given above is very helpful) because a 3$ usbasp does not work anymoreunderstand where to find the pin defines (or write one)understand which toolchain is necessary and how to install it onto my macthen all that you saidWhat I'm saying is: I'd be happy if all I had to do was writing the libraries or modify the existing ones: I currently have more or less no clue on how to blink a led on an attiny 202

author: Simon
author_rank: Unknown
timestamp: April 21, 2019, 09:29:21 am
content: Read the series manual, that explains the pins/ports. Ther are actually better named that they use to be. You can of course come up with your own nmemonics that define the code. Bcause they use truct variables it is easier now because the struct variable is x.y so you can mix definitions oy x and y to get the x.y register name.You want to use the Atmel ICE to program the devices and if you can get MPLAB for mac that is all you need.

author: alan.green@gmail.com
author_rank: Unknown
timestamp: April 21, 2019, 10:07:14 am
content: Quote from: Moriambar on April 21, 2019, 09:16:47 amRegarding libraries, you can download Microchip's lCheck out start.atmel.com - it provides you with startup code and libraries for all the modern AVR chips, including the ATTiny202.To blink an led:Go to start.atmel.comClick on Create ProjectSelect ATTiny202 from the list of partsOn the Pin Mux page, select a pin (say PA3), name it LED and set it to be a digital outputClick on "Export Project", make sure MPLAB X is selected and exportImport into MPLAB XYou'll then have libraries which let you blink the IDE with something like this code:Code:while (1) {_delay_ms(500);LED_toggle_level();}All the code for the libraries is available in the IDE, so you examine it to see exactly how LED_toggle_level() manipulates the registers.If you select an i2c peripheral, it will generate i2c drivers, too. These drivers are a bit more sophisticated than Arduino's wire library, but are well documented (see the doxygen directory) and easy enough to work with.I was surprised to find that MPLAB claims to support the Atmel ICE that already own - will definitely be trying it out.

author: Simon
author_rank: Unknown
timestamp: April 21, 2019, 10:12:27 am
content: The problem I have with the atmel start is that you set stuff up and then what? so i setup a PWM output, how do i actually tell the pin to produce a cetain PWM duty? where are the instructions for driving these libraries?

author: Moriambar
author_rank: Unknown
timestamp: April 21, 2019, 10:20:38 am
content: Quote from: alan.green@gmail.com on April 21, 2019, 10:07:14 amThanks, I'll have to try. First I'll have to make a compatible UPDI programmer (I know it's possible) looking online.

author: Simon
author_rank: Unknown
timestamp: April 21, 2019, 10:23:46 am
content: Just buy the atmel ICE

author: Moriambar
author_rank: Unknown
timestamp: April 21, 2019, 10:24:36 am
content: Quote from: Simon on April 21, 2019, 10:23:46 amjust about 120€ over my budget, sorry

author: Simon
author_rank: Unknown
timestamp: April 21, 2019, 10:26:22 am
content: well for free you get nothing. You spend time making a programmer that will be a project in itself or actually do the job you want to do.

author: Moriambar
author_rank: Unknown
timestamp: April 21, 2019, 10:28:09 am
content: Quote from: Simon on April 21, 2019, 10:26:22 amBut time does not come out of my bank account, while money does. I do this as an hobby, not professionally, and I have all the time I need, but not the money, do I'd rather spend some time than a lot of money

author: Simon
author_rank: Unknown
timestamp: April 21, 2019, 10:30:13 am
content: Fair enough.

author: Simon
author_rank: Unknown
timestamp: April 21, 2019, 10:50:07 am
content: And the problem with atmel start is that it is broken, from the pwm_basic.dox file in the documentation section of the prject I just setup that only has the PWM output enabled:Code:/*------------------------------------------------------------------------*/ /**\addtogroup doc_driver_pwm_basic PWM Basic Drivers\brief Driver for basic PWM functionality.The PWM Basic driver provides basic PWM functionality.The driver has the following features:- Initializing the hardware implementing the PWM as specified by the user in START- Supports the number of PWM channels provided by the underlying hardware- Enable and disable output of PWM channels on I/O pins- Setting duty cycle for each of the PWM channels- Load TOP value for the PWM, to specify resolution- Register ISR callback routine to be called on counter overflowThe application can change the period or duty cycle when the PWM is running.Functions are provided to configure these two parameters.Note these are raw register values and the parameter duty_cycle meansthe period of first half during one cycle, which should not be larger thantotal period value.The user can hookup a callback to the Overflow ISR, specifying any actions to beperformed by the ISR. To generate code for including a callback handler,tick the "Include harness for IRQ on overflow"- box in START. START allows theuser to specify the rate R at which to call the ISR callback function. Thecallback function is called every R'th ISR execution. If R==0, the callback isnot called by the ISR.The PWM basic driver uses the same bit width as the Timer or PWM hardwarethe driver uses, typically 8 or 16 bits. The data types used in internalvariables and parametyers to functions reflect this bit width.\section doc_driver_pwm_basic_functional Functional DescriptionThe PWM Basic driver is built on top of a hardware resource providingPWM functionality. This includes a counter counting from BOTTOM to TOP(or vice versa), and a compare register per channel. Everytime the valueof the counter matches the value of the compare register, a signal is sentto an output pin waveform generator, generating an appropriate waveformon the I/O pin mapped to that PWM channel. The functions<component_name>_enable_output_chN and <component_name>_disable_output_chNenables or disables PWM output in the I/O pin mappedto PWM channel N. When output is enabled, the I/O pin output value iscontrolled by the PWM module. When the PWM output is disabled, the I/O pin valueis not controlled by the PWM module, but by other modules or used asgeneric I/O pin.The <component_name>__load_counter() function loads the counter in the Timermodule with the specified value. The <component_name>__load_top() functionloads the TOP value (sometimes called PERIOD) register with the specifiedvalue. For each of the PWM channels 0 to N, a function<component_name>_load_duty_cycle_chN() loads the duty cycle register of thatPWM channel with the value specified.The <component_name>_register_callback()-function allows the application tohookup a callback function to the overflow ISR.\section doc_driver_pwm_basic_hardware Hardware DependenciesThe PWM Basic driver needs Timer or PWM hardware to be available on the device.When the user has selected a device and added a PWM component,the Driver field in the Component Settings pane in START willlet the user select which timer driver to use, select *Drivers:PWM:Basic*to use the PWM Basic driver.The Configuration Pane in START will display options that aredependent on the hardware used to implement the PWM driver.For example, an option may allow changing the clock prescaling usedto drive the underlying timer hardware.Different Timer or PWM hardware offer a choice of different PWM modes, such as:- Single slope- Dual slope (Phase Correct)- Dual slope (Phase and Frequency Correct)The choice of PWM mode is not visible to the PWM Basic driver other than forinitialization of the hardware. The user must make sure that a suitable modeis chosen when selecting a configuration in START.In some underlying hardware, the PWM channels are numbered differently from 0 to N.Frequently, timers with PWM support provides two PWM channels named A and B, where:- Hardware channel A is mapped to PWM Basic channel 0- Hardware channel B is mapped to PWM Basic channel 1In some underlying hardware, some of the PWM modes does not allow the TOP value to bechanged, instead it is fixed at a value such as 0xff, 0x1ff or 0x3ff. For such hardware,the function <component_name>_load_top() does nothing.Some underlying hardware have both a buffered and unbuffered version of the Periodand the Compare registers. For these hardwares, the PWM Basic driver writes tothe *buffered* Period and Compare registers in the<component_name>_load_duty_cycle_ch<n>() and <component_name>_load_period() functions.\section doc_driver_pwm_basic_software Software DependenciesThe PWM Basic may be configured to use use the interrupt functionalityof the underlying timer or PWM hardware. Make sure that global interruptsare enabled (using sei()) and that the Interrupt Controller, ifpresent, is configured so that the Overflow interrupt is servicedcorrectly.\section doc_driver_adc_basic_code Code example\code#include <atmel_start.h>volatile bool isr_executed = false;volatile adc_result_t measurement;volatile uint8_t measurement_normalized;void adc_handler_cb(void){measurement = ADC_0_get_conversion_result();measurement_normalized = measurement>>(ADC_0_get_resolution()-8);isr_executed = true;}int main(void){/* Initializes MCU, drivers and middleware */atmel_start_init();// Test polled mode// Get conversion from ADC CH0measurement = ADC_0_get_conversion(0);// Get 8 MSB of conversion resultmeasurement_normalized = measurement>>(ADC_0_get_resolution()-8);// Test IRQ modesei();ADC_0_register_callback(adc_handler_cb);// Start conversion from ADC CH0ADC_0_start_conversion(0);// Wait for ISR to be execuedwhile (!isr_executed);while (1);}\endcode*/So tell me, am I seeing things or is the PWM documentation mixed up with the ADC documentation? If this is the level of competence they have with the atmel start thing I'd rather spend the time writing my own code rather than trying to fathom out someone elses particularly considering that hey can change that code at any time and i would have to do my research again.

author: alan.green@gmail.com
author_rank: Unknown
timestamp: April 21, 2019, 09:15:34 pm
content: Quote from: Moriambar on April 21, 2019, 10:20:38 ampyupdiuses a USB-TTL Serial adapter as the programmer and a python program to drive it. The USB-TTL Serial adapters costs $2, and you probably already have one.jtag2updiuses an Arduino as a programmer, driven by avrdude. I'm not sure why this is a better solution than pyupdi.Also, maybe the 15USD MPLAB Snap fits your budget. Seethis forum post

author: alan.green@gmail.com
author_rank: Unknown
timestamp: April 21, 2019, 09:37:09 pm
content: Quote from: Simon on April 21, 2019, 10:50:07 amYou're right! That's clearly the ADC example tacked onto the end of the PWM documentation. I'd report a bug, but I'm not sure how to do that. I'm sure I'll see more issues like this, now that I'm looking for them.All that said, using Atmel START has got me a long way, quickly. Most things just work, and for the things that don't, or for where START is too high-level, I have been able read the generated code along with the datasheet, and work out what it ought to be doing for myself.

author: Moriambar
author_rank: Unknown
timestamp: April 21, 2019, 09:38:18 pm
content: Quote from: alan.green@gmail.com on April 21, 2019, 09:15:34 pmgreat, I definitely have an usb-ttl serial adapter, that I use to program the pro-mini clones. Thanks, I'll try that

author: Simon
author_rank: Unknown
timestamp: April 21, 2019, 09:40:24 pm
content: Um. I just wanted to produce a PWM signal but I can't. Atmel start will not tell me how to talk to the PWM, it tells me instead to use the ADC. I want nothing to do with it. I have the same problem with ARM stuff like STM cube, gives you a load of code but does not tell you how to use it, so might as well write my own.

author: westfw
author_rank: Super Contributor
timestamp: April 21, 2019, 10:30:54 pm
content: QuoteYour best bet for programming is probably the jtag2updi (runs on a $3 Arduino clone) that alan.green mentioned.There is also thehttps://www.microchip.com/DevelopmentTools/ProductDetails/PartNO/ATTINY416-XNANOboard, which is quite cheap (this has the top-of-the-line Tiny-1 chip, and a built-in debugger, so in theory it is useful for writing and understanding tiny1/tiny0 peripheral code. The on-board debugger/programmer may be usable to debug/program external chips as well; I'm not sure.)QuoteThe underlying CPU architecture has not changed much, and in fact is similar to some of the smaller Xmega chips. So the free toolchain of choice is still avr-gcc, which you can download for mac ("Darwin") fromhttp://distribute.atmel.no/tools/opensource/Atmel-AVR-GNU-Toolchain/3.6.1/This does not include make or an IDE; just CLI compilers.In theory, MPLAB (which is cross-platform) will support these chips, and the MPLAB SNAP programmer will program them.AVR support in MPLAB is a bit new and buggy, though.Also in theory, you can use the CLI compilers with standard IDEs like Eclipse, XCode, PlatformIO, etc.QuoteMicrochip is distibuting new chip support in the form of "packs", which you can download from[url=http://packs.download.atmel.com/]http://packs.download.atmel.com/Atmel Studio (and MPLAB?) is set up to install and use these semi-automatically; they're a bit annoying to deal with if you're using one of the CLI toolchains. I wrote some rough instructions here:[url=https://www.avrfreaks.net/comment/2526416#comment-2526416]https://www.avrfreaks.net/comment/2526416#comment-2526416Note that the pin defines for these new chips are now structure based (like XMega and ARM), rather than the old AVR-style "every register gets it's own #define" So you end up using code like:Code:x = PORTB.in;// instead of x = PINB;QuoteYou have avr-libc, but in general that doesn't support peripherals.In theory the tiny0/tiny1 series is supported byAtmel Startbut people have about the same respect for Start-produced code that they have for most vendor produced libraries. I haven't looked at the actual code much; I stopped looking when a trivial project (with USART and I2C added, for example) resulted in "project" with a diffuse and incomprehensible directory structure with over 100 files...Various people are looking at creating Arduino Cores for these devices; surely they ought to replace ATtiny13 (which is more expensive, has less memory, and fewer peripherals), and probably most of the ATtiny85 (ditto) projects. Your guess is as good as mine when those cores will be "mature" enough for general use (and/or whether they'll pass Atmel Start.)

author: MarkR42
author_rank: Regular Contributor
timestamp: April 23, 2019, 10:04:12 am
content: I'm basically agreeing with what others posted. But* No, you can't use the older AVR type programmers. These parts use UPDI as a programming interface, which is a true one-wire interface which makes in-circuit programming easier* You can buy a attiny416-xplained nano dev boardhttps://www.microchip.com/DevelopmentTools/ProductDetails/ATTINY416-XNANO- they are available cheaply (<$10) from several suppliers and it just plugs into the usb port.* You can either route the updi interface from the xplained-nano to your project board (while disabling the built-in attiny416) OR* Develop your basic concept on the xplained board and then program your final device with pyupdi.I did exactly that.I bought the dev board and used the official stuff to get started, then I moved to using pyupdi.py and a usb-serial dongle thingy, plus a 4.7k resistor (like it says in the doc) to program my devices in-circuit.