SlideShare a Scribd company logo
Linux Driver for STMicro LIS3DH
演講:秦O航
Outline
Linux Kernel Driver 實作
G-sensor 應用及原理
G-sensor 電路實作
i2c protocol
Demo實作
前言
實現在既有的嵌入式系統中,靈活的添加
新的裝置,則可提高產品的可利用性、多
元性、及客製化的概念嘗試加速效能。
所以在這個專題中著手製作,模組化的驅
動程式,則可以實現這樣的概念。
Gsensor應用:
硬碟、CD隨身聽、安全氣囊、
遊戲、wii、GPS航位推算等。
About STMicro LIS3DH
G-Sensor
I2C
Linux I2C Framework
Slave
LIS3DH
Master
Raspberry
Circuit
Pi  LIS3DH
Pi
I2C interface
SDA
SCL
Procedure for Linux Driver for LIS3DH
LIS3DH
I2C Driver
Character Driver
/dev/lis3dh
cat /dev/lis3dh
gsensor@19{
compatible = "lis3dh";
reg = <0x19>;
};
Device Tree
User Application
lis3dh.ko
lis3dh.dtbo1
2
3
Add I2C Driver
struct I2c_driver lis3dh_driver
Probe
lis3dh_init
register char
remove
unregister char
del_i2c_driver
module_i2c_driver (lis3dh_driver)
Describe a node in Device Tree
/boot/overlays/ lis3dh.dtbo
DT
compiler
Lis3dh.dts
gsensor@19{
compatible = "lis3dh";
reg = <0x19>;
};
Device Tree
Character Driver
Struct File_Operator
read()
write()
Ioctl()
open
release()
cat /dev/lis3dh
Code Snippet for Read:
//X_L (28h)
g_sensor[0]=i2c_smbus_read_byte_data
(client,0x28);
//X_H(29h)
g_sensor[1]=i2c_smbus_read_byte_data
(client, 0x29);
x = (short) (g_sensor[0] | (((unsigned
short)g_sensor[1]) << 8));
i2c Operation
讀寫
1) Write: 需要1個I2C Message
2) Read: 需要2個I2C Message (會有2個START)
資料長度
1) Byte (8 bit)
2) Word (16 bit)
3) Block (multi-byte , at most 32 bytes)
I2c Message Format
Read/Write Example
addr flags
I2C Read example (2個 i2c_msg)
I2C Write example (1個 i2c_msg)
每一次的START就要包裝成一個i2c message, 然後用i2c_transfer()去送,
i2c_transfer()送完後就是STOP狀態
Linux I2C Client API
//Write送出2個byte: <SA+’flag’> <value>
s32 i2c_smbus_write_byte (const struct i2c_client *client, u8 value)
s32 i2c_smbus_read_byte (const struct i2c_client *client)
//Write送出3個byte: <SA+’flag’> <cmd> <value>
s32 i2c_smbus_write_byte_data(const struct i2c_client *client, u8 command,u8 value)
s32 i2c_smbus_read_byte_data(const struct i2c_client *client, u8 command)
//Write送出4個byte: <SA+’flag’> <cmd> <value> <value>
s32 i2c_smbus_write_word_data (const struct i2c_client *client, u8 command,u16 value)
s32 i2c_smbus_read_word_data (const struct i2c_client *client, u8 command)
//Write送出n個byte: <SA+’flag’> <cmd> <value> <value> …….<value>
s32 i2c_smbus_write_block_data (const struct i2c_client *client, u8 command, u8 length, const u8 *values)
s32 i2c_smbus_read_block_data (const struct i2c_client *client, u8 command,u8 length, u8 *values)
i2c_smbus_xfer_emulated()
LIS3DH
Slave Address 0x19
16
Protocol for LIS3DH
An 8-bit sub-address (SUB) is transmitted: the 7
LSB represent the actual register address while
the MSB enables address auto increment.
If the MSB of the SUB field is ‘1’, the SUB (register
address) is automatically increased to allow
multiple data read/writes.
17
Protocol for LIS3DH
18
MAK is Master acknowledge and NMAK is No Master Acknowledge
SUB address
Demo
insmod LIS3DH_Linux_Drv_0626.ko
方位
X>0
朝正面 Z>0
Y>0
Demo
References
LinuxDeviceDriver Programming驅動程式設計 博碩文化出版
解析Linux驅動程式設計MMC/SD、USB、
I2C、PCI網路及輸入裝置等 博碩文化出版
ITTRAINING輸出入裝置與驅動程式設計 艾鍗學院出版
王者歸來Linux驅動程式開發權威指南 佳魁出版

