This tutorial will talk about how to build a development board for the Atmel ATTiny2313 series microcontroller using minimal components. The board will support ISP (In-system Programming) using any supported programmer (e.g. AVRISP) and can also be used as standalone board once the code is burned into it. Using similar concepts, you can build identical boards for other microcontrollers in the series too (e.g. ATMega32). Consider it poor man’s board or a lazy man’s board…when you need to get only the basics to begin experimenting with the microcontroller.
The picture below is the board I built. It took me around 5 hours (this was my first such board).
Whenever you build a board like this, you need to consider the following:
- Planning for soldering and board layout
- Enable support for ISP (In-System Programming)
- The frequency (or clock source selection)
- Power source
- Ports and pins that you will expose to connect to peripherals
The remainder of the section will deal with each option as a sub-section. Please note, the discussion is specific to ATTiny2313 (but as stated before, can be extended to any microcontroller in the series)
Planning for soldering and creating board layout
You will first need to get a few components as listed below:
- 20-pin IC socket (we will solder the socket and then push the IC in the socket. Never solder the IC directly)
- Terminal Block, 2-pin (for power source)
- 1uF (or 0.33uF) de-coupling capacitor
- Tactile switch (push-switch)
- 10K resistor
- Between 12pF – 22pF capacitors (2 Nos.)
- Crystal. If you are planning to do RS-232 based communication, please ensure, the crystal is a multiple of 1.8432 (e.g. 3.686 MHz, 7.3728MHz). Keep the value between 3 MHz – 20MHz. If you are not planning to do RS-232 programming, then pick any crystal less than 20MHz.
- 10-pin FRC cable PCB connector (male type)
- Male and female breakaway headers
- A veroboard (or proto-board)
The picture below explains the placement of the various components on the board during the build. Notice, I am yet to solder the two capacitors next to the crystal.
At the center, is the big-black-bad Attiny2313 🙂
The very first thing you need to do is to plan the layout and the various connections on a piece of paper. There are some key decisions that you need to make in this phase. Here are the decisions I made:
- The board will not have its own power supply. An external regulated power supply will be required to run the processor on the board. Every decision has its pros and cons. The decision I took has the following advantages:
- The board has less component count.
- The board layout is simple.
- You are focusing on the microprocessor circuit and other things do not clutter your mind J
- Having a board like this, works in the long term. When you decide to connect multiple boards to build a larger system, you can have one single power supply to drive all boards.
- I’ll have a reset switch on the board. Just to ensure I can kill the processing in case something goes not as plan. I have never come across that situation, but giants in this space (from whom I have learnt something) always recommend having a reset switch. So I’ll go by their advice. If you come across or know more, do let me know.
- I will use only port B. The reason is that on Attiny2313, you get all the 8-bits only on port B (PB0…PB7). That way, I have at-least 8-bits on a single port to experiment. Also, again, it helps me to keep things simple.
- I planned to do some RS-232 based programming. RS-232 based programming requires that the PC and your micro-controller agree on a baud rate. This baud rate must be such that your clock frequency is cleanly divisible by a number to keep errors in the data transmission low. To ensure this, the microcontroller must be driven by an external crystal. I had an old crystal in my junk box of 3.6864 MHz. This is a multiple of 1.8432 (1.8432 * 2 = 3.6864). The number “1.8432” is called magic-number, simply because it pops-out from nowhere! Now consider this, if you want a baud rate of 9600, then 3.6864 MHz / 384 = 9600. So, the crystal was used instead of the internal clock.
- Because I plan to use RS-232 based programming, I’m also interested in Tx/Rx pins. So, the other pins that I’ll use are Pin-2 and Pin-3. There are no other pins that I’m using on this board. (Port B and Tx/Rx)
- Professional boards are available at cheap rates, allow you to program a variety of microcontrollers, however, I decided to add in-system programming support for my board too. That helps me in the following
- I get to learn the pin connections for programming the controller.
- To reprogram the board with my next project, I do not need to take the microcontroller out and plug it in a different board. Who knows, some James Bond somewhere would have destroyed all programmer boards just to stop Dr. Evil from creating the next world domination program on Attiny2313!
- I took the decision that ISP interface will not be directly hardwired to the microcontroller pins. Given the fact that ATTiny2313 pins play multiple roles under multiple circumstances, the same pins are used to program and also for I/O. In general, there is no harm in hard-wiring the ISP connections, however, I kept mine completely disconnected. To program, I must connect the jumpers. When the jumpers are not connected, you cannot program the IC.
- When the ISP device is attached to the board, it is capable of providing power, thus, the ISP Vcc was connected to the microcontroller Vcc. This means, that as long as the ISP is connected, you do not need an external power source (remember the terminal blocks)
Once all the crucial decisions are taken, first create a block diagram on a piece of paper (I created mine on a tissue paper 🙂 ). The diagram has been reproduced below:
The diagram above, outlines where am I going to place the components. The rectangle with circles in it, represent male headers which will act as jumpers. As stated before, jumpers will be connected only during programming. One key thing to note here is that Vcc and GND run across the length of the board. It’s a good idea to do so. That way, the power and ground are available from all points on the board. Also note, the ISP interface connects to Vcc and ground. This means, the board can be powered by ISP device when connected and you do not need additional power source (but do not run power hungry devices directly, you may fry the board and upstream devices).
Soldering the ISP connections
I do not have a RS232 port on my laptop. Most recent laptops would probably not have one. That is why, these days, many online shops offer a USB based programmer. I have an old AVRISP programmer from www.sunrom.com that works great will various AVR microcontrollers. The ISP pinout of the programmer I have is shown on the left.
The connections I made between the ISP socket pins are given on the right.
The diagram on the right represents how I soldered the various pins. Please note, you must join pin 4,6,8 & 10 and connect them to ground. All of them. Also, as stated in the board layout, connect the Vcc and ground to the Vcc and ground on the board so that ISP power can drive very low power experiments and you do not need an external power supply.
The ISP socket pins connected to the microcontroller pins as given on the left.Actually, as stated before, I just connected the Vcc and Ground of the ISP socket to the Vcc and ground on the board. Other pins were simply connected to male-headers (see previous images for clarity), both for the ISP socket and the microcontroller. So, during programming, I would connect them with jumpers and once programmed, I would remove the jumpers.
The circuit connected with jumpers for programming looks like the one shown below (Picture taken before board was complete, notice the capacitors and other headers still not soldered). The red wires are jumpers that complete the connection from ISP socket to microcontroller pins:
Clock source selection
As mentioned before, I’m using a 3.686 MHz crystal to ensure I have very low error rate during RS-232 communication. The ATTiny2313 ships with internal clock source of 8 MHz which is divided by 8 to give you 1MHz clock. If you really need a stable clock, you should use an external crystal. See the datasheet for details on values supported for frequency.
Also, before you program, you must burn the fuses to instruct/inform the controller that you plan to use an external crystal. Again, please see the datasheet for correct fuse bits. I used AVR Studio’s GUI to fuse the bits. Its pretty simple that way. I also programmed the fuse bit to output the clock source on pin 6 (for Attiny2313). I did this so that I can check the output with my oscilloscope and ensure that the controller is indeed running on 3.6864 MHz (and my oscilloscope did show the clock frequency to be 3.6864 MHz !)
To ensure crystal works correctly, create connections as shown on the left.
Do not forget the capacitors. Earlier, I did not connect the capacitors and only the crystal was connected. There was no clock on pin-6 L
The datasheet for 2313 recommends to use 12-22 PF capacitors. I used 22pF capacitors and it works.
The power source
This subject is already covered in great details in earlier sections. Just to re-iterate, I’m using external power source and have provided terminal blocks (green cubes in picture) for external power source. Additionally, for very low current experiments ( less than 20mA) I’m extracting power from the ISP programmer.
Ports and pins exposed
I soldered a female header (8-pin) with pin-12 till pin-19. That gives me access to all 8-bits of PortB.
I also soldered another femal header(2-pin) with pin-2 and pin-3 to gain access to Tx/Rx pins on the controller.
I could have used male-headers, like in professional boards, however, I did the other way round…simply because, I can push a single-stand wire (or breadboard wire) in the female connector much easily and connect additional circuit built on my breadboard.
Try out at your own risk…don’t hold me responsible for anything bad…Enjoy!