+ 한국항공대학교 최차봉 교수님의 임베디드 SW 과목 내용을 정리한 글입니다.
Asynchronous Communication Limitation (UART)
클럭 대신 start bit, stop bit을 사용한다.
1. Problems when two systems with slightly different clocks
= 두 시스템간의 싱크가 맞지 않아 클럭이 다를 수 있다.
2. A lot of Overhead on Every Byte
= 8 bit 데이터를 전송하는데 2 bit가 더 들어가기 때문에 효율이 80%밖에 되지 않는다.
3. Complex Hardware required
= 클럭 대신 데이터를 갖고 싱크를 맞춰야하기 때문에 하드웨어가 복잡해진다.
4. If the receiver is looking at the wrong times, it will see the wrong bits.
= 두 시스템의 시간이 다를 경우, 잘못된 비트를 읽어 에러가 발생한다.
=> Synchronous Solution: SPI
= 클럭을 사용한 해결책이다.
SPI (Serial Peripheral Interface)
Uses seperate lines for Perfect Sync
= 양쪽에서 별도의 클럭 데이터를 받기 때문에 클럭이 달라질 수 없다.
= Clock Signal의 Rising or Falling Edge에서 Clock 데이터를 주고 받으며 동시에 데이터를 읽거나 쓴다.
+ Master = Controller
+ Slave = Peripheral
(Only one side) Master generates Clock Signal (SCK = CLK)
= Master에서 Clock 신호를 보낸다.
(The other side) Slave can be Multiple.
= Slave는 여러 개가 있을 수 있다.
MOSI(COPI): Data is sent from Master to Slave.
= Master에서 Slave로 가는 신호 (Master Out Slave In)
MISO(CIPO): Slave sends Response back to Master.
= Slave에서 Master로 가는 신호 (Master In Slave Out)
Full Duplex (전이중 통신)
= 송수신을 동시에 가능하다.
ex) 휴대폰
vs Half Duplex (반이중 통신)
= 한 번에 한 방향으로만 통신이 가능하다.
ex) 무전기
SS(CS): SS Should be LOW to talk to a Particular Slave
= 초기에는 HIGH 상태이고, LOW 상태일 때, 특정 Slave와 통신 가능하다. (Slave Select)
+ 한 개만 LOW로 선택할 수 있다.
Programming for SPI
SPI.begin()
= SPI 통신 시작
SPI.end()
= SPI 통신 종료
SPI.setCloclDivider(x)
= 클럭을 x배 느리게 설정
SPI.transfer()
= SPI 통신 수행
SPI 장단점
< 장점 >
1. Asynchronous (UART) 통신보다 빠르다.
2. 하드웨어적으로 단순하다.
3. 여러 개의 Slave와 동시에 통신 가능하다.
< 단점 >
1. 많은 선들이 필요하다. (MISO, MOSI, SCK 등..)
2. 코드를 잘 짜야한다. (어렵다.)
3. Slave끼리는 서로 직접 통신할 수 없고, 모든 통신을 Master가 통제해야 한다.
4. 각 Slave마다 서로 다른 CS가 필요하다. Slave가 많아지면 문제가 발생한다.
'Computer Science > Embedded Software' 카테고리의 다른 글
[Embedded Software] SPI Communication 실습 (2) | 2023.10.18 |
---|---|
[Embedded Software] UART Communications 실습 (0) | 2023.10.11 |
[Embedded Software] Serial Communications (0) | 2023.10.11 |
[Embedded Software] PWM 실습 (1) | 2023.10.05 |
[Embedded Software] Interrupt 실습 (0) | 2023.09.27 |