| **银杏科技有限公司旗下技术文档发布平台** |||| |技术支持电话|**0379-69926675-801**||| |技术支持邮件|Gingko@vip.163.com||| ^ 版本 ^ 日期 ^ 作者 ^ 修改内容 ^ | V1.0 | 2020-03-04 | zh. | 初次建立 | ===== iCore4T_RTT_7_I2C挂载LM75A设备 ===== * iCore4T ARM+FPGA双核心板I2C总线挂有三个设备,分别为AXP152电源管理芯片,LM75A温度传感器,EEPROM存储器,在上一个例程中给大家分享了I2C总线驱动的添加过程,今天直接给大家分享LM75A的挂载过程。 * LM75A 是一个使用了内置带隙温度传感器和Σ-△模数转换技术的温度-数字转换器,可用于iCore4T核心板温度监控,如果温度过高可以输出报警信息。 ==== 1、修改kconfig文件,在menuconfig中添加配置LM75A的选项 ==== {{ :icore4t:iCore4T_RTT_7_1.png?direct |}} ==== 2、添加lm75a驱动程序,并将该文件放在../bsp/stm32/libraries/HAL_Drivers,我把源码贴在下面 ==== /* * Copyright (c) 2006-2018, RT-Thread Development Team * * SPDX-License-Identifier: Apache-2.0 * * Change Logs: * Date Author Notes * 2020-02-17 zh. first version */ #include #include #include #include #include #ifdef BSP_USING_I2C_LM75A #define LM75A_ADDR (0x90 >> 1) /* For lm75a i2c bus*/ #define LM75A_I2CBUS_NAME "i2c1" static struct rt_i2c_bus_device *lm75a_i2c_bus = RT_NULL; static rt_err_t i2c_read_nbyte(rt_uint8_t slave_addr, rt_uint8_t cmd, rt_uint8_t *buf, rt_uint32_t len) { rt_i2c_master_send(lm75a_i2c_bus, slave_addr, RT_I2C_WR, &cmd, 1); rt_i2c_master_recv(lm75a_i2c_bus, slave_addr, RT_I2C_RD, buf, len); return RT_EOK; } float lm75a_read(void) { union { unsigned char buf[2]; short int value; }temp; float f; unsigned char c; lm75a_i2c_bus = rt_i2c_bus_device_find(LM75A_I2CBUS_NAME); if(lm75a_i2c_bus == RT_NULL) { rt_kprintf("i2c_bus %s for lm75a not found!\n", lm75a_i2c_bus); return -RT_ERROR; } i2c_read_nbyte(LM75A_ADDR,0,temp.buf,2); c = temp.buf[0]; temp.buf[0] = temp.buf[1]; temp.buf[1] = c; f = temp.value; f /= (float)32.0; f *= (float)0.125; return f; } static int lm75a(int argc, char **argv) { float tempture; int temp; tempture = lm75a_read(); temp = tempture * 100; rt_kprintf("The current temperature is: %d.%02d°\n",temp/100,temp%100); return RT_EOK; } MSH_CMD_EXPORT(lm75a, show current temperature); #endif /* BSP_USING_I2C_LM75A */ ==== 3、添加文件路径,这样生成工程的时候可以自动将该文件加入MDK工程 ==== {{ :icore4t:iCore4T_RTT_7_2.png?direct |}} ==== 4、打开menuconfig,配置LM75A ==== {{ :icore4t:iCore4T_RTT_7_3.png?direct |}} ==== 5、使用scons命令生成MDK5工程,编译,烧录,就可以获取温度信息了 ==== {{ :icore4t:iCore4T_RTT_7_4.png?direct |}} 至此,我们成功的挂载了LM75A设备。       ==== 6、源代码 ==== 源代码可以移步这里下载: 链接:https://pan.baidu.com/s/1fcLU4WaRDlgr0mNYwZj1Yg 提取码:zstq