Go Down

Topic: What's beneath the Arduino library? (Read 909 times) previous topic - next topic


I was looking at the SPI library source files and saw some constructions I wasn't familiar with. My guess it is something that is called AVR (?).

I want to learn how the software layers fit together and what I can do to customize/replace them. I seek information that documents the complete stack from hardware (I found the datasheet for the mcu) up to the Arduino libraries.

Can anyone direct me to some resources (links) I can read up on?

Thanx very much.


and saw some constructions I wasn't familiar with

So post them and ask, or are we supposed to guess what you are familiar with and what you aren't?


I didn't wanna get into specifics. I'm just looking for the information on the software layer that is 'under' the Arduino 'language'/statements/functions.

But since you've asked  :D

Here's the transfer method of the SPI class:
Code: [Select]

byte SPIClass::transfer(byte _data) {
  SPDR = _data;
  while (!(SPSR & _BV(SPIF)))
  return SPDR;

I don't get the SPDR and SPSR and _BV(SPIF) stuff. What are those and where are they defined? Is that what is called AVR?


Feb 22, 2012, 01:04 pm Last Edit: Feb 22, 2012, 01:06 pm by Graynomad Reason: 1
SPDR and SPSR are registers (SPI Data and Status) in the Arduino processor. That processor is an AVR ATmegaXXX chip made by Atmel.

_BV is a macro to get a "bit value"

So that code loops until the SPIF (Interrupt Flag) bit in the SPSR (Status Register) is set indicating that the byte has been transmitted.

If you look at the ATmega328 or ATmega2560 data sheet you will find all these acronyms and register names.

Rob Gray aka the GRAYnomad www.robgray.com


Ah, so these keywords are recognized by the compiler directly?

Go Up