Knowledge Base‎ > ‎General Gyaan‎ > ‎

Tutorials

ADC on the ATMEGA

posted Sep 17, 2016, 7:09 AM by Rohit Bhaskar

ADC stands for Analog to Digital Converter. What do we need it for ? Well a lot of sensors that are used in Electronics(and Robotics) give output voltages in the form of potential differences. Doesn't make sense ? Simply speaking, a sensor will give out its readings in the form of voltages. So what do we do with it ?? Well, we convert it to a number which will help us determine the actual implications of that reading. We fix a maximum reading as the reference number (255 in our case,since we will be ignoring the last 2 bits) and calculate the corresponding value of our reading on the new scale. 

So, moving on, the ADC feature is available on PORTA of the ATMEGA16/32.

Features :

1. The reference (maximum) value can be taken from the AREF pin or an internal reference level of 2.56V is provided which can be accessed by the software. The AVCC may also be used as AREF by simply decoupling it(connecting to ground through a capacitor).
2. 10-bit is available. This means that you can distinguish between two readings which have a difference of (Reference Value/210) . This means that the max value is broken up into 210-1 = 1023 parts and if you have a reference of say 5V, you can distinguish between readings 4.88mV apart (yeah, that's right !!)
3. The ADC can be used in free running mode(which means it will keep on converting continuously) or single conversion mode. 
4. An interrupt may be generated once a conversion is complete, so that the MCU need not keep on checking for completion of conversion. 
5. There is a ADC Noise Cancelling mode, which allows the user to switch off the other digital circuitry which might affect the conversion. 
6. Since the result is 10 bit, the result is stored in 2 registers : ADCH and ADCL. If the ADLAR bit is not set, the result is right aligned. In that case, the 2 MSBs of the result are the 2 LSBs of the ADCH register and the remaining 8 LSBs of the result are in the ADCL. In this case, it is necessary to read the ADCL first and the ADCH second, only then will the ADC registers be updated with the next result. 
7. Accuracy is best between 50 and 200 Khz clock frequency. Running at 16 Mhz,we select the prescaler as 128, which gives a clock frequency of 8/128, which is 125 Khz.

Code :

Now, we set up the registers.ADC RegistersNext, we write the functions to initialise ADC and call a conversion.ADC Code

Resources :

1. ATMEGA16 Datasheet Pages 204 - 221 
2. ADC Tutorial on AVRFreaks 
3. Sample code 
4. Registers


Contributed by :
Ankit Daftery
ankitdaf [at] gmail [dot] com

Ball detection using Matlab

posted Sep 17, 2016, 7:08 AM by Rohit Bhaskar


BALL DETECTION USING MATLAB 

Category: IMAGE PROCESSING 


Description: Detecting a ball involves image processing. The best way to do so can be writing your algorithms on MATLAB or openCV, where we can load our image on the data base and do required math’s on the image. This project involves detecting a ball in real time and continuously noting the ball coordinates. The coordinates obtained can be used to control motors to follow the ball (ball follower) or to control your camera to move along its 2 axis with the moving ball. Thus the input to the algorithm is image and output is x and y coordinates of the ball. 

Requirements: MATLAB, WEBCAM. 

Coding:
 The code is written in MATLAB. To understand the code one must go through GETTING STARTED of matlab help. 

CODE: 

imaqhwinfo 
info = imaqhwinfo('winvideo') 
dev_info = imaqhwinfo('winvideo',1) 
vid = videoinput('winvideo'); 
set(vid,'TriggerRepeat',Inf); 
vid.FrameGrabInterval = 1; 
vid.FramesPerTrigger=20; 


figure; % Ensure smooth display 

set(gcf,'doublebuffer','on'); 
start(vid) 
while(vid.FramesAcquired<=1000) 
I = getdata(vid,1); 
fR=I(:,:,1); 


MY=fR >180; 



MY = bwareaopen(MY,5); 

se = strel('disk',4); 
MY = imclose(MY,se); 
MY = imfill(MY,'holes'); 


J=rgb2hsi(I); 

H=J(:,:,1); 
MY1=H < 0.5; 


F=MY & MY1; 



F = bwareaopen(F,5); 

se = strel('disk',4); 
F = imclose(F,se); 
F = imfill(F,'holes'); 


imshow(F) 



[B,L] = bwboundaries(F,'noholes'); 



s = regionprops(L, 'centroid'); 

cor = cat(1, s.Centroid); 


disp(cor); 



%pause(0.05); 

flushdata(vid); 
end 
stop(vid) 




Author:
 ANIKET .A . TATIPAMULA
Mobile : 9969982534.

Video linkshttp://www.youtube.com/watch?v=_FIU2rLs2mA 

Fuse Bits : Changing your MCU speed and JTAG

posted Sep 17, 2016, 7:07 AM by Rohit Bhaskar

When you begin with micro-controllers, and you are reading the datasheets or tutorials, you are very likely to have come across the term "Fuse Bits" which relate to the MCU speed and JTAG. Being beginners and not having the slightest idea about both, it is generally left for "later, when I get more experienced" . The fact that even the tutorials promise to come to it later adds to this lack of confidence. 

When I was trying to interface my LCD with my ATMEGA16, I found that the display was being printed too slow for my liking , and so I resolved to increase the MCU speed. (though that was not the real problem, as I later found) 

So here I am, with no knowledge about fuse bits or JTAG or anything. So what I do ? Read the datasheet, of course !! 

Here's what the datasheet says : 

There are two fuse bytes : lfuse (lower fuse byte) and hfuse (higher fuse byte). These represent atributes of the MCU, and can be programmed to change the attributes. See the table below for the attributes : 

 

 
(Source : ATMEGA16 Datasheet)

For our purpose, in the hfuse byte we need to reset the JTAGEN to disable JTAG, and reset CKOPT to enable us to select a different internal clock. CKOPT, you can understand, but why change the JTAG part ? That's because four pins of PORTC are JTAG enabled and sometimes give weird unexpected output if not disabled. The other bits can be left unchanged. 

Now, we need to change the 4 bits of CKSEL in the lfuse byte to select the internal clock speed. Here's the table for different clock speeds.

  
(Source : ATMEGA16 Datasheet) 

Now, how do I program it ? AVRDude or ICCAVR. 

Its very easy to do so in ICCAVR and you don't even need to know about the above fuse bits, but I don't use ICCAVR and find AVRDude better. So here's how to go about it in AVRDude. 

First make the makefile that you generally make for your programs. Then burn a program into your mcu. Keep the MCU and programmer connected during the whole process and never apply a reset until the whole thing is over. Note the first line of the output window below. 

It looks something like this : 

avrdude -p m32 -c -bsd -u programname.hex 

Now go over to DOS mode and follow the steps in the picture below. 
 

 
(Image courtesy : Bibin John's Ebooks) 

Remember though : The above settings were an example. The bits might be different for your device. Just change the ones that you need after consulting the table above, leave the remaining ones unchanged, calculate the resulting hex number and replace it in the appropriate places. 

I hope you all find it quite simple, just as I did. 

Oh and ya, congratulation !! Your MCU has now become 8 times faster !!! 

Caution : Once you change your fuse bits to use an EXTERNAL clock, remember that you won't be able to even program your MCU without using that clock. You will just get an "AVR Device not responding" error, so be careful with what you do !
Also make sure you calculate the fuse bits for the specific micro-controller(this tutorial deals with ATMega16) because each one will have its own byte structure!



Contributed by :
Ankit Daftery
ankitdaf [at] gmail [dot] com

Interfacing a PS/2 keyboard to the ATMEGA16

posted Sep 17, 2016, 7:06 AM by Rohit Bhaskar

There are a lot of devices which would be great if we could use them to communicate with a micro-controller and a keyboard is one of them. Adding a keyboard interface opens up a whole world of varying your input to the MCU and controlling it. 

A lot many tutorials about this are already available on the internet, but I found that patching ready made code to your MCU is most often problematic. Its best to understand the protocol and write code yourself. 

THE PS/2 PROTOCOL : 

This is how a male PS/2 connector (on the keyboard) looks like :

 6-pin Mini-DIN (PS/2) Male Connector: 

1 - Data 
2 - Not Implemented 
3 - Ground 
4 - Vcc (+5V) 
5 - Clock 
6 - Not Implemented 

Communication :
 

Each key press on the keyboard corresponds to a fixed hex code which is communicated by the keyboard controller to the MCU. This code is known as the scan code. This is followed by a "break code", which indicates that the key was released and consists of two "words". The first "word" is the same for all keys (generally F0), and the second "word" is generally the scan code repeated again. 

Now let's deal with only communication from the keyboard to the MCU. 

The data format is as below :
1 start bit 
8 data bits, least significant bit first 
1 parity bit (odd parity) 
1 stop bit (always 1) 

One word therefore consists of 11 bits, and three words make a package. One package corresponds to one key press. 

Timing : 

The data and clock lines are open-collector. They are always high in the idle state. The keyboard pulls the clock line low and generates a clock signal to begin sending data on the data line, when a key is pressed. 

Note that the keyboard won't send any data if the clock line has been held low by the micro-controller, even if a key is pressed



The timing diagram for communication is on the left. The clock line which is normally high is pulled low by the keyboard to begin transmission. One clock pulse consists of a high level for half a clock cycle followed by a low level for the remaining half. Data is loaded when the clock line is high and therefore must be read when the clock line changes from high to low i.e. on the falling edge of the clock. Timing is absolutely critical and wrong timing will lead to totally wrong or even no data. The SCK line (used if communicating via SPI) should have a frequency of about 10 -16.7 kHz. Since we shall be using the interrupt method, we need not bother with the clock frequencies. 

The Interface : Data acquisition 

Data acquisition can be done in different ways, including SPI , or by continuously polling the data and clock lines to see when they go low etc. However, shall be using the interrupt method here. 


The clock signal generated by the keyboard is fed to the INT2 line of the ATMEGA16. The reason for selecting INT2 is that it is an edge triggered interrupt and can be used to detect a rising and falling edge asynchronously i.e. independent of the MCU clock. The data line is sampled at every interrupt trigger and the needed bits are stored and shifted to obtain the scan code.Since we already know the data packet format, we can safely afford to neglect the remaining bits. Here, we shall not be reading the break codes. However, they may be used if special functionality is needed. 


Code :Click here to view the Keyboard Data Acquisition Code
This code is very basic and will help you obtain the key scan codes. You can further add the look-up tables for these scan codes to identify the keys pressed. You could also try out key combinations and implement extra functions, password features etc. 

Issues :
 Reliability issue : The above code works just fine. One scan code can be detected additionally as well. However, if code to read the two scan codes that follow is added, all the data i.e. all three words get messed up. Reason yet to be detected and fixed. 

References and additional reading 

1. Science Prog website 
2. ComputerEngineering.org 
3. Interrupt based Code 

Images courtesy computerengineering.org 

P.S : Code will be improved and added soon. Keep visiting !! :D

Contributed by:
Ankit Daftery
ankitdaf [at] gmail [dot] com

Exernal Interrupts on the ATMEGA

posted Sep 17, 2016, 7:04 AM by Rohit Bhaskar

So, now you know how to use the ADC and the UART features present on the ATMEGA.

The ATMEGA16/32 has one more feature of great importance to us : external interrupts.Click here to read a brief introduction on Interrupts
Okay, now why are they of importance to us ? A lot of stuff generates signals in the form of voltages or voltage changes to indicate decided events. For example, a device might have one line which goes low for a few clock cycles and then high again to indicate that it has completed its task.We can therefore use this line as an external interrupt line to schedule further tasks. 

The ATMEGA16/32 has 3 external interrupt lines : INTO,INT1 and INT2, on pins PD2,PD3 and PB2. 

Interrupts on INT0 and INT1 can be 

1. level-triggered(meaning that the interrupt is triggered when the signal goes low i.e. 0V for some time 

OR 

2. edge-triggered(meaning that the interrupt is triggered when the signal changes from high to low or low to high) 

====> INT2 can only be used as an edge-triggered interrupt. 

Setting up the interrupts :: 

Control Registers MCUCR : MCU Control Register 

 

Bits 3,2,1,0 are the ones which are of importance to us. 
Bits 3,2 are used for sensing an external interrupt on line INT1. 
Bits 1,0 are used for sensing an external interrupt on line INT0. 

The table for setting up these bits is as follows :  

The table for INT0 is similar to the one above. It is to be noted that if an edge triggered interrupt is selected, the edge (change) must last for at least one cycle for it to be detected. Similarly, if a low level triggered interrupt is selected, the low signal level must be held till the instruction being executed currently by the MCU is completed. 

MCUCSR : MCU Control and Status Register

  

Bit 6 is the only one of importance here, and controls the INT2 line. 

If this bit is set to 1, a rising edge generates an interrupt and if it is set to 0, a falling edge generates an interrupt. The pulses here also must be longer than one clock cycle. 

Also, the ISC2 bit must be set following a specific method,since an interrupt can occur even while changing the ISC2 bit. 

The procedure is something like this : 

1.Disable INT2 by clearing its Interrupt Enable bit in the GICR Register. 
2.The ISC2 bit can be changed. 
3.The INT2 Interrupt Flag should be cleared by writing a logical one to its Interrupt Flag bit (INTF2) in the GIFR Register before the interrupt is re-enabled.

GICR : General Interrupt Control Register

  

Bit 7,6,5 enable the INT1, INT0 and INT2 lines respectively if set to one. 

GIFR : General Interrupt Flag Register

  

Bit 7,6,5 manage the status of the Interrupt requests. The flag is set for each of these when the respective line is triggered, and cleared when the corresponding interrupt service routine is executed.Alternatively, we can clear the flags manually by writing it to 1.Click here to view Sample Code to setup the interrupts
<---------------------------------------------------------------------------------------------> Resources : 

1. ATMEGA 16 Datasheet 
2. Introduction to interrupts 
3. Sample Code

Contributed by :
Ankit Daftery
ankitdaf [at] gmail [dot] com

Interfacing a 16 X 2 LCD to your ATMEGA

posted Sep 17, 2016, 7:02 AM by Rohit Bhaskar

Often, when you are working with micro-controllers, you might feel the need to see what conditions are being executed or what input the micro-controllers are taking. For that, you can always use LEDs, but then LEDs are a very clumsy and confusing way of going about it. 

So, what should you use that shows me what's going on ?? An LCD, of course !! 

Here's how. 

1. Read the datasheet of your LCD. 
2. Understand your LCD. 
3. Write the code. 
4. Burn the code. 
5. Make the connections and voila !! 

For the purpose of modularizing work ( and for fear of this post becoming too long and boring), I have posted the detailed discussions section-wise as text files.

 All links are at the bottom of the post. 

Step 1 : Requirements : 

I am using a HITACHI JHD162A LCD Display, with a HD44780 LCD Controller, which comes for roundabout Rs. 110. The datasheet of the controller is much more important than that of the module, since its the controller which is going to take in input and print the screen. You need not bother with the datasheet of the LCD itself. Of course, you will also need a micro-controller with at least 11 usable pins and lots of connectors. 

Step 2: Understand your LCD : 

Read the datasheet.HD44780 LCD Datasheet Explained
Step 3: Write the code:

Easier said than done, eh ? Well, do the next best thing. Find code on the internet, understand it and tweak it, based on your configuration. I read Bibin John's code and modified it a bit. I have also been recommended Peter Fleury's library as being easy to use, but I haven't gone through it as yet.JHD162A LCD Code
 I have used the delay function provided by WinAVR in my code, since Bibin has written his own delay loop in assembly language and it was giving me faulty delays,making the wait too long. Step 4: Burn the code: The easiest part by far. Just make sure your code is syntactically and logically correct ( you need to know the datasheet well for that) and burn it using WinAVR. 

Step 5: 

Connect :

  

Quite an important step. Even if the code is correct, your screen will display junk at the most and black boxes usually if the connections are improper. Here's the checklist. 

Here's a picture of the output I get :

   

Shortcomings,problems, general precautions etc

There are lots of things that can go wrong, implying there are lots of things you must be careful about.LCD Interfacing Checklist
Problems :ProblemsHappy Printing !! 

P.S. Many thanks to Shashank S. for his help. --------------------------------------------------------------------------------------------- Links : 

1. Datasheets : a. HITACHI JHD162A LCD Display 
                        b. HD44780 LCD Controller (Courtesy : Sparkfun

2. Reading : a. Bibin John's Books 
                    b. Robotics India 
                    c. AVR-Beginners 
                    d. Meteosat's Tutorial 

3. Files  :     a. Datasheet summary 
                   b. Code 
                   c. Checklist 
                   d. Problems 
                   e. Peter Fleury's library 

Contributed by :
Ankit Daftery
ankitdaf [at] gmail [dot] com

Making your own AVR ATMEGA programmer

posted Sep 17, 2016, 6:57 AM by Rohit Bhaskar

Having worked on a parallel port bot before,I wanted to move on to something more complicated. Making intelligent bots,that work on only sensors,somehow didn't appeal to me and I wanted software to play some role on it...So I decided to work on a micro-controller project. 

Well,for programming a micro-controller,I need a programmer : Hardware that will interface the chip with the computer. I bought an AVR ATMEGA32L chip, as it seemed enough for my foreseeable projects. I browsed the web for a programmer.Lots of links are available with tons of information on making as well buying one. Well, I asked a friend and he told me that it was possible to make one and that it would also be more convenient to just buy it,as it was pretty cheap. However, being in the electronics field, I decided to make one myself, just to learn how things work(which I would never have bothered to do otherwise). Well, the experience has been great and have had moods ranging from puzzled to pure frustrated !!

 After almost a week of 3 hours daily and almost an entire weekend,I finally managed to piece everything together...It necessarily doesn't take this long, I just spent lots of time planning the layout..which eventually got messy anyways... Its nothing more than assembling a circuit on a General Purpose PCB,which requires basic soldering and planning skills.  

Click the image for a larger view 

Here's the power circuit :

  
(Click the image for a larger view)

Here's how to go about making the programmer : 

1. Get a mount for your chip. That way,the chip can be plugged in or removed any time, improving portability...Beats soldering the chip directly... 
2. Get safety resistors for all pins going to the parallel port..They limit the current and protect the parallel port from blowing up 
3. Get a diode (I couldn't because I have fixed polaritites..) to prevent everything from blowing up in case you connect the power cable wrong 
4. Get LED's before the regulator and after the regulator..It goes a long way in troubleshooting...Has saved me a lot of frustration 
5. Get a switch for the power supply...This will save you the trouble of removing the power plug every now and then 
6. Use a LED for the RESET port....This will tell you when a RESET has been applied. 
7. The capacitors in parallel with the voltage regulator are optional..generally to be used if dealing with radio circuits to reduce noise and stabilise voltage... 
8.The external clock is optional and used to increase the speed. It won't be used until you make some settings in the software,so you might as well put it on your board and keep for future use.. 

The connection between the parallel port pins and the pins of the ATMEGA32L are as follows : 
Pin 7 ------------------> ~RESET (Reset Bar) 
Pin 8 ------------------> SCK 
Pin 9 ------------------> MOSI 
Pin 10 -----------------> MISO 
Pin 19 -----------------> GROUND 

Here's how my programmer looks 

 

Here's one with the power on :

 

And one with the reset switch pressed :

 

Tips while soldering: 
1. Use solder wisely. You don't want to make unwanted connections just because you used too much solder.. 
2. The solder should not only be adequate, it should also hold the component in place.I had two such problems,where the switch and a resistor were soldered,but not held in place, due to which there were loose connections leading to power problems.This is extremely dangerous,as you wouldn't want power going off while you are programming it... 
3. Tap your circuit vigorously and also wave it in the air vigorously,while the LEDs are glowing. Also the PCBs are slightly flexible,so try bending them and see if the LEDs go off...This will help you detect loose connections. 
4. I also had an issue with the LED that comes before the voltage regulator. Even though I supplied more than 12V from the eliminator, most of the voltage dropped across the resistor connected with the LED and so the regulator did not get the needed supply and the chip did not work. If this happens, you will get a "AVR Device not responding" error when you try to program it . If so,remove the LED and resistor. They are supposed to be indicators, but there's no point in keeping them if they only spoil the fun. 

This programmer can be used with the ATMEGA16,ATMEGA32 and the ATMEGA32L
 Hope you found this easy to understand and fun.. 

If you have any questions or suggestions, please comment



Contributed by :
Ankit Daftery
ankitdaf [at] gmail [dot] com

SPI : Serial Peripheral Interface

posted Sep 17, 2016, 6:56 AM by Rohit Bhaskar

The serial peripheral interface provided in the ATMEGA16/32 allows a high-speed synchronous data communication channel with other devices.The relevant pins on the ATMEGA are : 

1. MOSI : Master Out,Slave In : Pin B,5 This line is used by the master to send out data to the slave.The Master always initiates any communication.

2. MISO : Master In,Slave Out : Pin B,6 This line is used by the slave to send data to the master. 

3. SCK : Serial Clock : Pin B,7 This is the serial clock generator. Communication takes place only when the clock is working.The clock starts a cycle when the master initiates communication. 

4. (~SS): Slave Select : Pin B,4 The slave will respond only if the Slave Select line is pulled low.If not pulled low,the chip will not read data even if keeps on receiving clock pulses.The Master pulls the Slave select line high again at the end of the data transfer to synchronise the slave.

Connections :

Master ------------------------------------------> Slave

MOSI ------------------------------------------> MOSI

SCK ------------------------------------------> SCK 

~SS -------------------------------------------> ~SS 

MISO <------------------------------------------ MISO

Data Flow :

The SPI supports a full duplex operation, which means communication can take place both ways simultaneously, i.e. data can be sent on one line and received on another line simultaneously.

When two-way communication is desired, it is best to follow the following method. 

1. Write Data to the SPDR (SPI Data Register)
2. Wait till the transmission is complete. You can do this either by polling a flag or by using interrupts. 
3. Read the SPSR (SPI Status Register) and then the SPDR immediately after that, in that order, if you are using the polling method. Just reading the SPDR is enough if you are using the interrupt example.This will prevent any accidental loss of data. 

This can be done safely even with the slave, since the data which has been queued up in the SPDR will not be transmitted unless the Master initializes communication. However, iteration-based loops cannot be used in the case of the slave to send data, since it is unsure when the Master will initiate communication and so the data would keep on updating in the SPDR without being sent. It is thus advisable to use the interrupt method in case a transmission by the slave is desired.

Modes of Operation :

Click here to view the SPI Modes of operation

Control registers :

 

 Bit 7 – SPIE : SPI Interrupt Enable
 This bit causes the SPI interrupt to be executed if SPIF bit in the SPSR Register is set and if the global interrupt is enabled.

Bit 6 – SPE : SPI Enable 
1 ----> SPI Enabled
 0 ----> SPI Disabled 

Bit 5 – DORD : Data Order 
If DORD = 1 , the LSB of the data word is transmitted first. 
If DORD = 0 , the MSB of the data word is transmitted first.

Bit 4 – MSTR : Master/Slave Select 
MSTR = 0 ----> Slave Mode 
MSTR = 1 ----> Master Mode 

If SS is configured as an input and is driven low while MSTR is set, MSTR will be cleared, and SPIF in SPSR will become set. MSTR will then have to be set again manually to re-enable SPI Master mode.

Bit 3 – CPOL : Clock Polarity 
CPOL = 1 ----> SCK is high when idle
CPOL = 0 ----> SCK is low when idle 

 
Bit 2 – CPHA : Clock Phase 

The settings of the Clock Phase bit (CPHA) determine if data is sampled on the leading (first) or trailing (last) edge of SCK.

  

Bits 1, 0 – SPR1, SPR0 : SPI Clock Rate Select 1 and 0 

These control the SCK rate of the Master device and have no effect on the Slave. The relationship between SCK and the Oscillator Clock frequency (fosc) is shown in the following table:

Status Register :

 

Bit 7 – SPIF : SPI Interrupt Flag 
This flag is set when a serial transfer is complete. An interrupt is generated if SPIE in SPCR is set and global interrupts are enabled. If ~SS is an input and is driven low when the SPI is in Master mode, this will also set the SPIF Flag. SPIF is cleared by hardware when executing the corresponding interrupt routine or it can be manually cleared by first reading the SPI Status Register with SPIF set, then accessing the SPI Data Register (SPDR). 

Bit 6 – WCOL : Write COLlision Flag The WCOL bit is set if the SPI Data Register (SPDR) is written during a data transfer. The WCOL bit (and the SPIF bit) are cleared by first reading the SPI Status Register with WCOL set, and then accessing the SPI Data Register.

Bit 5..1 – Res : Reserved Bits

Bit 0 – SPI2X : Double SPI Speed Bit 
When this bit is written to one the SPI speed (SCK Frequency) will be doubled when the SPI is in Master mode . This means that the minimum SCK period will be two CPU clock periods, as opposed to the minimum of 4 in normal mode. When the SPI is configured as Slave, the SPI is only guaranteed to work at fosc/4 or lower. The SPI interface on the ATmega16 is also used for program memory and EEPROM download- ing or uploading.

Sample code:

Click here to view sample SPI CodeThe code to setup the slave is pretty simple and can be found in the ATMEGA16 Datasheet on Page No. 139

Resources :

1. ATMEGA16 Datasheet 
2. Modes of Operation 
3. Sample Code

Contributed by :
Ankit Daftery
ankitdaf [at] gmail [dot] com

Code for Steppermotor Line track

posted Sep 17, 2016, 6:54 AM by Rohit Bhaskar

The tutorial for the same will be put in few days.

UART : Making your own Module

posted Sep 17, 2016, 6:52 AM by Rohit Bhaskar

If you are done with UART between two micro-controllers, I am sure you would like to move on and try and communicate with a computer.

Communication with the serial port of a computer, however is not so straight-forward, since the logic system of the serial communication line differs from that of the micro-controller. The difference is basically in voltage levels. RS-232 is a method for porting the micro-controller logic to serial port logic. Read up on the background of RS-232 for understanding properly.

So, for this, you need a module which will connect the micro-controller and the PC and regulate data communication.A Max-232 chip is the one which converts the logic levels. Lots of circuits are available for it on the internet. You just need to run an image search for "max 232 circuit" or "rs 232" or similar.Here's the image:



For making this module, use the following :
1. Right-angled DB9 female connector
2. A millimeter board made especially for the above connector
3. A Max-232 chip and mount
4. Miscellaneous connectors and wires.

All the above are easily available in the market. Try to use them for convenience,especially the first two.

Here's how my finished module looks like :



Note the two holes on the board and the wire coming out. I purposely looped the wire once like this, because I have seen soldered connections break off due to pulling while use. The loop and the tight wires help to prevent that. Also, try to keep the wire a bit long, so it is convenient to connect it with your MCU.

Well,this is all you need.

Contributed by :

Ankit Daftery

ankitdaf [at] gmail [dot] com

1-10 of 21