Last active
January 13, 2020 20:09
-
-
Save ti-nspire/80b821e54f69a506b78a3d7e77d01019 to your computer and use it in GitHub Desktop.
MAX31855_Example_for_ATmega328P
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <avr/io.h> | |
#include <util/delay.h> | |
extern "C" { | |
#include "USART.h" | |
} | |
#include "mySPI.h" | |
#include "MAX31855.h" | |
int main(){ | |
initUSART(); | |
MAX31855 tc('B', 2); // PB2を!SS端子として実体化する。PB3~PB5は!SS端子に指定してはならない。 | |
enableSPI(128, 0, 'M'); // SPIクロック=(システムクロック/128分周)、モード0、MSBファーストでSPIを開始する。 | |
while(1){ | |
tc.getData(); // 32ビットを全部取得する。 | |
printString("!SS pin : P");transmitByte(tc.getPort());printNibble(tc.getPin());printString("\n");// !SSピン | |
printString("hot temp : ");printFloat (tc.getHotTemp()) ;printString("\n");// 熱接点温度 | |
printString("cold temp : ");printFloat (tc.getColdTemp()) ;printString("\n");// 冷接点温度 | |
printString("failed? : ");printNibble(tc.isFailed()) ;printString("\n");// 下のいずれかが発生しているか? | |
printString("shorted2Vcc?: ");printNibble(tc.isShorted2Vcc());printString("\n");// 電源に短絡しているか? | |
printString("shorted2Gnd?: ");printNibble(tc.isShorted2Gnd());printString("\n");// GNDに短絡しているか? | |
printString("opened? : ");printNibble(tc.isOpened()) ;printString("\n");// 切れているか(外れているか)? | |
printString("\n"); | |
_delay_ms(1000); | |
} | |
disableSPI(); // SPIを無効化する(ただしここまでは達しない)。 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment