7,275
edits
(→諸注意) |
|||
(One intermediate revision by the same user not shown) | |||
[http://xx-prime.hatenablog.com/entry/2015/04/26/224618 Arduino yunで放射線センサのデータをxivelyとM2Xにアップロードする - XX-Prime's blog]
[http://qiita.com/kassy_kz/items/ebeda9bcda444cf401a0 IFTTTを用いてArduinoからツイートする
[https://github.com/itman83/ArduinoYun https://github.com/itman83/ArduinoYun]
{
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);
|