SlideShare a Scribd company logo
1 of 26
Download to read offline
マイコン講習
ー第5回ー
K.Miyauchi
2021.10.12
目次
・通信の基礎
・UART/USART
・I2C
・SPI
・3つの特徴
・レーザ測距センサ(I2C)
(c) K.Miyauchi 2
本講習で使用するもの
パソコン:Windows, Mac
開発環境:Arduino IDE
マイコン:Arduino Leonardo
その他,回路周りの物品
(c) K.Miyauchi 3
回路図
(c) K.Miyauchi 4
通信の基礎
通信とは、
複数のコンピュータ間でデータのやり取りをすることをいう.
通信の方法として,
大きく分けて2種類あり,シリアル通信とパラレル通信がある.
「シリアル通信」
1,2本の通信線を用いて、1bitずつ順番に送信する方法
「パラレル通信」
複数の通信線を用いて(8の倍数にすることが多い)通信する方法
(c) K.Miyauchi 5
通信の基礎
一見,パラレル通信の方が通信は思えるかもしれないが,
通信線でのデータの伝送速度や誤差などを考えたときに,
現在は,コンピュータが高性能となっているため,
シリアル通信の方が高速な通信を行うことができる.
一昔前は,パラレル通信が主流だったが,
現在はシリアル通信が主流.
(c) K.Miyauchi 6
通信の基礎
データを伝送する形式として3種類ある.
「単方向伝送」
一方向にのみ,データを伝送する方法
送信,受信のどちらかしかできない
「半二重伝送」
1つの通信線で,時間で区切って,データの送受信を行う方法
同時に送受信ができない
「全二重伝送」
2つの通信線で,データの送受信を行う方法
同時に送受信ができる
(c) K.Miyauchi 7
通信の基礎
イメージ
(c) K.Miyauchi 8
送
信
受
信
受
信
送
信
送
信
受
信
受
信
送
信
送
信
受
信
単方向伝送 半二重伝送 全二重伝送
通信の基礎
通信時の同期方式にもいくつか種類がある.
「調歩同期」
伝送データにスタートビットとストップビットを加えて,
同期をとる通信方法
「クロック同期」
データ伝送路とは別にクロックを発生させて,
クロックの立ち上がり,もしくは立ち下がりで同期をとる方法
(c) K.Miyauchi 9
通信の基礎
伝送されたデータの誤り検出方法にも,いくつか種類があります.
「パリティチェック」
伝送データにおいて,
Highとなっているビットが偶数個もしくは奇数個になるように
データに1bitのパリティビットを付与して,検出する方法
「CRC」
データビット列のあとに、
数ビットから数十ビットのCRCビットを付与して,検出する方法
(c) K.Miyauchi 10
通信の基礎
シリアル通信において,
通信の速さを表すパラメータとして,
変調速度(Baudrate)[baud]と転送速度[bps]がある.
変調速度は,
1秒間に何回の変調を行うかを表している.
転送速度は,
1秒間に何ビットのデータを転送するかを表している.
変調速度(baudrate)≠転送速度であることに注意.
(c) K.Miyauchi 11
通信の基礎
今回は,シリアル通信で用いられる
UART/USART
I2C
SPI
を紹介する.
(c) K.Miyauchi 12
UART/USART
UART(Universal Asynchronous Receiver/Transmitter)は,
調歩同期方式によるシリアル信号をパラレル信号に変換,
その逆方向の変換を行うためのインタフェースICである.
USART(Universal Synchronous Asynchronous Receiver/Transmitter)は,
クロック同期方式によるシリアル信号をパラレル信号に変換,
その逆方向の変換を行うためのインタフェースICである.
USARTは,クロックによる同期をとるため,
伝送のずれが生じないのでエラーの発生率を下げることができるが,
最大通信速度を考慮した際に,UARTより通信データ量が小さくなく傾
向がある.
UARTは,マイコン⇔コンピュータ間の通信でよく用いられる.
(c) K.Miyauchi 13
UART/USART
UART/USARTにおけるデバイス間の信号の流れ
(c) K.Miyauchi 14
TxD(送信)
RxD(受信)
GND
TxD(送信)
RxD(受信)
GND
CLK
TxD(送信)
RxD(受信)
GND
CLK
TxD(送信)
RxD(受信)
GND
UART USART
UART/USART
UART/USARTを利用した通信規格として,
RS-232CやRS-485などがあります.
これらの規格は,コンピュータ外部の
デバイス間通信などで使用する.
これらは,以下のような信号で送信します。
・スタートビット(1 bit)
・データビット(7 bit or 8 bit)
・パリティビット(0 bit or 1 bit)
・ストップビット(1 bit or 2 bit)
これらを,
1セットとして送受信する.
(c) K.Miyauchi 15
UART/USART
UARTの通信イメージ
(c) K.Miyauchi 16
START D0 D1 D2 D3 D4 D5 D6 D7 STOP
スタートビットがLowになったときに通信を開始する.
受信側はLowになったタイミングで一定リズムでRxD端子のレベル
を記録します.
ストップビットがHighになったときに受信を終了します.
信号
受信
タイミング
UART/USART
UART/USARTでは,以下について設定する必要がある.
・通信速度
・データビット数
・パリティの有無
・ストップビット数
個人的には,データビット8 bit,パリティ無し,ストップビット1 bit
をよく使用する.(ArduinoのSerial.begin()の初期設定と同じ)
(c) K.Miyauchi 17
I2C
I2C(Inter-Integrated Circuit)とは、
シリアルデータ(SDA)とシリアルクロック(SCL)の
2本の信号線で通信する通信規格である.
通信する際には,
マスタとスレーブの2つに分け,
マスタがスレーブに命令信号をだすと,
命令信号に応じて、
マスタがスレーブにデータを書き込んだり,読み込んだりできる.
I2Cは,マイコン⇔センサ間の通信でよく用いられる.
余談ですが、
I2Cが正式な書き方ですが,めんどいのでI2Cで書いてある.
また,読み方は、「アイ・スクエアド・シー」になる.
(c) K.Miyauchi 18
I2C
I2Cにおける信号の流れ
(c) K.Miyauchi 19
SCL
SDA
SCL
SDA
SCL
SDA
SCL
SDA
SCL
SDA
マスターは、
何個あってもよい
スレーブは、
何個あってもよい
マスターが特定の
アドレスを送信する
マスター送信した
アドレスが一致したら
データを送受信
I2C
通信の流れのイメージ
1.マスターがスレーブにアドレス信号を送信する.
2.スレーブがアドレスと合致したとき,
通信可能である場合に,信号を返す.
3.マスターが命令信号を出す.
4.スレーブが命令信号に対応した送受信を行う.
5.マスターが通信終了信号を送信する.
1つの伝送路で通信が行われているときには,
他のマスターやスレーブは,信号をすべて無視することになる.
(c) K.Miyauchi 20
SPI
SPI(Serial Peripheral Interface)とは、
シリアルクロック(SCK)
マスター・イン・スレーブ・アウト(MISO)
マスター・アウト・スレーブ・イン(MOSI)
スレーブセレクト(SS)
の4本の信号線で通信する規格である.(3線方式もある).
I2Cと同じように,
マスターとスレーブに分けて通信を行う.
マスターは1つしかあってはならないが,
スレーブはいくつあっても構わない(制約があり).
SPIは,マイコン⇔センサ間の通信でよく用いらる.
(c) K.Miyauchi 21
SPI
SPIにおけるデバイス間(複数)の信号の流れ
(c) K.Miyauchi 22
SCK
MOSI
MISO
SS1
SS2
SS3
SCK
MOSI
MISO
SS
SCK
MOSI
MISO
SS
SCK
MOSI
MISO
SS
マスターは、
スレーブの数だけ
SS端子を用意する
セレクト(マスタと接続
されている線がLow)
されたら、通信開始
SPI
通信の流れのイメージ
1.マスターが通信したいデバイスのSSをLowにする
2.マスターはセットされた8 bitデータをMOSIから
スレーブは,設定されている8 bitデータをMISOから
マスターのシリアルクロックに合わせて送信され,
それぞれが、MOSI、MISOで受信する.
3.マスターが通信の終了を出すために
通信していたデバイスのSSをHighにする
SPIは、 8 bitずつデータを交換するっていうイメージ
(c) K.Miyauchi 23
3つの特徴
3種類のシリアル通信規格等を紹介したが、
以下の表がまとめ的なもの.
(c) K.Miyauchi 24
UART/USART I2C SPI
同期方式 調歩/クロック クロック クロック
伝送形式 全二重伝送 半二重伝送 全二重伝送
データブロック 最大12 bit/最小9 bit 8 bit 8 bit
エラー検出 パリティチェック 無 無
通信速度 ICに依存 ICに依存 ICに依存
通信デバイス数 1 vs 1 複数マスタ vs 複数スレーブ 1 マスタ vs 複数スレーブ
SPIとI2Cについては,
ICによっては両方に対応しているものもある.
レーザ測距センサ(I2C)
I2Cデバイスのレーザ測距センサを使用してみましょう.
プログラムが長いので一部配布.
(c) K.Miyauchi 25
演習
・前にある物体を追従するようなロボットを作成したい.22 cm以上
離れた場合には,DCモータを正転,近づいた場合には,18 cm以内
になった場合には,DCモータを反転させよ.
・測距センサからの取得した値をPCに送信するシステムを作りたい.
PCから”L”を受信したときに,測距センサから物体等までの距離を
送信せよ.
(c) K.Miyauchi 26

