The Top 25 ATtiny Interview Questions for Embedded Systems Jobs

This is the third part of my USB tutorial for ATtiny2313 and V-USB library. We mostly finished setting up the breadboard in the second part. Now it’s time for the code! This is likely to be the longest of the three parts, so let’s get started!

Landing an embedded systems job often requires mastery of microcontroller programming. ATtiny microcontrollers from Microchip are a popular choice for many embedded applications. As such expect ATtiny-related questions if you’re interviewing for an embedded software role.

In this article, we’ll explore the top 25 ATtiny interview questions and sample answers to help you ace your next job interview Whether you’re a hobbyist tinkerer or a seasoned professional, understanding the key concepts behind these tiny yet mighty chips is essential

1. Compare ATtiny Microcontrollers to Arduino and Raspberry Pi

Frequency of Entities:
attiny: 4
arduino: 2
raspberry pi: 2

Arduino, Raspberry Pi and ATtiny are all microcontroller platforms, but with varying complexity, size, cost and use cases:

  • ATtiny – Family of low power compact 8-bit AVR microcontrollers made by Microchip. Well-suited for simple embedded applications.

  • Arduino – Open source electronics platform based on ATmega MCUs. More powerful than ATtiny with built-in support for peripherals.

  • Raspberry Pi – Credit card-sized single board PC capable of running Linux. Most complex and flexible option, but also more expensive and power hungry.

2. Program an ATtiny Chip Using Arduino as ISP

Frequency of Entities:
attiny: 3
arduino: 3

To program an ATtiny with Arduino as the in-system programmer (ISP):

  1. Connect Arduino to computer and upload the ArduinoISP sketch.

  2. Wire up ATtiny to Arduino based on pinout for the ATtiny model.

  3. In Arduino IDE, select ATtiny board, processor and clock speed.

  4. Under Programmer, choose Arduino as ISP.

  5. Write sketch compatible with ATtiny’s resources.

  6. Upload using Sketch > Upload Using Programmer.

The Arduino will compile and flash the program to the ATtiny via SPI.

3. Coding Considerations for the ATtiny

Frequency of Entities:
attiny: 3

When writing code for ATtiny microcontrollers:

  • Optimize for the limited memory and flash storage.

  • Avoid memory-hungry libraries.

  • Use pin-efficient techniques like multiplexing.

  • Account for lower maximum clock speed.

  • Ensure your development environment supports ATtiny programming and debugging.

Tight resources on ATtiny forced careful, efficient code. Plan pin usage, memory allocation and timing factoring the target chip specs.

4. The Role of Watchdog Timers in ATtiny

Frequency of Entities:
attiny: 3
watchdog timer: 2

The watchdog timer (WDT) on ATtiny chips provides:

  • An independent timer to recover from crashes.

  • System reset generation if software fails to periodically service WDT.

  • A way to escape infinite loops and hangs.

For example, in a weather station project, I used the WDT to sleep and periodically wake the ATtiny for sensor sampling. If the chip hangs, the WDT timer reset lets it resume operation.

5. Optimizing Power Consumption on ATtiny

Frequency of Entities:
attiny: 2

Strategies to minimize power consumption on ATtiny include:

  • Using sleep modes when idle.

  • Disabling unused modules.

  • Choosing lower clock frequencies if possible.

  • Operating at the lowest suitable supply voltage.

  • Writing efficient code to reduce unnecessary computation.

The ATtiny’s event-driven sleep modes, paired with careful configuration and coding, enable low-power battery operation.

6. Interfacing with ATtiny via SPI

Frequency of Entities:
attiny: 2
spi: 4

To use the SPI interface on ATtiny:

  1. Configure pins – Set MOSI, MISO, SCK, SS as outputs.

  2. Initialize SPI Control Register for mode, clock rate, etc.

  3. Enable SPI in master mode.

  4. Write transmit data to the data register to start transmission.

  5. Wait for transfer complete flag.

  6. Read received data from the data register.

SPI provides synchronous serial communication with peripherals like sensors, SD cards, etc.

7. Example of a Complex Project with the ATtiny

For a weather station project, I used an ATtiny85 with the challenges of:

Frequency of Entities:
attiny: 2
weather station: 3
memory: 1

  • Very limited memory – just 8KB flash and 512 bytes RAM.

  • Difficulty implementing algorithms within memory constraints.

  • Optimizing power consumption for battery operation.

