Arduino Yun cheat sheet: Difference between revisions

Line 442: Line 442:
  [http://forum.arduino.cc/index.php?topic=213389.0 Arduino Yun SPI on ICSP connector (try to connect to a isd 1760 shield)]
  [http://forum.arduino.cc/index.php?topic=213389.0 Arduino Yun SPI on ICSP connector (try to connect to a isd 1760 shield)]
  [http://forum.arduino.cc/index.php?topic=223320.0 SPI on Yun]
  [http://forum.arduino.cc/index.php?topic=223320.0 SPI on Yun]
SPI Library によると、
<syntaxhighlight lang="cpp" enclose="div">
void SPIClass::begin()
{
  uint8_t sreg = SREG;
  noInterrupts(); // Protect from a scheduler and prevent transactionBegin                                                   
  if (!initialized) {
    // Set SS to high so a connected chip will be "deselected" by default                                                   
    uint8_t port = digitalPinToPort(SS);
    uint8_t bit = digitalPinToBitMask(SS);
    volatile uint8_t *reg = portModeRegister(port);
    // if the SS pin is not already configured as an output                                                                 
    // then set it high (to enable the internal pull-up resistor)                                                           
    if(!(*reg & bit)){
      digitalWrite(SS, HIGH);
    }
    // When the SS pin is set as OUTPUT, it can be used as                                                                   
    // a general purpose output port (it doesn't influence                                                                   
    // SPI operations).                                                                                                     
    pinMode(SS, OUTPUT);
    // Warning: if the SS pin ever becomes a LOW INPUT then SPI                                                             
    // automatically switches to Slave, so the data direction of                                                             
    // the SS pin MUST be kept as OUTPUT.                                                                                   
    SPCR |= _BV(MSTR);
    SPCR |= _BV(SPE);
<syntaxhighlight>
試しに、
<syntaxhighlight lang="cpp" enclose="div">
SPI.begin();
digitalWrite(SS, LOW)
<syntaxhighlight>
してみたらどうなるか確認する。


== DS3234 の SQW と Alarm ==
== DS3234 の SQW と Alarm ==