WEEK 8

Embedded programming

Group assignment: compare the performance and development workflows for other architectures.

Individual assignment: read a microcontroller data sheet program your board to do something, with as many different programming languages and programming environments as possible

I have developed a weekly work plan that I describe in the following calendar.

1. Group assignment

Go to the Sedicupct website

2. Individual Assignment

2.1 ATtiny44 data sheet

Attach the microcontroller (ATTINY44-SSU). Datasheet

ATtiny44

Features

  • High performance, low power AVR® 8-bit microcontroller.
  • 4K byte of in-system programmable program memory flash.
  • 256 bytes in-system programmable EEPROM.
  • I/O and packages (14-pin SOIC, 20-pin QFN/MLF: Twelve programmable I/O lines).
  • Operating voltage: ( 2.7 - 5.5V ).

Pin configurations

  • There are (Vcc and Gnd).
  • PB pins (0-3).
  • PBA pins (0-7).
  • Pin PB3 is RESET.

The Atmel® ATtiny24/44/84 is a low-power CMOS 8-bit microcontroller based on the AVR enhanced RISC architecture. By executing powerful instructions in a single clock cycle, the Atmel ATtiny24/44/84 achieves throughputs approaching 1MIPS per MHz allowing the system designer to optimize power consumption versus processing speed.

In the diagram, the PA port (0-7) appears in blue and the PB port (0-3) is green, I also identify the VCC (Supply voltage) and GND (Ground.), The SRAM and EEPRON memories, the 32 registers (General Purpose Registre) connected to the arithmetic logic unit (ALU) and the ISP interface.

Port B (PB3...PB0) Port B is a 4-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The Port B output buffers have symmetrical drive characteristics with both high sink and source capability except PB3, which has the RESET capability. To use pin PB3 as an I/O pin instead of RESET pin, program (‘0’) RSTDISBL fuse. As inputs, Port B pins that are externally pulled low will source current if the pull-up resistors are activated. The Port B pins are tri-stated when a reset condition becomes active, even if the clock is not running.

Port A (PA7...PA0) Port A is a 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit). The port A output buffers have symmetrical drive characteristics with both high sink and source capability. As inputs, Port A pins that are externally pulled low will source current if the pull-up resistors are activated. The port A pins are tri-stated when a reset condition becomes active, even if the clock is not running.

CRYSTAL OSCILLATOR: XTAL1 and XTAL2 are input and output, respectively, of an inverting amplifier which can be configured for use as an on-chip oscillator, as shown in Figure 7-2 Either a quartz crystal or a ceramic resonator may be used. The optimal value of the capacitors depends on the crystal in use, the amount of stray capacitance, and the electromagnetic noise of the environment.

if we don't want to use the internal clock but an external clock, as we do with our ATTiny board, page 25 describes how to connect an external clock and what kind of external clocks you can use. When choosing an external clock, you must set the CKSEL fuses to 0000.

On my Atiny44 board I used a resonator as shown in picture 8 resonator connection.

One of the differences between crystal and resonator is that a resonator has build in capacitors. See this pic and focus on the electronics symbol: resonator has crystal symbol and on both legs capacitors:

the communication pins: MISO pin 5 and MOSI pin 6, which we use to program our ATTiny using our USBTiny.

2.2 Programming ATtiny44 with Arduino IDE

I used my ATtiny45 programmer from week 4 "Electronic Production and connected it to the USB port of the computer.

Connect the ATtiny44 helloboard FROM week 6 "Electronic Design" to 5vdc using the FTDI connector. Through the ISP connectors I connect my programmer with the helloboard.

Program using ARDUINO IDE. In tools I select the ATtiny24 / 44/84 board, the ATtiny44 Chip, the Clock: "20 Mhz (external)", Port: COM3. Burn Bootloader.

I have created a basic program in Arduino, to turn a led on and off using a button.

Initially I used arduino pin = 2 but it didn't work, I found it to be an alternate pin. Use main pin = 8 and it worked.

2.3 Programming ATtiny44 with Platformio

PlatformIO is a development environment designed for IoT applications, which runs on the Atom editor or Microsoft Visual Studio Code. It is compatible with more than 400 development boards. PlatformIO installation is very simple, you just have to download the Visual Studio Code, which is the Microsoft IDE, the free version.

I have followed the following manual

Install PlatformIO for VSCode / Get started

Download and install Microsoft Visual Studio Code. . PlatformIO IDE is built on top of it .

1.Open VSCode Package Manager.

2.Search for the official platformio ide extension.

3.Install PlatformIO IDE.

I find an error in the installation.

Clic Check avaliable solutions