To address the memory issue, I used bitwise operators, reduced variables, and efficient data structures. For power, I leveraged sleep modes and timed wakeups while maintaining timing accuracy. Despite its minimal resources, with careful coding the ATtiny85 proved capable of impressive functionality.

8. Built-in vs External ADCs with ATtiny

Frequency of Entities:
attiny: 2
adc: 4

Advantages of ATtiny’s built-in ADCs:

  • Integration reduces complexity and saves PCB space.

  • Faster conversion than external ADCs through direct data bus access.

However, external ADCs offer:

  • Higher resolution and sampling rates.

  • Better linearity and lower noise.

So if precision measurements are needed, an external ADC may be preferable. Otherwise the internal ADC saves money and PCB area.

9. Using PWM on ATtiny Microcontrollers

Frequency of Entities:
attiny: 2
pwm: 4

To utilize PWM on ATtiny chips:

  1. Configure the TCCRx timer/counter registers for the desired PWM mode.

  2. Set prescaler value through CSxx bits to scale the PWM frequency.

  3. Define output compare behavior via COMxx bits to enable PWM output.

  4. Adjust duty cycle by writing to OCRx registers. Higher OCRx values increase the PWM high time.

PWM outputs on ATtiny are useful for controlling motors, dimming LEDs, generating analog voltages, and more.

10. Debugging Code on an ATtiny

Frequency of Entities:
attiny: 2
debugging: 2

Debugging options for ATtiny include:

  • Using a hardware debugger like Atmel-ICE which connects via JTAG or debugWIRE interfaces.

  • Adding print statements to output key variables over serial connection to computer.

  • Using an oscilloscope or logic analyzer to monitor pin states and timing.

  • Simulating code execution on the ATtiny in Atmel Studio before deploying to physical chip.

  • Ensuring your code is modular and readable for easier troubleshooting.

Debugging ATtiny poses challenges due to limited resources and interfaces. A combination of simulation, instrumentation, debugging hardware and good practices help.

11. Handling Interrupts on ATtiny

Frequency of Entities:
attiny: 1
interrupts: 4

To handle interrupts on ATtiny:

  • Define ISR routines to run when specific interrupts trigger.

  • Set/clear corresponding bits in interrupt mask registers to enable/disable interrupts.

  • Use interrupts for timely response to events like sensor data updates, ADC conversions completion etc.

  • Keep ISR code concise, avoid delay() and minimize variables shared with main program.

Interrupts make ATtiny suitable for real-time embedded applications by quickly responding to asynchronous external or internal events.

12. Interfacing ATtiny with Other Devices

Frequency of Entities:
attiny: 2

Interfacing the ATtiny with other devices involves:

  • Using its GPIOs configured as digital inputs or outputs.

  • Implementing communication protocols like I2C, SPI using dedicated hardware or bit-banged in software.

  • Connecting analog sensors to ADC input pins and reading digitized values.

  • Driving actuators like motors via PWM outputs.

  • Triggering interrupts on state changes on input pins.

With a basic understanding of digital and analog I/O techniques, the diminutive ATtiny can interact with an amazing variety of electronics.

13. Addressing ATtiny Limitations in Projects

Frequency of Entities:
attiny: 2

When working within the ATtiny’s constraints:

  • Use multiplexing and shift registers to expand limited I/O pins.

  • Minimize memory usage through efficient coding and avoiding libraries.

  • Implement bootloader for field firmware updates within small code space.

  • Leverage prototyping boards and perfboards for interfacing, before designing custom PCB.

  • Extensively simulate code on PC before deployment to reduce debugging time.

  • Adopt a modular, iterative approach

Adding V-USB as a part of your project

First, we will download the latest version V-USB library from OBdev. Head to the Downloads-section and get the latest .zip – I got vusb-20120109.zip.

Unzip the archive and copy the usbdrv subfolder to your project folder (the whole folder, not just contents). Go to the subfolder and make a copy of usbconfig-prototype. h with the name usbconfig. h. Locate the #define lines for IO port and port bits and clock rate, and update them as necessary to reflect our configuration where D+ is in PD2 and D- in PD3 and clock rate is 12 MHz:

Also, it’s smart to make sure that V-USB tells the computer that it is powered by USB (i.e. e. Doesn’t power itself and can only handle 50 mA of power (100 mA max from USB power in my version). ):