More Related Content

Recently uploaded

ネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdf
ネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdfネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdf
ネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdfTakayuki Nakayama
 
2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用
2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用
2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用KLab Inc. / Tech
 
情報を表現するときのポイント
情報を表現するときのポイント情報を表現するときのポイント
情報を表現するときのポイントonozaty
 
Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介
Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介
Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介Hyperleger Tokyo Meetup
 
LoRaWAN無位置ロープ式水漏れセンサーWL03A 日本語マニュアル
LoRaWAN無位置ロープ式水漏れセンサーWL03A 日本語マニュアルLoRaWAN無位置ロープ式水漏れセンサーWL03A 日本語マニュアル
LoRaWAN無位置ロープ式水漏れセンサーWL03A 日本語マニュアルCRI Japan, Inc.
 
LoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイル
LoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイルLoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイル
LoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイルCRI Japan, Inc.
 
Keywordmap overview material/CINC.co.ltd
Keywordmap overview material/CINC.co.ltdKeywordmap overview material/CINC.co.ltd
Keywordmap overview material/CINC.co.ltdkokinagano2
 
MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。
MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。
MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。iPride Co., Ltd.
 

Recently uploaded (8)

ネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdf
ネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdfネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdf
ネットワーク可視化 振る舞い検知(NDR)ご紹介_キンドリル202405.pdf
 
