1 Jan 2020

BRIEF INTRO

BRIEF :
             Before we start lets say we are going to cover the topics in brief. But i promise you i will make it clear all the topics which i deal with . Before entering into the discussion we should know some of the terminologies in the microcontroller which we will be dealing with so lets learn some terminologies.

             1. Pin Diagram (atmega8)
             2. Block diagram (atmega8)
             3. Ports & Pins   which are I\O Ports
             4. System clock
             5. Interrupts
             6. Timers - 0 , 1 , 2
             7. Usart and their PROBLEMS
             8. SPI
             9. ADC
           10. MEMORY ARCHITECTURE
           11. Bootloader section
           12. FUSE bits and LOCK bits
           13. Compilation steps to burn hex file into the target microcontroller using a usbasp programmer .
           14. How a hex file is written in the microcontroller
            
            I do think i am just starter or learner everytime because this is wast subject like an ocean so try to learn as much as you can though you were good at  this there are so many things that should be taken care of so please this should be taken care of many things even a small mistake can cause huge losses in real life .

            Suppose lets consider the real time example where embedded systems are used . Lets say you are a racer and you have a race car think that it met with a accident during the race so as soon as accident occurs in order to protect you air ballon should come out as soon as possible with in the span of some microseconds or nanoseconds  so here you should take care of interrupts , ISR timing , clock speed etc in order to save you . Think it come after 1 min or 2 mins its no use right . Learn precisely what ever you learn in order to get accurate results.ok

             Lets start guys. We are all friends we are just going to have discussion thats it no teacher and student relationship in my premises.


16 Jul 2012

usart problem 2!!!!!!!!!!!!!!!!!!!!!!!!!!!1

The main reason that minicom why serial programs we get errors is before you transmit or receive you should check the following conditions:

1. Baud rate 
2. Frequency

these two things should be same in the program and in the minicom if you are transmitting the program with the baud rate of 9600 and you have configured the baud rate of the minicom as the 115200 what do you think you will get output. You will get the junk values in the terminal . In order to get sync with the transmission you should make it 9600 in the hyperterminal. In detail i will should you my errors and how did i rectify them.

see the program which i have programmed has the baud rate of 9600 bits per second and i configured the terminal as the 115200 bits per second . So no sync in between both of them . So you get the following output.

usart junk value due mismatch sync

So in order to get your data as the data you are transmitting in the program if there is sync or have baud rate same then you get the transmission as below

 How to configure the baudrate in minicom

 open minicom using the minicom -s before you do this connect serial port with serial wire. And as i explained in previous post in detail here lets discuss how to change the baudrate

Assume previously you have the baudrate of 115200 and you need to change it to 9600 .
Now change the baudrate what you need.

 you press 'C' for 9600 baud rate and then press ESC now you will see your baud rate


You got your required baudrate so continue working with your application . 
And also make that hardware / software flow control : NO
enjoy..................


                                    PROBLEM3

 







minicom problems!!!!!!!!!!!!!!!!!

(usart )
Common problems and solutions :

Q. Trying to open minicom to complete the installation and i keep getting is  "minicom : cannot open /dev/tty8 : Permission denied "
Sol : Type minicom -s  and change the port of access to /dev/ttyUSB0


use the command  minicom -s as shown


and then change the port name which is showing the as permission denied to /dev/ttyUSB0 and your frequency as required by default hardware/software flow control should be : NO


now press A to change the port  this is the default port which is showing permission denied. Now you need to change it so


press A  and type /dev/ttyUSB0 in the place of the ttyS0 or something .

Now change hardware flow control to NO if it is already unselected then leave it.  Press ESC for comming out of those selections.

Even though it doesn't open minicom then first connect the serial port for the board and try the whole thing again .

Now you get your minicom to work . enjoy .................

Problem2 : Baudrate selection config 

XMODEM PROTOCOL

XMODEM USING MINICOM: 

XMODEM is one of the serial communication protocols which is used to write/read  the data to/from microcontroller serially. So in order to do that you need to have some medium to communicate that medium is xmodem .

XMODEM is used to transmit the files to/from PC.

This is having many models like:
1. XMODEM - CRC
2. XMODEM - CHECKSUM
3. XMODEM - 1K
4. XMODEM - 1KG

Firstly lets discuss about XMODEM - CRC  in detail as we are using it presently:

You send your data in the form of packets :
A Packet consists of

1. Start of header           <   soh    >     1 byte
2. Packet number           <   pk no >     1 byte
3. ~Packet number        <~(pk no)>    1 byte
4. 128 bytes of data       <   data    > 128byte
5. 2 bytes of check sum <    crc     >     2byte
                                                            -------------
                                                            133 byte
                                                            -------------
