当前位置:网站首页>[Development Tutorial 9] crazy shell arm function mobile phone-i2c tutorial
[Development Tutorial 9] crazy shell arm function mobile phone-i2c tutorial
2022-07-26 16:49:00 【efans_ Mike】
ARM Feature phone
—— Crazy shell · Development board series
I2C course

chart 1
Section 1 I2C Hardware circuit
take P12 And P13 Configure to I2C Two interfaces of ,P12 And P13 It has been led out through the row needle , As shown in the figure below :

chart 2
In the second quarter I2C
2.1 I2C Introduce
I2C Bus is a programmable control bus that provides support for circuit communication in the system , It is a software defined two-wire communication protocol .
Two lines I2C The serial interface includes a serial data line (SDA) And a serial clock line (SCL);
Support two communication rates , The standard model (0~100Kb/s) And fast mode ( Less than or equal to 400Kb/s);
Clock synchronization ;
32 Send and receive bytes FIFO;
Host send and receive operations ;
7 or 10 Bit address ,7 or 10 Send for mixed format ;
Block sending mode ;
The default slave address is 0x055;
Interrupt or poll operation mode ;
Programmable data line hold time ;
2.2 Register introduction
I2C There are many related registers , So we only introduce the commonly used registers , For others, please refer to the official data manual AD14580_DS_v3.1.pdf, Located in the directory :..\WT Development board \ Hardware information .
2.2.1 I2C Control register
chart 3
15:7 position : Keep unused ;
6 position :I2C Slave enable bit ,’0’ Indicates that the slave device is enabled ,’1’ Indicates that the slave device is unavailable , This bit does not have to be set by software , But make sure that if this bit is ’0’ Then the... Of this register 0 It's also for ’0’;
5 position : As the main equipment , Whether to send restart condition ,’0’ Indicates no ,’1’ Can be said ;
4 position : As the main equipment , Decide to 7 Bit address or 10 Bit address starts sending ,’0’ Express 7 Bit address ,’1’ Express 10 Bit address ;
3 position : As a slave device , Decide to 7 Bit address or 10 Bit address starts sending ,’0’ Express 7 Bit address ,’1’ Express 10 Bit address ;
2:1 position :I2C Communication speed selection ,1 Indicates standard speed (100Kbit/s),2 Express fast (400Kbit/s);
0 position :I2C Main equipment enable ,’0’ Indicates that the master device is unavailable ,’1’ Indicates that the master device is enabled , Make sure that if this bit is ’1’ Then the... Of this register 6 It's also for ’1’;
2.2.2 I2C Destination address register

chart 4
15:12 position : Keep unused ;
11 position : This bit determines whether the software broadcasts or starts byte commands ,’0’ It means to ignore the second 10 position GC_OR_START And normal use IC_TAR;
10 position : If the first 11 Bit is set to ’1’, Then this bit indicates whether the controller broadcasts or starts byte commands ,’0’ Indicates the sending broadcast address , After that, you can only write , If a read operation is performed, it will result in TX_ABRT Set up , The controller stays in broadcast mode , Until the first 11 Bit is cleared ,’1’ Indicates the sending start byte ;
9:0 position : This is the destination address sent by the master device , If the broadcast is sent, this bit is ignored ,CPU Just write these bits once ; Note that if the destination address is the same as the slave address, there is a loop , however FIFO Master slave sharing , So complete loop is feasible , Only one-way circuits are supported , A master device cannot send data to itself, but only to the slave device .
2.2.3 I2C Receive and send data cache and command register

chart 5
15:9 position : Keep unused ;
8 position : Read write control bit , As a slave device, you cannot control the direction , It can only be used as the main equipment ,’0’ Said to write ,’1’ Express reading ;
7:0 position : Storage I2C Data sent or received on the bus , If you are operating the register and want to read, this bit is ignored , If you read this register, this bit stores the received data .
2.2.4 I2C eliminate TX_ABRT interrupt
chart 6
15:1 position : Keep unused ;
0 position : Clear the sending abnormal stop bit , Read this bit to clear the transmission abnormal stop interrupt , And send exception stop source register bit . Send... At the same time FIFO Refresh from / Released in the reset state , More writes can be allowed .
2.2.5 I2C Enable register