I have used solution 3.

Python installation runs.

Reset VScode, close and reopen the program. Verify that the platformio icon exists.

To create a project using ATtiny44 I have followed the steps of Josephus-vanderbie-Fabacademy2019 PlatformIO

Click on plaformIO: Home.

Clic en + New Project.

Select the Board (Generic ATtiny44 (Atmel).

When a project is generated, the necessary folders and basic files are created, in some cases we will not use all of them. In this case, for the platformIO, the following will be generated:.

  • .pio / folder where the intermediate and temporary files of the compilation will be generated.
  • include / Here you should save the headers of your files, that is, the .h files.
  • lib / folder to generate your project's own libraries, that is, private libraries.
  • source (src) / to save the source code (.c and .cpp).
  • test / here you can define your tests to run and check that the code works well.
  • platformio.ini platformio configuration file, here the libraries to be used by the program are defined (for example the Arduino SD library ...), and many other things. Generally, the one that comes by default is enough.

In fact, the main.cpp file is the main file of your program and if you open it you will see that it is ready to be compiled with the necessary includes. If you are used to * .ino files you will see that it is the same only that a header #include has been added, the rest is exactly the same.

To compile and upload the program, some icons will have appeared in the lower left to be able to work more comfortably. They are like the ones in the Arduino IDE, in addition to more advanced functions. I leave you here the most common ones.

Configure the platform to upload the code to ATTiny. Open the platformio.ini file.

Next open the main.cpp in the src folder and write the following code to create a new blink sketch.

Copy the following code.

Enter the platformio.inio and modify the code.

  • Platform is atmelavr, because our ATTiny44 is part of this architecture.
  • Board is our ATTiny44 chip.
  • Frame is Arduino.
  • Board_build.f_cpu is 20000000L because this is the speed of the external clock.
  • The charging protocol is our usbtiny.

Finally, we can compile and load our code.

2.4 Programming ADRIANINO (ATtiny1614) with Arduino

I have followed the tutorial of Adrian Torres ADRIANINOto mill, soldering and program the ATtiny1614.

Download the .png images of the traces and contour. I opened the fabmodule.org and uploaded the images and configured the parameters to use the SRM-20.

Use a template to organize electronic components. First solder the ATtiny1614, the smaller components and lastly the FTDI, UPDI connectors.

I have followed the following tutorial SpenceKonde/megaTinyCore for the installation of Boards Manager in Arduino. Open Arduino IDE.

  • 1. File -> Preferences, please enter the above url in "Additional urls of dashboard manager". The boards manager URL is: http://drazzy.com/package_drazzy.com_index.json
  • 2. Tools -> Dashboards -> Dashboard Manager ...
  • 3. Select "Spence Konde megaTinyCore" and click "Install". For best results, choose the latest version.
  • I configure the Arduino IDE for the ATtiny 1614; I set the clock to 20MHz and in my case the communication port with the COM3 microcontroller. It is important to have the FTDI-USB connected and choose the "Serial Port and 4.7k programmer (pyupdi style)".

Use Neil / Adrian's Blink program, on pin 8 on Arduino the LED and button on pin 10.

The connection that Adrian uses needs the FTDI-USB and connect the UPDI + VCC module to the board, in this case to the Adrianino that has the three pins (UPDI + GND + VCC).

I am going to use another configuration using the FT230X adapter. I have connected it directly to the UPDI connectors of the Adrianino.

When I compiled I get an error message.

In the Regional Review, Nuria and Adrian tell me that the FT230X had to be hacked (change the order of the RX and TX) and that the connection of the FT230X adapter must first be connected to an FTDI / UPDI Adapter and then to the Adrianino. I have verified that a track of the FT230X Adapter has been damaged so I use an FTDI232 cable instead of the FT230X.

I have compiled and it worked.

4. Conclusions of the week

How was the week?

This week was a little easier than the previous ones, since I only had to use the programming.

What went wrong ?

At first I was not sure which programming language I would use, but in the end they recommended that I try using the platformIO which is very similar to the Arduino IDE.

What went well?

Programming with the Arduino IDE was straightforward. Using platformIO is easy to use, you just have to perform a few previous steps, the advantage is that it allows me to use different microcontroller structures. I liked using the ATtiny1614 and the experience following Adrianino's tutorial was simple and easy to use.

What will you do different next time

I would like to try other programming structures and software to expand my knowledge and compare the pros and cons of each of them.

My files

Electronic board design in Eagle

Blink_Button_Gustavo ATtiny44 (.ino)

ATtiny44 with PLATFORMIO (.ccp)

Blinck_Button_Gustavo ATtiny1614 (.ino)