2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用
2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用
2024年5月17日 先駆的科学計算フォーラム2024 機械学習を用いた新たなゲーム体験の創出の応用
 
情報を表現するときのポイント
情報を表現するときのポイント情報を表現するときのポイント
情報を表現するときのポイント
 
Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介
Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介
Hyperledger Fabricコミュニティ活動体験& Hyperledger Fabric最新状況ご紹介
 
LoRaWAN無位置ロープ式水漏れセンサーWL03A 日本語マニュアル
LoRaWAN無位置ロープ式水漏れセンサーWL03A 日本語マニュアルLoRaWAN無位置ロープ式水漏れセンサーWL03A 日本語マニュアル
LoRaWAN無位置ロープ式水漏れセンサーWL03A 日本語マニュアル
 
LoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイル
LoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイルLoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイル
LoRaWAN無位置ロープ型水漏れセンサー WL03A-LB/LSカタログ ファイル
 
Keywordmap overview material/CINC.co.ltd
Keywordmap overview material/CINC.co.ltdKeywordmap overview material/CINC.co.ltd
Keywordmap overview material/CINC.co.ltd
 
MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。
MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。
MPAなWebフレームワーク、Astroの紹介 (その1) 2024/05/17の勉強会で発表されたものです。
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

第5回電子制御講習