| 24 | #endif |
| 25 | |
| 26 | void SPIClass::begin() |
| 27 | { |
| 28 | uint8_t sreg = SREG; |
| 29 | noInterrupts(); // Protect from a scheduler and prevent transactionBegin |
| 30 | if (!initialized) { |
| 31 | // Set SS to high so a connected chip will be "deselected" by default |
| 32 | uint8_t port = digitalPinToPort(SS); |
| 33 | uint8_t bit = digitalPinToBitMask(SS); |
| 34 | volatile uint8_t *reg = portModeRegister(port); |
| 35 | |
| 36 | // if the SS pin is not already configured as an output |
| 37 | // then set it high (to enable the internal pull-up resistor) |
| 38 | if(!(*reg & bit)){ |
| 39 | digitalWrite(SS, HIGH); |
| 40 | } |
| 41 | |
| 42 | // When the SS pin is set as OUTPUT, it can be used as |
| 43 | // a general purpose output port (it doesn't influence |
| 44 | // SPI operations). |
| 45 | pinMode(SS, OUTPUT); |
| 46 | |
| 47 | // Warning: if the SS pin ever becomes a LOW INPUT then SPI |
| 48 | // automatically switches to Slave, so the data direction of |
| 49 | // the SS pin MUST be kept as OUTPUT. |
| 50 | SPCR |= _BV(MSTR); |
| 51 | SPCR |= _BV(SPE); |
| 52 | |
| 53 | // Set direction register for SCK and MOSI pin. |
| 54 | // MISO pin automatically overrides to INPUT. |
| 55 | // By doing this AFTER enabling SPI, we avoid accidentally |
| 56 | // clocking in a single bit since the lines go directly |
| 57 | // from "input" to SPI control. |
| 58 | // http://code.google.com/p/arduino/issues/detail?id=888 |
| 59 | pinMode(SCK, OUTPUT); |
| 60 | pinMode(MOSI, OUTPUT); |
| 61 | } |
| 62 | initialized++; // reference count |
| 63 | SREG = sreg; |
| 64 | } |
| 65 | |
| 66 | void SPIClass::end() { |
| 67 | uint8_t sreg = SREG; |
nothing calls this directly
no test coverage detected