ATmega328P Peripherals@Arduino Uno

This is in continuation of last blog Please SUBSCRIBE to YouTube channel Embedkari  for further discussion on Embedded Systems. I will validate the ATmega328P concepts with practical approach. You will realized this only after reading till end. I recommend to  use laptop/PC or at least Tablet for  watching related YouTube video.

What is the  User Application Program Flow from location 0x0000 ?

Disassembly of user application generated by method discussed in earlier blog shows :

  • 00000000 <__vectors>:0: 0c 94 5d 00 jmp 0xba ; 0xba <__ctors_end>4: 0c 94 85 00 jmp 0x10a ; 0x10a <__bad_interrupt>
  • ::::::::::::::::::::::::::::::::::::::::::::::::
  • 000000ba <__ctors_end>:
  • ::::::::::::::::::::::::::::::::::::::::
  • 0xf4 <__do_global_ctors+0x8>102: 0e 94 ce 02 call 0x59c ; 0x59c <main>  //Calling User main() defined at 
  • C:\Program Files (x86)\Arduino\hardware\arduino\avr\cores\arduino
  • int main(void)  //main() of User Application{init()

    ::::::::::::::

  •      setup();  // calling setup() defined in Sketch 
  •      for (;;) {            loop();  // calling loop() defined in Sketch              if (serialEventRun) serialEventRun(); // Function callback

                     }

  •      return 0;}

Callback Function :The core specific code invokes serialEvent() if defined by user.

  • void serialEventRun(void){#if defined(HAVE_HWSERIAL0)

    if (Serial0_available && serialEvent && Serial0_available()) serialEvent();

    #endif

    :::::::::::::::::::::::Similar code for  HWSERIAL1,HWSERIAL2,HWSERIAL3:::::::::::::::::::::::

    }

How SRAM Data Memory is defined ?   Lets look at the Data Memory MAP again:

mem5

  • This device has 2K bytes internal SRAM for data memory from 0x100 to 0x8FF
  • The data memory range is defined by  RAMSTART(0x100) and RAMEND(0x8FF)  in iom328p.h at  C:\Program Files (x86)\Arduino\hardware\tools\avr\avr\include\avr
  • The common io.h file includes iom328p.h  for ATmega328P

How to customize the ATmega328P Peripherals ?

arduno2

PIN Multiplexing Each pin can be configured for particular functionality

I/O-Ports :

  • Data Register (Portx) :If PORTxn is written to ‘1’ when the pin is configured as an input pin, the pull-up resistor is activated. To switch the pull-up resistor off, PORTxn has to be written to ‘0’ or the pin has to be configured as an output pin.
  • Data Direction Register (DDRx) : 1 (output), 0(Input)
  • Port Input Pins (PINx) : Read only. Writing one will result a toggle in corresponding data register bit
  • Pull-up Disable (PUD) bit:  MCUCR[PUD] disables the pull-up function for all pins in all ports when set.
  • Note: The port pins will be  tri-stated after RESET . Writing a ‘1’ to PINxn toggles the value of PORTxn, independent on the value of DDRxn. The SBI instruction can be used to toggle one single bit in a port

References : All documents are available here. I am referring to most of these :

Thanks for reading till end. I am trying to improve usability of my  site. Did you find this discussion helpful ? If so,  Please subscribe to YouTube channel Embedkari as well for additional embedded related stuff.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.