Playing with Arduino
A page to record my playing with Arduino
Internal Structure of Arduino Software

Introduction

I am analyzing the implementation and internal structure of the Arduino Software 1.8.10. The goal is to clarify the software that comes with arduino-1.8.10-windows.zip as far as I can.

I checked the code for Arduino Uno where #if is used. It means Arduino Mega or Leonardo may have different behavior.

If you have any comments, suggestions, corrections or anything, please contact to ‘garretlab at gmail.com’ by e-mail. Note that I am a Japanese, please use plain English.

Arduino

wiring_digital.c
pinMode()function to configure the port as an input or an output.
digitalRead()returns if the specified pin is HIGH or LOW.
digitalWrite()sets the specified digital pin to HIHG or LOW.
turnOffPWM() stops PWM output of a specified timer.
wiring_analog.c
analogReference()sets the reference voltage for analog input.
analogRead()reads the value from analog pin using analog-digital(AD) converter.
analogWrite()outputs PWM(Pulse Width Modulation) wave.
Tone.cpp
tone()generates square wave with specified frequency.
toneBegin()manages the relation of pin and timer.
noTone()stops the output of square wave.
disableTimer()initializes the timer/counter set by tone().
TIMER2_COMPA_vectinterrupt handler which is called when the timer/counter2(TCNT2) becomes the same value of compare register(OCR2A).
wiring.c
init()initializes the timer counter, AD converter and serial communication of ATmega328P.
millis()returns the number of milliseconds since the board has booted.
micros()returns the number of microseconds since the board has booted.
TIMER0_OVF_vectinterrupt handler that is executed when the Timer/Counter0(TCNT0) overflows.
WInterrupts.c
attachInterrupt()function to sets a function to be called when an external interrupt occurs.
detachInterrupt()function to resets a function to be called when an external interrupt occurs.
wiring_shift.c
shiftIn()gets 8 bit of data and assembles them into 1 byte of data.
shiftOut()sends a byte of data bit by bit.
wiring_pulse.c
pulseIn()measures the time of input pulse.
wiring_pulse.S
countPulseASM()assembler code to count the pulse length.
hooks.c
yield()function to relinquish the CPU.
HardwareSerial0.cpp
Serialdefinition of Serial object.
USART_RX_vectan interrupt handler that is called when a data is received using serial communication.
USART_UDRE_vectan interrupt handler that is called when a data can be transmitted using serial communication.
HardwareSerial.cpp
Registers for serial communicationRegisters for serial communication.
HardwareSerial::begin()sets theg communication speed and other settings.
HardwareSerial::end()ends the serial communication and sets RX and TX pins to normal input/output mode.
HardwareSerial::read()reads data from receive buffer.
HardwareSerial::peek()reads data from receive buffer without modifying the buffer.
HardwareSerial::available()returns how many bytes can be written to receive buffer of serial communication.
HardwareSerial::flush()sends all data in the serial transmit buffer.
HardwareSerial::write()wites binary data to serial port.
HardwareSerial::availableForWrite()returns how many bytes can be written to transmit buffer of serial communication.
HardwareSerial::_tx_udr_empty_irq()copies data from Arduino serial communication transmit buffer to ATmega328P data transmit register.
HardwareSerial_private.h
HardwareSerial::HardwareSerial()constractor of HardwareSerial.
HardwareSerial::_rx_complete_irq()copies data from the receive buffer of ATmega328P to the receive buffer of Arduino.
HardwareSerial.h
HardwareSerialdefinition of HardwareSerial.
HardwareSerial::operator bool()checks if the serial port is available or not.
wiring_private.h
sbi()macro to set the bit(the second argument) of the address(the first argument) to 1.
cbi()macro to set the bit(the second argument) of the address(the first argument) to 0.
Arduino.h
digitalPinToBitMask()macro that returns the bitmask of a specified pin.
digitalPinToPort()macro that returns the port of a specified pin.
digitalPinToTimer()macro that returns the timer of a specified pin.
portModeRegister()macro that returns a mode register that controlls the mode of the specified port.
portOutputRegister()macro that returns an output port register of the specified port.
portInputRegister()macro that returns an input port register of the specified port.
bitRead()/bitSet()/bitClear()/bitWrite()read and write a bit from/to in the variable.
clockCyclesPerMicrosecond()/ clockCyclesToMicroseconds()/ microsecondsToClockCycles()convert the number of clocks and time(in microsecond).
interrupts()/noInterrupts()enables or disables the interrupts.

AVR-GCC

pgmspace.h
pgm_read_byte()macro that read a word of data stored in a specified address(PROGMEM area).
pgm_read_byte_near()macro that reads a byte of data stored in a specified address(PROGMEM area).
__LPM()macro that reads a byte of data stored in a specified address(PROGMEM area).
__LPM_enhanced__()assembler code that reads a byte of data stored in a specified address(PROGMEM area).
pgm_read_word()macro that read a word of data stored in a specified address(PROGMEM area).
pgm_read_word_near()macro that reads a word of data stored in a specified address(PROGMEM area).
__LPM_word()macro that reads a word of data stored in a specified address(PROGMEM area).
__LPM_word_enhanced__()macro that reads a byte of data stored in a specified address(PROGMEM area).
common.h
SREGStatus register of ATmega328P.
sfr_defs.h
_BV()macro that checks if the second argumen-th bit of the first argument is 1.
_SFR_ADDR()macro that returns the address of the argument.
_SFR_MEM_ADDR()macro that returns the address of the argument.
_SFR_BYTE()macro that returns a byte of data of the specified address.
_SFR_WORD()macro that returns two bytes of data of the specified address.
_SFR_IO8()converts the I/O address to the memory address.
_SFR_MEM8()macro to return a byte of data of the specified address.
_SFR_MEM16()macro to return two bytes of data of the specified address.
_MMIO_BYTE()macro that dereferences a byte of data at the specified address.
_MMIO_WORD()macro that dereferences two bytes of data at the specified address.
bit_is_set()macro that checks if the second argumen-th bit of the first argument is 1.
bit_is_clear()macro that checks if the second argument-th bit of the first argument is 0.
_VECTOR()macro to convert an interrupt vector number to a real address.
iom328p.h
DDRregisters which determine if the digital pin is output mode or input mode.
PINregisters to control digital I/O.
PORT registers for bi-directional I/O.
ADMUXregister that controls the reference voltage, the presentation of the ADC conversion and analog channel selection.
ADCSRAregister to control AD conversion.
ADCL/ADCHregisters which store the result of AD conversion.
Timer/Counter Control Registerregisters to control timers and counters.
Output Compare Registerregisters to set the duty ratio for PWM output.
Timer/Counter Interrupt Mask Registerregisters related to timer interruption.
Interrupt VectorsDefinitions of the interrupt vectors.
Timer/Counter Registerregisters incremented by each timer clock.
Timer/Counter Interrupt Flag Registerregisters to control timer interruption.
EICRA/EIMSKregisters to control external interrupts.
USART0registers related to Universal Synchronous and Asynchronous serial Receiver and Transmitter.
interrupt.h
cli()macro that executes an assembler instruction to disable interrupts.
sei()macro that executes an assembler instruction to enable interrupts.
ISR()macro that executes an assembler instruction to disable interrupts.
SIGNAL()macro to define a function to register to interrupt vectors.

Last update

August 19, 2019



inserted by FC2 system