179        SPISettings( uint32_t maxSpeed, uint8_t bitOrder, uint8_t dataMode )
 
  181            if ( __builtin_constant_p( maxSpeed ) )
 
  183                initAlwaysInline( maxSpeed, bitOrder, dataMode );
 
  187                initMightInline( maxSpeed, bitOrder, dataMode );
 
 
  236        void initMightInline( uint32_t maxSpeed, uint8_t bitOrder, uint8_t dataMode )
 
  238            initAlwaysInline( maxSpeed, bitOrder, dataMode );
 
  242#pragma GCC diagnostic push 
  243#pragma GCC diagnostic ignored "-Wunused-variable" 
  245        void initAlwaysInline( uint32_t maxSpeed, uint8_t bitOrder, uint8_t dataMode )  __attribute__((__always_inline__))
 
  250            const uint8_t kSpiClockDiv4     = 0x00;
 
  251            const uint8_t kSpiClockDiv16    = 0x01;
 
  252            const uint8_t kSpiClockDiv64    = 0x02;
 
  253            const uint8_t kSpiClockDiv128   = 0x03;
 
  254            const uint8_t kSpiClockDiv2     = 0x04;
 
  255            const uint8_t kSpiClockDiv8     = 0x05;
 
  256            const uint8_t kSpiClockDiv32    = 0x06;
 
  258            const uint8_t kSpiModeMask      = 0x0C;   
 
  259            const uint8_t kSpiClockMask     = 0x03;   
 
  260            const uint8_t kSpi2xClockMask   = 0x01;   
 
  286            if ( __builtin_constant_p( maxSpeed ) )
 
  288                if ( maxSpeed >= F_CPU / 2 )
 
  292                else if ( maxSpeed >= F_CPU / 4 )
 
  296                else if ( maxSpeed >= F_CPU / 8 )
 
  300                else if ( maxSpeed >= F_CPU / 16 )
 
  304                else if ( maxSpeed >= F_CPU / 32 )
 
  308                else if ( maxSpeed >= F_CPU / 64 )
 
  319                uint32_t clockSetting = F_CPU / 2;
 
  321                while ( clockDiv < 6 && maxSpeed < clockSetting )
 
  340                    | ( (bitOrder == 
kLsbFirst) ? _BV(DORD) : 0 )
 
  341                    | ( dataMode & kSpiModeMask )
 
  342                    | ( (clockDiv >> 1) & kSpiClockMask );
 
  344            mSpsr = clockDiv & kSpi2xClockMask;
 
  347#pragma GCC diagnostic pop 
 
  450        asm volatile( 
"nop" );
 
  451        while ( !( SPSR & _BV(SPIF) ) )
 
 
  482        if ( SPCR & _BV(DORD) )
 
  485            asm volatile( 
"nop" );              
 
  486            while ( !( SPSR & _BV(SPIF) ) )
 
  491            asm volatile( 
"nop" );
 
  492            while ( !( SPSR & _BV(SPIF) ) )
 
  499            asm volatile( 
"nop" );                
 
  500            while ( !( SPSR & _BV(SPIF) ) )
 
  504            asm volatile( 
"nop" );
 
  505            while ( !( SPSR & _BV(SPIF) ) )
 
 
  539    inline void transmit( uint8_t* buffer, 
size_t count )
 
  546            while ( --count > 0 )
 
  548                uint8_t out = *(p + 1);
 
  549                while ( !( SPSR & _BV(SPIF) ) )
 
  556            while ( !(SPSR & _BV(SPIF) ) )
 
 
 
A class that binds settings for configuring SPI transmissions.
Definition SPI.h:159
SPISettings()
The constructor builds an SPISettings object with default settings corresponding to a maximum transmi...
Definition SPI.h:199
SPISettings(uint32_t maxSpeed, uint8_t bitOrder, uint8_t dataMode)
The constructor builds an SPISettings object out of three parameters describing the maximum transmiss...
Definition SPI.h:179
uint8_t getSpcr() const
Return the appropriate configure value for the SPCR register.
Definition SPI.h:212
uint8_t getSpsr() const
Return the appropriate configure value for the SPSR register.
Definition SPI.h:224
This namespace bundles an interface to the SPI hardware subsystem on the AVR ATMega328p (Arduino Uno)...
Definition SPI.h:110
uint32_t transmit32(uint32_t data)
Transmit a long-word-sized integer (four bytes) using the SPI subsystem. The order in which the bytes...
Definition SPI.cpp:90
SpiMode
An enumeration that defines the modes available for SPI transmissions.
Definition SPI.h:131
@ kSpiMode0
Phase falling, idle low (CPHA = 0, CPOL = 0)
Definition SPI.h:132
@ kSpiMode1
Phase rising, idle low (CPHA = 1, CPOL = 0)
Definition SPI.h:133
@ kSpiMode3
Phase rising, idle high (CPHA = 1, CPOL = 1)
Definition SPI.h:135
@ kSpiMode2
Phase falling, idle high (CPHA = 0, CPOL = 1)
Definition SPI.h:134
void enable()
Enable the SPI subsystem for transmission.
Definition SPI.cpp:38
ByteOrder
An enumeration that defines the byte order for multibyte SPI transmissions.
Definition SPI.h:116
@ kLsbFirst
Least significant byte first.
Definition SPI.h:117
@ kMsbFirst
Most significant byte first.
Definition SPI.h:118
uint8_t transmit(uint8_t data)
Transmit a single byte using the SPI subsystem.
Definition SPI.h:441
void configure(SPISettings settings)
Set the configuration of SPI subsystem to match the needs of the system you are going to communicate ...
Definition SPI.h:426
void disable()
Disable the SPI subsystem, precluding further transmissions.
Definition SPI.cpp:79
uint16_t transmit16(uint16_t data)
Transmit a word-sized integer (two bytes) using the SPI subsystem. The order in which the bytes are s...
Definition SPI.h:467