wiki:SPIMaster

Version 3 (modified by sgk, 15 years ago) ( diff )

--

SPIマスター

Arduino用のSPIクラス(マスター側)を書きました。

source:/arduino-spi

使い方の例。MAX6675冷接点補償K熱電対ディジタルコンバータから温度を読んでみました。

#include "SPI.h"

#define SLAVE  10

void
setup()
{
  Serial.begin(9600);
  SPI_Master.begin(SLAVE);
}

void
loop()
{
  delay(500);
  long value;
  SPI_Master.enable(SLAVE);
  value = SPI_Master.read() << 8;
  value |= SPI_Master.read();
  SPI_Master.disable();
  
  if ((value & 0x0004) != 0)
    Serial.println("Error");
  else
    Serial.println((float)(value >> 3) / 4);
}
Note: See TracWiki for help on using the wiki.