로직 애널라이저를 시험해보는 그 3(SPI)
SPI를 로직 애널라이저로 확인
여기의 속편에서 이번에는 SPI를 시도한다.

PulseView
이번에는 Windows판을 사용한다. 여기 등에서 Download. 설정에 대해서는, 그 1 , 그 2 와 같다.
SPI 설정
프로토콜을 선택한다(아래의 “Add protocol decode”클릭).

그러면 다음 대화 상자가 표시됩니다.

"SPI"를 입력하여 검색하고 SPI를 클릭합니다.

Clock을 D7, CS를 D0, MOSI를 D3, MISO를 D4에 할당한다(사용하지 않는 핀은 “Disable”로 설정). 이번 이용하는 SPI 디바이스(A/D 컨버터)의 모드는 "Mode 0,0"이므로, "Clock polarity"및 "Clock phase"는 모두 '0'이 된다.
대상 기기
이전 시도한 A/D 컨버터 MCP3008이 SPI 디바이스, A/D 컨버터 앞에 온도 센서가 있다. 온도 센서는 A/D 컨버터의 Channel 0에 접속.
A/D 컨버터 MCP3008
데이터시트 에서 다음 부분이 중요.

소스 코드
여기 에 있던 코드를 약간 수정한 정도(감사합니다!).
#include <SPI.h>
#define SPI_CS 10
float Vref = 5.0 ;
SPISettings settings(1000000,MSBFIRST,SPI_MODE0);
void setup() {
Serial.begin(9600);
pinMode(SPI_CS, OUTPUT);
SPI.begin();
}
void loop(){
// SPI setting and write&read
SPI.beginTransaction(settings);
digitalWrite(SPI_CS, LOW);
SPI.transfer(0b00000001); // Start bit 1
byte highByte = SPI.transfer(0b10000000); // SingleEnd Channel 0
byte lowByte = SPI.transfer(0x00); // dummy
digitalWrite(SPI_CS, HIGH);
SPI.endTransaction();
unsigned int dataCh0 = ((highByte & 0x03) << 8) + lowByte;
// Conversion of read data according to MCP9700 spec
float volts = dataCh0 * Vref / 1024;
float temperature = (volts - 0.5) / 0.01; // : 500 mv at 0 degree and 10 mv / degree
Serial.println("dataCh0: " + String(dataCh0,HEX) + " Voltage: " + String(volts,3));
Serial.println("Temperature: " + String(temperature,2) + " degrees");
Serial.println();
delay(3000);
}
위에서 설명한 데이터 시트가 구현되었습니다.
- SPI 설정은 1MHz, MSB First, 모드 0(Mode 0,0)
- CS Low
- "Start bit"write
- "SingleEnd/Channel 0"write & 1바이트 read
- Dummy write & 1바이트 읽기
- CS를 High
배선의 모습

여기 과 같다. 보이지 않지만 Vcc와 GND는 Arduino 측에 연결되어 있습니다.
(로지아나용으로 복수의 와이어 있음.)
결과
로직 애널라이저 디코딩 결과 및 시리얼 콘솔 디스플레이는 다음과 같습니다.

디지털 변환 된 값 "9b"가 모두 보입니다. 성공.
마지막으로
실은 계속이 있습니다.
Reference
이 문제에 관하여(로직 애널라이저를 시험해보는 그 3(SPI)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다
https://qiita.com/infinite1oop/items/01d2dbbc9ed24c2458df
텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)
#include <SPI.h>
#define SPI_CS 10
float Vref = 5.0 ;
SPISettings settings(1000000,MSBFIRST,SPI_MODE0);
void setup() {
Serial.begin(9600);
pinMode(SPI_CS, OUTPUT);
SPI.begin();
}
void loop(){
// SPI setting and write&read
SPI.beginTransaction(settings);
digitalWrite(SPI_CS, LOW);
SPI.transfer(0b00000001); // Start bit 1
byte highByte = SPI.transfer(0b10000000); // SingleEnd Channel 0
byte lowByte = SPI.transfer(0x00); // dummy
digitalWrite(SPI_CS, HIGH);
SPI.endTransaction();
unsigned int dataCh0 = ((highByte & 0x03) << 8) + lowByte;
// Conversion of read data according to MCP9700 spec
float volts = dataCh0 * Vref / 1024;
float temperature = (volts - 0.5) / 0.01; // : 500 mv at 0 degree and 10 mv / degree
Serial.println("dataCh0: " + String(dataCh0,HEX) + " Voltage: " + String(volts,3));
Serial.println("Temperature: " + String(temperature,2) + " degrees");
Serial.println();
delay(3000);
}
Reference
이 문제에 관하여(로직 애널라이저를 시험해보는 그 3(SPI)), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/infinite1oop/items/01d2dbbc9ed24c2458df텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)