We are going to use OBdev’s licensed vendor and device IDs, so they don’t need to be changed. Keep in mind that this also means that my tutorial, including the schematic in part 2, is GPL. But we do want to customize the vendor name and device name (note the backward slash in vendor name string used to split the #define to two lines so it fits into this blog post):

The usbconfig. If you want to get a sense of what the library can do, you might want to read through the other options in the h header file. Now the only thing missing is the actual C file to use the library. Here is the barebones version of main. c we’ll start with:

The code should be pretty straightforward to understand:

  • Include the usbdrv.h to access V-USB functions
  • Implement usbFunctionSetup() to handle USB requests (we’ll do that soon)
  • Set up a 1-second watchdog timer in the main function. If 1000 milliseconds go by without a call to wdt_reset(), the microcontroller will be reset.
  • Call usbInit() to initialize the V-USB library
  • Use usbDeviceDisconnect(), a 500 ms delay (while calling watchdog reset every 2 ms), and usbDeviceConnect() to force re-enumeration of USB devices.
  • Enable interrupts
  • Loop forever while calling the watchdog reset and usbPoll()

Our code might freeze for some reason (for example, reading bad data and hitting a bug or an endless loop), and the USB device would then stop responding. This is why we use the watchdog timer. In this case, wdt_reset() is not called, and after one second, the watchdog timer resets our ATtiny automatically. The program execution then starts up again, making it look like you just reset the circuit yourself. This isn’t required, but it’s a good idea because it keeps the user from having to unplug and plug the device back in if something goes wrong.

Another thing you may wonder is why the disconnect/delay/connect -procedure is needed at all. This is because the host PC can remember the identifier that was given to a USB device, even if that identifier is lost when the device is reset. It is important that both the host PC and our device have the same ID so they can talk to each other over the USB bus.

Now let’s see if we can get it all to compile. The easiest way is to use my already-made Makefile, which has all the statements our PC-side command-line client needs. Put the makefile to your project folder and run make main. hex too see if it works. Besides seeing the commands that the Makefile runs, this way you also see what V-USB is doing. The only thing you need to remember is to include -Iusbdrv so that the compiler can find the h files from usbdrv folder, and then just having the three additional object files (usbdrv. o, oddebug. o, usbdrvasm. o) put into the same . elf file along with main. o.

Bare-Metal MCU #9 – Review; ATTiny85 from scratch

FAQ

What is the purpose of Attiny?

ATtiny85 microcontroller performs different functions on a single IC. Some microcontroller pins are available with the capacity to use the above one function. Some of the main functions of this microcontroller include timers, SPI communication, I2C communication, BOD (Brown Out Reset), Interrupt &ADC.

What are the specifications of Attiny?

Program Memory Size (KB)
8
Pin Count
8
Operation Voltage Max.(V)
5.5
Operation Voltage Min.(V)
1.8
ADC Resolution Max
10

What is the difference between Attiny 84 and 85?

The Attiny 85 is an 8 pin IC with 5 pins available for Digital I/O, 3 analog inputs, and 2 PWM pins. The Attiny84 is a 14 pin IC, it has all eight pins on the PA registers available for digital output, digital input, analog input, and three of them are good for PWM output, in addition the PB7 pin also supports PWM.

What is the difference between Attiny and atmega328?

Clock Speed: The high speed of Attiny85 is 20 MHz, while Atmega328P is 16 MHz. Therefore, Attiny85 can execute instructions at a higher speed than Atmega328P. Although, the advantage of the higher clock speed is negated by the fact that Attiny85 has less flash memory available than Atmega328P.

Is attiny10 IDE-friendly?

I also stumbled upon an application called ATTiny10IDE that provides non-volatile memory programming for the ATtiny10 microcontroller. While the name sounds promising, it is not Arduino IDE-friendly. Therefore, it is not the solution we are looking for. Finally, I landed on a solution that is Arduino IDE-friendly and has already worked for someone.

Will there be serial programming in attiny10 microcontroller?

Firstly, there will be no serial programming because the ATtiny10 microcontroller doesn’t include SPI communication port. Therefore, we won’t be using USBASP as an external programmer.

Will attiny10 be included in a tiny core?

According to the ATTinyCore authors, they have no plans to include the ATtiny10 in their offered core. Although you can use the Tiny Core with other tiny AVR’s. I also stumbled upon an application called ATTiny10IDE that provides non-volatile memory programming for the ATtiny10 microcontroller.

Is the attiny85 a good microcontroller?

Although the ATtiny85 is a more popular microcontroller, it is not as small as the ATtiny10, which is widely available at a reasonable price of around $0.4 At first, it seemed easy to interface with this microcontroller using Arduino IDE. However, it wasn’t as straightforward as expected.

Related Posts

Leave a Reply

Your email address will not be published. Required fields are marked *