In this protocol the data packet is in the format :


The file is divided into packets and send according to acknowledgements . Before sending another packet acknowledgement should be sent to say that we received the packet successfully or return No Acknowledgement so that the same packet will be retransmitted .

Packet number starts from value 1 and goes upto 255 and then start from 0 . 
Checksum is calculated by taking a 256 modulus of the sum of all ASCII values of each of 128 bytes in the data block.

The data flow is given :


The receiver will be sending 'C' to transmitter i.e:XMODEM to say that i am ready to receive data waits for 3 seconds and then timeout and again resend 'C' this will be continuing  until we receive data.

If we get the data then send the acknowledgement to the minicom so that xmodem will come to know that packet was received successfully and then this continues and if something goes wrong some error in the packet or not received it sends <NAK> (No Acknowledgement ) so that it transmit the same packet to the receiver. 

To verify that whole data is transmitted it sends EOT at the end which is nothing but End Of Transmission we should be checking for EOT. 

At receiver side you should build the code to receive the data don't bother about transmission as it is simple it is done by the hyperterminal. I will show you this clearly in next post.

In next post we will discuss about the XMODEM - checksum it is similar as the crc little changes were present.

9 Jul 2012

LocK Bits in detail

LOCK BITS :

          Before we discuss these bits lets take a practical example in day to day life until now we are dealing with the byke example right . we discussed fuses are like gares which are used to ride the microcontroller and in the same way you protect your byke with a Lock right to protect it from being stolen . In the same way you have your developed a project and now you burn this code to the microcontroller there are chances that someone can hack your code from it right so in order to protect your code you lock your microcontroller after all the code is written one time . so that others cannot steel your code.

You have different combination of locks over here for that You refer the data sheet MEMORY PROGRAMMING section you will mostly find this information at the beginning itself ok.

Real time scenario:
           Ya assume that you wrote a bootloader . Now your bootloader is writting your application section from bootloader section so while writting you should be careful that it never erases or never writes into the bootloader section so you need to lock that perticular section in order to disable the access to that section ok. Now By using the lock bits you can do this protection .

Ya i will explain you the lock bits in atmega8 ok......

Same way as fuse bits here also
0 --> Programmed
1 --> Unprogrammed

Lock bits are 6 in number
     ------               Reserved
     ------               Reserved
1. BLB12   --      1
2. BLB11   --      1
3. BLB02   --      1
4. BLB01   --      1
5. BL2       --      1 
6. BL1       --      1

Selecting the BL2  & BL1 is based on your requirement the below values you use
                        1          1          -->    No memory lock features
                        1          0          -->    Disable programming Flash and EEPROM
                        0          1          -->    Disable programming and verification of Flash and EEPROM in any mode.

In the same way comes
BLB02 &BLB01 (APPLICATION PART)
    1             1            -->   No restrictions for SPM or LPM for accessing APP sec.
    1             0            -->   SPM NO write to APP sec.
    0             0            -->   1. NO write to APP sec by the SPM.
                                         2. LPM executing from the bootloader section is not allowed to read from APP sec.
                                         3. If Interrupt vectors are placed in BOOT  sec interrupts are disabled while executing from the APP section.
    0             1            -->    only ( 2 ) & ( 3 ) points are enabled.   

BLB12 & BLB11  (BOOTLOADER PART):
    1             1            -->   

      



LoW FuSe bits

LOW FUSE BITS:

     As i explained what are the uses of fuses and how they are to be used now we will only discuss what LOW FUSE BITS are used for .


         FUSES            DEFAULT settings
     1. BODLEVEL   ----    1
     2. BODEN         ----    1
     3. SUT1             ----    1
     4. SUT0             ----    0
     5. CKSEL3        ----    0
     6. CKSEL2        ----    0
     7. CKSEL1        ----    0
     8. CKSEL0        ----    1

BODLEVEL  --   This fuse bit we set when we need the brown out detector. Like you have a application which should Reset when the input voltage is less than 4.5 V and another as when ever the voltage goes below 2.7 V it should get reset .

