Page 1
1 /**
2 ******************************************************************************
3 * File Name : I2C.c
4 * Description : This file provides code for the configuration
5 * of the I2C instances.
6 * Auther : Dhg
7 * Date : 2017-11-26
8
9 * Note :
本程序可实现
TSM12M
12
通道触摸芯片的驱动,网上类似可用资源非常之少;
10
自己通过多次试验才写好驱动,实测可用,特此分享给大家;
11
希望可以帮助大家少走弯路
!
12 ******************************************************************************
13
14
15 /* Includes ------------------------------------------------------------------*/
16 #include "i2c.h"
17
18 #include "gpio.h"
19
20 /* USER CODE BEGIN 0 */
21 #define CH_SENS(a,b) 0x##a##b
22
23 /* TSM12M Register Map */
24 typedef enum
25 {
26 SENS1 = 0x02, //Sensitivity, Channel 2 and 1
27 SENS2 = 0x03, //Channel 4 and 3
28 SENS3 = 0x04, //Channel 6 and 5
29 SENS4 = 0x05, //Channel 8 and 7
30 SENS5 = 0x06, //Channel 10 and 9
31 SENS6 = 0x07, //Channel 12 and 11
32 CTRL1 = 0x08,
33 CTRL2 = 0x09,
34 REF_RST1 = 0x0A,
35 REF_RST2 = 0x0B,
36 CH_HOLD1 = 0x0C,
37 CH_HOLD2 = 0x0D,
38 CAL_HOLD1 = 0x0E,
39 CAL_HOLD2 = 0x0F,
40 OUTPUT1 = 0x10,
41 OUTPUT2 = 0x11,
42 OUTPUT3 = 0x12,
43
44 }TSM_RegMapAddr_TypeDef;
45
46 /* USER CODE END 0 */
47
48 I2C_HandleTypeDef hi2c1;
49
50 /* I2C1 init function */
51 void MX_I2C1_Init(void)
52 {
53
54 hi2c1.Instance = I2C1;
55 hi2c1.Init.Timing = 0x2000090E;
56 hi2c1.Init.OwnAddress1 = 0;
57 hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
58 hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
59 hi2c1.Init.OwnAddress2 = 0;
60 hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
评论9
最新资源