chart 7
15:1 position : Keep unused ;
0 position : Controller enable bit ;
2.2.6 I2C Status register

chart 8
15:7 position : Keep unused ;
6 position : Judge whether the slave device is active ;
5 position : Determine whether the main equipment is active ;
4 position : Judging reception FIFO Whether it is full ;
3 position : Judging reception FIFO Is it empty ;
2 position : Judge the transmission FIFO Whether it is full ;
1 position : Judge the transmission FIFO Is it empty ;
0 position : Judge I2C Whether the module is active .
2.2.7 I2C receive FIFO Number register
chart 9
15:6 position : Keep unused ;
5:0 position : receive FIFO How many bytes can be received .
2.2.8 I2C Send abnormal termination source register

chart 10
15 position : When the master device needs to send data , But enter the state of reading data ;
14 position : When sending data , The slave device loses the bus ;
13 position : When the slave device wants to receive data ,FIFO There are already some data in ;
12 position : Loss of arbitration ;
11 position : When the main equipment is unavailable , The user operates the main equipment ;
10 position : Restart unavailable , And the main equipment is 10 Send read command in bit address mode ;
9 position : Restart unavailable , But the user sends a start byte ;
8 position : Restart unavailable , But the user tried to send data in high-speed mode ;
7 position : The master device has sent a start byte , And the start byte is confirmed ;
6 position : The main device is in high-speed mode , And confirmed ;
5 position : Read after the master device controller broadcasts ;
4 position : The master device sends a broadcast , But it was not confirmed from the device ;
3 position : Only the main equipment is valid , The master device has sent the address , And confirm , But no confirmation signal can be obtained when sending data ;
2 position : Use of main equipment 10 Bit address mode ,10 The second byte of the bit address is not acknowledged by any slave device ;
1 position : Use of main equipment 10 Bit address mode ,10 The first byte of the bit address is not acknowledged by any slave device ;
0 position : Use of main equipment 7 Bit address mode , But it was not confirmed by any slave device .
2.3 Explanation of register configuration
#define CLK_PER_REG (* ( volatile uint16*)0x50000004)
#define I2C_CON_REG (* ( volatile uint16*)0x50001300)
#define I2C_TAR_REG (* ( volatile uint16*)0x50001304)
#define I2C_DATA_CMD_REG (* ( volatile uint16*)0x50001310)
#define I2C_CLR_TX_ABRT_REG (* ( volatile uint16*)0x50001354)
#define I2C_ENABLE_REG (* ( volatile uint16*)0x5000136C)
#define I2C_STATUS_REG (* ( volatile uint16*)0x50001370)
#define I2C_RXFLR_REG (* ( volatile uint16*)0x50001378)
#define I2C_TX_ABRT_SOURCE_REG (* ( volatile uint16*)0x50001380)
start-up I2C Module clock :CLK_PER_REG |= 0x0020;
I2C Initialization register configuration of :
Shut down first I2C controller , I2C_ENABLE_REG=0x00;
Set to main mode , Turn off slave mode , You can start again , The speed is set to fast , The address is 7 Bit mode (0x0000000001100101), I2C_ CON _REG =0x0065;
Set the target device address to 0x51, I2C_TAR_REG =0x51;
open I2C controller , I2C_ENABLE_REG=0x01;
Wait for the controller to be ready ,while( (I2C_STATUS_REG & 0x20) != 0 );
The read address is 0x98 One byte at , Send the address first I2C_DATA_CMD_REG = 0x98; Wait for the transmission to finish while((I2C_STATUS_REG&0x0002)==0); Send read instructions I2C_DATA_CMD_REG = 0x0100; Wait for the transmission to finish while((I2C_STATUS_REG&0x0004)==0); Then wait for the data to be received while(I2C_RXFLR_REG == 0); Reading the data in the receive buffer is the receive data rx_data = I2C_DATA_CMD_REG;
To the address of 0x98 Write a byte at 0xaa, Send the address first I2C_DATA_CMD_REG = 0x98; Wait for the transmission to finish while((I2C_STATUS_REG&0x0002)==0); send data I2C_DATA_CMD_REG = 0xaa; Wait for the transmission to finish while((I2C_STATUS_REG&0x0004)==0);
In the third quarter I2C experiment
The modules used in the experiment are : Bottom plate of mobile phone development board ,Jlink Debugging tools , DuPont line 、 Heart rate and body temperature module 、3.7V Lithium battery or Mocro USB Line .
Connect the heart rate and body temperature module to the main control base plate through DuPont line , The connection is as follows :
(1) One end of the heart rate and body temperature module needs to use DuPont cable to connect the heart rate and body temperature module 3V3、GND、SCL、SDA Four pins , As shown in the figure below :
chart 11
(2) One end of the main control board of the mobile phone needs to be connected with DuPont cable J4 Of 2 Pins and J10 The two pins of the heart rate and body temperature module correspond one by one , As shown in the figure below