So, the first requirement can be achieved without enabling this fuse you get the trigger level of 4.5V and for second requirement you need to enable or program the fuse to '0' so that trigger level changes to 2.7V (this is used when you need you circuit to work even you have voltage less than 5 . In some conditions it require .

BODEN        - - This fuse bit we set for enabling the Brown Out Detector .

SUT1  ,  SUT0   :
                       This by default setted to the maximum startup time. In order to change the startup time we use them. There are different levels of startups you should refer datasheet in clock source section . Based on your application you should program these bits

CKSEL3 , CKSEL2, CKSEL1, CKSEL0 :

                       These fuses are used for selecting the frequency of the clock at which it should run . For different frequencies these fuses changes same as i said garing the microcontroller before it starts working. These fuse bits are like gares if you don't gare them properly you may loose your microcontroller or it may not work as you like it to work.

Finally what i mean to tell Read these bits clearly in data before you program it because you may messed up with the fuse setting some time so before setting fuse bits make  yourself  comfortable before you decided to write them on MC . ok

At beginning it looks like it is difficult once when you are some practice you automatically program for what ever you require ok.

Learn them well .........................................

How to work with them in avrdude :   click here

After this will go  to Lock bits which are also important to be discussed  in next tutorial . Link to Lock bits

8 Jul 2012

FuSe Bits and their functionality

Hai.........
Lets discuss about the Fuse bits which are perticularly important in atmega or avr microcontrollers .

Ya i will give some example to understand clearly i know that most of us know bike or car to ride right so lets think you have a bike and you need to ride it that has gares ok so you sit on bike and start it after that in order to move you need to step into bike/car and give your first gare to move the vehicle right in the same there are some conditions to be met in order to run the avr microcontroller . Even though you write program into microcontroller you need to gare it with fuse bits . We should give the clear gares how to work . ok

Now lets come to the atmega8 here you have fuses bits which are
  1. High fuse bits  (8 bits)
  2. Low fuse bits (8 bits)
and there are some other bits named  "EXTENDED FUSE BITS " which are not present in this microcontroller for some controllers with high performance have these bits depending on their working same as having different set of gares for different capacity bikes .

By Default the fuse bits are set to some value. you can check it by using the commands listed in the below 

Here the value 1 indicates the "UNPROGRAMMED"
                         0 indicates  "PROGRAMMED"

High Fuse Bits:
I will give you the high fuse bits which are present in the atmega8
         Bits                            Default values
  • RSTDISBL     -->        1
  • WDTON         -->        1
  • SPIEN           -->         0
  • CKOPT          -->         1
  • EESAVE        -->         1
  • BOOTSZ1      -->         0
  • BOOTSZ0      -->         0
  • BOOTRST     -->          1
So , these are the fuse bits which are called HIGH FUSE BITS.
WDTON   --  This bit is programmed when we use the watch dog timer i.e the watch dog timer doesn't work perfectly if you don't enable this if you are using the predefined library functions.
                   [WATCH DOG TIMER RELATED BIT]
SPIEN     -- This fuse should be programmed when you are using the serial peripheral interconnect protocol and This must be always enabled if you want to communicate through this interface.
               note:  Never ever make this bit unprogrammed until you think you don,t need but you never come to this . I prefer not to touch this bit at all. let this be programmed.
                   [ SPI RELATED BIT]

CKOPT    --  This fuse is used to select whether you need the internal clock or external clock to your microcontroller. In order to understand this clearly you should be clear with clock concept and what bits are related to the clock.
                   [CLOCK RELATED BIT]


EESAVE  --  This is used while EEPROM programming . we think if we just used the EEPROM related registers and dump the values we needed into the eeprom it will store the values right no this concept some what different you should enable the EESAVE gare like gare of a byke and then program the eeprom values into the microcontroller eeprom. ok
So, what  you do is write program and burn the hex file and then set the fuses.

BOOTSZ0, BOOTSZ1:
                     In breif microcontroller has two sections in memory locations
                     1. Application and
                     2. Bootloader section
lets about these things in detail in next coming tutorials .
These fuses are used to configure the size of the bootloader and flash they are specified in the data sheet different microcontrollers have different locations and sizes.
            Bootloader concept is a vast subject so upto to now know this only you can write the flash to itself using it . In this section all store program memory commands are executed  and in application section load program memory instructions are executed i.e: reads the falsh that it it couldn't write to flash are.
   Bootloader section    --- write to flash area of its own
   Application section   ---  Reads the flash and execute the written program .

BOOTRST -- This fuse bit is used for selecting reset position. As i said flash will have two sections . So, Two sections means we can set the RESET position to bootloader or application section. Lets say you need when ever you reset you should activate your bootloader section then PROGRAM this bit else if you want your application itself to execute after the RESET is pressed then it jumps to the location of application section 0x0000 where your application program is written.
             Reset vector to bootloader section  ---  0   (programmed)
             Reset vector to application section  ---  1  (unprogrammed)
How to burn the fuse bits: click here

You can Read next tutorial for the Low fuse bits