More Related Content

PDF
Magnum IO GPUDirect Storage 最新情報
PDF
Hopper アーキテクチャで、変わること、変わらないこと
PDF
CUDAのアセンブリ言語基礎のまとめ PTXとSASSの概説
PPT
實作 Linux Driver 移植在樹莓 Pi 上:Linux One wire sensor & I2C framebuffer Driver Po...
PDF
第9回ACRiウェビナー_セック/岩渕様ご講演資料
PDF
Max-Sliced Wasserstein Distance and its use for GANs
PPTX
モデル高速化百選
PDF
CXL_説明_公開用.pdf
Magnum IO GPUDirect Storage 最新情報
Hopper アーキテクチャで、変わること、変わらないこと
CUDAのアセンブリ言語基礎のまとめ PTXとSASSの概説
實作 Linux Driver 移植在樹莓 Pi 上:Linux One wire sensor & I2C framebuffer Driver Po...
第9回ACRiウェビナー_セック/岩渕様ご講演資料
Max-Sliced Wasserstein Distance and its use for GANs
モデル高速化百選
CXL_説明_公開用.pdf

What's hot (20)

PPTX
RustによるGPUプログラミング環境
PDF
2015年度先端GPGPUシミュレーション工学特論 第5回 GPUのメモリ階層の詳細 (様々なメモリの利用)
PPTX
CPU / GPU高速化セミナー!性能モデルの理論と実践:理論編
PPTX
移植FreeRTOS 之嵌入式軟體研究與開發
PDF
データ爆発時代のネットワークインフラ
PDF
NEDIA_SNIA_CXL_講演資料.pdf
PDF
CPU / GPU高速化セミナー!性能モデルの理論と実践:実践編
PDF
モバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組み
PDF
HistoPyramid Stream Compaction
PDF
Dockerだけではないコンテナのはなし
PDF
2015年度GPGPU実践基礎工学 第10回 GPUのプログラム構造
PDF
Tensorflow Liteの量子化アーキテクチャ
PDF
シスコ装置を使い倒す!組込み機能による可視化からセキュリティ強化
PDF
GPGPU Seminar (GPGPU and CUDA Fortran)
PDF
Gpu vs fpga
PDF
「ゼロから作るDeep learning」の畳み込みニューラルネットワークのハードウェア化
PDF
Making Cassandra more capable, faster, and more reliable (at ApacheCon@Home 2...
PDF
2値化CNN on FPGAでGPUとガチンコバトル(公開版)
PDF
1072: アプリケーション開発を加速するCUDAライブラリ
PDF
[KubeCon NA 2020] containerd: Rootless Containers 2020
RustによるGPUプログラミング環境
2015年度先端GPGPUシミュレーション工学特論 第5回 GPUのメモリ階層の詳細 (様々なメモリの利用)
CPU / GPU高速化セミナー!性能モデルの理論と実践:理論編
移植FreeRTOS 之嵌入式軟體研究與開發
データ爆発時代のネットワークインフラ
NEDIA_SNIA_CXL_講演資料.pdf
CPU / GPU高速化セミナー!性能モデルの理論と実践:実践編
モバイルゲームの「大規模な開発」かつ「高頻度の更新」を実現するための開発環境整備の取り組み
HistoPyramid Stream Compaction
Dockerだけではないコンテナのはなし
2015年度GPGPU実践基礎工学 第10回 GPUのプログラム構造
Tensorflow Liteの量子化アーキテクチャ
シスコ装置を使い倒す!組込み機能による可視化からセキュリティ強化
GPGPU Seminar (GPGPU and CUDA Fortran)
Gpu vs fpga
「ゼロから作るDeep learning」の畳み込みニューラルネットワークのハードウェア化
Making Cassandra more capable, faster, and more reliable (at ApacheCon@Home 2...
2値化CNN on FPGAでGPUとガチンコバトル(公開版)
1072: アプリケーション開発を加速するCUDAライブラリ
[KubeCon NA 2020] containerd: Rootless Containers 2020
Ad

Similar to 實作Linux Driver移植在樹莓 Pi上:Linux Driver for STMicro LIS3DH (20)

PDF
PPTX
Why a zynq should power your next project
PDF
Linxu conj2016 96boards
PDF
Perceptual Computing Workshop à Paris
PDF
DRIVE PX 2
PDF
PDF
Perceptual Computing Workshop in Munich
PDF
Bits & Pixels using AI for Good.........
PDF
Webinar: NVIDIA JETSON – A Inteligência Artificial na palma de sua mão
PPTX
HiPEAC 2022_Marco Tassemeier presentation
PDF
AI, A New Computing Model
PDF
車載組み込み用ディープラーニング・エンジン NVIDIA DRIVE PX
PPTX
pcDuino tech talk at Carnegie Mellon University 10/14/2014
PDF
GTC 2018 で発表された自動運転最新情報
PDF
Introduction to Kinect v2
PDF
Anand_Agrawal_CV.pdf
PDF
Introduction to RIoT Hardware Kits & ESP32 Programming [Road to RIoT 2017]
PDF
Build a Deep Learning Video Analytics Framework | SIGGRAPH 2019 Technical Ses...
PDF
HKG18-301 - Dramatically Accelerate 96Board Software via an FPGA with Integra...
PDF
International Journal of Computational Engineering Research(IJCER)
Why a zynq should power your next project
Linxu conj2016 96boards
Perceptual Computing Workshop à Paris
DRIVE PX 2
Perceptual Computing Workshop in Munich
Bits & Pixels using AI for Good.........
Webinar: NVIDIA JETSON – A Inteligência Artificial na palma de sua mão
HiPEAC 2022_Marco Tassemeier presentation
AI, A New Computing Model
車載組み込み用ディープラーニング・エンジン NVIDIA DRIVE PX
pcDuino tech talk at Carnegie Mellon University 10/14/2014
GTC 2018 で発表された自動運転最新情報
Introduction to Kinect v2
Anand_Agrawal_CV.pdf
Introduction to RIoT Hardware Kits & ESP32 Programming [Road to RIoT 2017]
Build a Deep Learning Video Analytics Framework | SIGGRAPH 2019 Technical Ses...
HKG18-301 - Dramatically Accelerate 96Board Software via an FPGA with Integra...
International Journal of Computational Engineering Research(IJCER)
Ad

More from IttrainingIttraining (20)

PPTX
AI 認得你,也認得照片的重複 - 智慧型圖片管理系統:結合人臉辨識與重複圖片偵測技術【艾鍗學院學員專題 】
PPTX
AI 個人造型顧問:結合 Stable Diffusion 與 CLIP 的 AI 虛擬穿搭推薦系統設計【艾鍗學院學員專題 】
PPTX
「熊出沒注意!」:結合 YOLOv8 的台灣黑熊即時預警系統設計【艾鍗學院學員專題 】
PPTX
BentoCal:食物熱量健康管理系統 - 結合 YOLOv8 的便當影像辨識與熱量推估系統【艾鍗學院學員專題 】
PPTX
AI 飆股預測:你的智慧投資夥伴-基於技術分析與基本面的 AI 股價預測系統【艾鍗學院學員專題 】
PPTX
Character Generation Master 角色生成大師【艾鍗學院】
PPTX
吉伊卡哇臉盲辨識器 - 艾鍗學院學員專題 [AI人工智慧與邊緣運算工程師班]
PPTX
AI 語音複製 X 翻譯 - 艾鍗學院學員專題 [AI人工智慧與邊緣運算工程師班]
PPTX
以人工智能打造企業內部知識管理系統以PCB板為例 - 艾鍗學院學員專題 [AI人工智慧與邊緣運算工程師班]
PPTX
Scratch遊戲設計 教學培訓課程Scratch Game【台灣程式教育協進會】
PPTX
Scratch AI應用與遊戲開發 教學培訓課程【台灣程式教育協進會】
PPTX
APCS程式設計 - C++程式語言觀念 (大學程式設計先修檢測)
PPTX
艾鍗學院課程節錄 - 自然語言處理與大型語言模型(NLP,LLM,Transformer)
PPTX
艾鍗學院學員AI專題 - 飛向Kaggle宇宙🚀🚀-系外行星之光譜與物質濃度分析
PDF
艾鍗學院學員AI專題 - 類流感預測
PPTX
艾鍗學院學員AI專題 - AI 熱量管理師
PPTX
艾鍗學院學員AI專題 - Kaggle貸款風險預測模型開發
PPTX
艾鍗學院學員AI專題 - 串流平台Netflix 熱門電影與節目特徵分析及排行上榜預測平台
PPT
C++程式設計Basic
PPTX
第五組_速速單字書 Quickly Collect Words
AI 認得你,也認得照片的重複 - 智慧型圖片管理系統:結合人臉辨識與重複圖片偵測技術【艾鍗學院學員專題 】
AI 個人造型顧問:結合 Stable Diffusion 與 CLIP 的 AI 虛擬穿搭推薦系統設計【艾鍗學院學員專題 】
「熊出沒注意!」:結合 YOLOv8 的台灣黑熊即時預警系統設計【艾鍗學院學員專題 】
BentoCal:食物熱量健康管理系統 - 結合 YOLOv8 的便當影像辨識與熱量推估系統【艾鍗學院學員專題 】
AI 飆股預測:你的智慧投資夥伴-基於技術分析與基本面的 AI 股價預測系統【艾鍗學院學員專題 】
Character Generation Master 角色生成大師【艾鍗學院】
吉伊卡哇臉盲辨識器 - 艾鍗學院學員專題 [AI人工智慧與邊緣運算工程師班]
AI 語音複製 X 翻譯 - 艾鍗學院學員專題 [AI人工智慧與邊緣運算工程師班]
以人工智能打造企業內部知識管理系統以PCB板為例 - 艾鍗學院學員專題 [AI人工智慧與邊緣運算工程師班]
Scratch遊戲設計 教學培訓課程Scratch Game【台灣程式教育協進會】
Scratch AI應用與遊戲開發 教學培訓課程【台灣程式教育協進會】
APCS程式設計 - C++程式語言觀念 (大學程式設計先修檢測)
艾鍗學院課程節錄 - 自然語言處理與大型語言模型(NLP,LLM,Transformer)
艾鍗學院學員AI專題 - 飛向Kaggle宇宙🚀🚀-系外行星之光譜與物質濃度分析
艾鍗學院學員AI專題 - 類流感預測
艾鍗學院學員AI專題 - AI 熱量管理師
艾鍗學院學員AI專題 - Kaggle貸款風險預測模型開發
艾鍗學院學員AI專題 - 串流平台Netflix 熱門電影與節目特徵分析及排行上榜預測平台
C++程式設計Basic
第五組_速速單字書 Quickly Collect Words

Recently uploaded (20)

PPTX
OOP with Java - Java Introduction (Basics)
PPTX
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
PPTX
Sustainable Sites - Green Building Construction
PPTX
CYBER-CRIMES AND SECURITY A guide to understanding
PPTX
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
PPTX
Lecture Notes Electrical Wiring System Components
PDF
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
DOCX
573137875-Attendance-Management-System-original
PPTX
Internet of Things (IOT) - A guide to understanding
PDF
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
PPTX
CH1 Production IntroductoryConcepts.pptx
PDF
composite construction of structures.pdf
PPTX
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
PDF
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
PPTX
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
PPTX
Foundation to blockchain - A guide to Blockchain Tech
PDF
PPT on Performance Review to get promotions
PPTX
Geodesy 1.pptx...............................................
PDF
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
PDF
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT
OOP with Java - Java Introduction (Basics)
Engineering Ethics, Safety and Environment [Autosaved] (1).pptx
Sustainable Sites - Green Building Construction
CYBER-CRIMES AND SECURITY A guide to understanding
KTU 2019 -S7-MCN 401 MODULE 2-VINAY.pptx
Lecture Notes Electrical Wiring System Components
Mitigating Risks through Effective Management for Enhancing Organizational Pe...
573137875-Attendance-Management-System-original
Internet of Things (IOT) - A guide to understanding
The CXO Playbook 2025 – Future-Ready Strategies for C-Suite Leaders Cerebrai...
CH1 Production IntroductoryConcepts.pptx
composite construction of structures.pdf
Recipes for Real Time Voice AI WebRTC, SLMs and Open Source Software.pptx
BMEC211 - INTRODUCTION TO MECHATRONICS-1.pdf
CARTOGRAPHY AND GEOINFORMATION VISUALIZATION chapter1 NPTE (2).pptx
Foundation to blockchain - A guide to Blockchain Tech
PPT on Performance Review to get promotions
Geodesy 1.pptx...............................................
Mohammad Mahdi Farshadian CV - Prospective PhD Student 2026
SM_6th-Sem__Cse_Internet-of-Things.pdf IOT

實作Linux Driver移植在樹莓 Pi上:Linux Driver for STMicro LIS3DH