chart 12
Use JLINK Connect the mobile phone through DuPont line. Bluetooth is located on the main control backplane of the mobile phone , The connection is as follows :
(1)JLINK One end only needs to be connected with DuPont wire JLINK Of SWC、SWD、GND Three pins , As shown in the figure below :
chart 13
(2) The Bluetooth end of the mobile phone needs to use DuPont cable to connect the upper right J3 Three pins , And JLINK The connecting pins of the correspond one by one , Respectively SWC-->SWCLK、SWD-->SWDIO、GND-->GND, As shown in the figure below :
chart 14
take JLINK Plug in the computer USB Interface , After connecting, power the main control board of the mobile phone , For detailed introduction, please refer to 《 How to power on 》 course , Path is :..\WT_Mobile\0. So let's start here \0. Power on test .
open I2C Experimental Keil engineering i2c_eeprom.uvproj, Located in the directory :
..\WT_Mobile\1. Junior course \DA14580\5_ primary _I2C\projects\target_apps\peripheral_examples\i2c\i2c_eeprom\Keil_5, As shown in the figure below :
chart 15
stay KEIL Compile source code , Click on DEBUG, Then click Run at full speed , Place a breakpoint under the variable that stores the temperature data , When the program reaches the breakpoint, it will stop . Add this variable to the variable view window , You can see the temperature value , As shown in the figure below :



chart 16
More complete learning materials and corresponding open source Suites , Please visit the official website :“ Crazy shell ”
For customized development , Please use the official website “ Crazy shell ” At the bottom of the page “ Contact us ” Make contact
边栏推荐
- 正则表达式
- 量化交易之数字货币篇 - 通过时间戳与方向来合并逐笔成交数据(大单合并)
- Configmap of kubernetes
- What is the complexity often said during the interview?
- 工作流引擎在vivo营销自动化中的应用实践
- Why is digital transformation so difficult?!
- Sharing of 40 completed projects of high-quality information management specialty [source code + Thesis] (VI)
- [untitled]
- The process and harvest of developing browser plug-ins with clojurescript
- 面试时候常说的复杂度到底是什么?
猜你喜欢

Re8: reading papers Hier spcnet: a legal stat hierarchy based heterogeneous network for computing legal case

Application of workflow engine in vivo marketing automation

Win11怎么自动清理回收站?

Re7: reading papers fla/mlac learning to predict charges for critical cases with legal basis

PyQt5快速开发与实战 3.2 布局管理入门 and 3.3 Qt Designer实战应用

Definition and relationship of derivative, differential, partial derivative, total derivative, directional derivative and gradient

A preliminary understanding of MVC and ECS design architectures

Thinkphp历史漏洞复现

What is a distributed timed task framework?

Linux安装mysql8.0.29详细教程
随机推荐
Comprehensively design an oppe homepage -- layout and initialization
Vs2017 opens the project and prompts the solution of migration
Probe of kubernetes
kubernetes之探针
Docker install redis? How to configure persistence policy?
Response object - response character data
Video media video
Threads and processes
NUC 11构建 ESXi 7.0.3f安装网卡驱动-V2(2022年7月升级版)
京东三面:我要查询千万级数据量的表,怎么操作?
What is the complexity often said during the interview?
广州市安委办发布高温天气安全防范警示提醒
DTS搭载全新自研内核,突破两地三中心架构的关键技术|腾讯云数据库
抓包与发流软件与网络诊断
Use verdaccio to build your own NPM private library
利用MySQL主从复制延迟拯救误删数据
Application of workflow engine in vivo marketing automation
6种方法帮你搞定SimpleDateFormat类不是线程安全的问题
数字化转型怎么就那么的难?!
Vlang's way of beating drums