目前现有的max30205的驱动代码大多是基于Android单片机的,之前用了一个模块,看了一下数据手册,通信用的是IIC通信,读写数据地址都按照数据手册中来就行,和我用过的其他IIC通信的传感器相比,这个传感器的温度数据寄存器是十六位的,而我们一般用的读取代码历程都是一个字节,然后地址位依向后加一,这个模块在读完高八位时需要主机发送一个应答信号,然后继续读取低八位下面附有时序图和源代码:
30205.c:
- #include "30205.h"
- #include "delay.h"
- //float temperature=0;
- void max_init (void)
- {
- IIC_Init();
- I2CwriteByte(MAX30205_ADDRESS, MAX30205_CONFIGURATION, 0x00);
- //I2CwriteByte(MAX30205_ADDRESS, MAX30205_THYST , 0x00);
- // I2CwriteByte(MAX30205_ADDRESS, MAX30205_TOS, 0x00);
- }
- //写入指定地址一个字节数据
- void I2CwriteByte(u8 address,u8 subAddress,u8 data) //
- {
- //IIC_Start(); //产生开始信号
- I2Cwriteaddr(address|IIC_WRITE,subAddress); //对器件地址写入命令信号 然后寄存器地址
- IIC_Send_Byte(data); //对数据进行写进去
- IIC_Wait_Ack(); //等待回应
- IIC_Stop(); //产生停止信号
- }
- //I2C读一个字节操作
- u8 I2CreadByte(u8 address,u8 subAddress)
- {
- u8 data;
- // IIC_Start(); //开始
- I2Cwriteaddr(address|IIC_WRITE, subAddress); //对器件地址发送写入命令 写入寄存器地址
- IIC_Start(); //开始
- IIC_Send_Byte(address|IIC_READ); //发送读取命令
-
- IIC_Wait_Ack(); //等待回应
- data=IIC_Read_Byte(0);
- IIC_Stop(); //产生停止信号
- return data;
- }
- void I2CreadBytes(u8 address,u8 subAddress,u8*dest,u8 count)
- {
- int i;
- for(i=0;i<count;i++)
- {
- dest[ i]=I2CreadByte(address,subAddress);
- subAddress+=1;
- }
- }
- void I2Cwriteaddr(u8 address,u8 subAddress)//写地址和寄存器操作
- {
- IIC_Start(); //产生开始条件
- IIC_Send_Byte(address); //写入器件地址
- IIC_Wait_Ack(); //等待回应
- IIC_Send_Byte(subAddress); //写入寄存器地址
- IIC_Wait_Ack(); //等待回应
- //IIC_Stop(); //产生停止信号
- }
- int16_t Read_max16(u8 address,u8 subAddress)
- {
- int16_t data;
- u8 instant;
- // IIC_Start(); //开始
- I2Cwriteaddr(address|IIC_WRITE, subAddress); //对器件地址发送写入命令 写入寄存器地址
- IIC_Start(); //开始
- IIC_Send_Byte(address|IIC_READ); //发送读取命令
-
- IIC_Wait_Ack(); //等待回应
- data=IIC_Read_Byte(1);//主机发送应答信号
- //IIC_Wait_Ack();
- instant = IIC_Read_Byte(0);//主机发送非应答信号
- IIC_Stop(); //产生停止信号
- data = (data<<8)|instant;
- return data;
- }
- double GetTemperature(void)
- {
- double temperature= 0.0;
- int16_t temp;
- temp = Read_max16(MAX30205_ADDRESS,MAX30205_TEMPERATURE);
- temperature = temp*0.00390625;
- return temperature;
- }
复制代码
30205.h
- #ifndef __30205_H
- #define __30205_H
- #include "sys.h"
- #include "IIC.h"
- #define MAX30205_ADDRESS 0X90 //8bit address converted to 7bit
- //一些寄存器地址
- #define MAX30205_TEMPERATURE 0X00
- #define MAX30205_CONFIGURATION 0X01
- #define MAX30205_THYST 0X02
- #define MAX30205_TOS 0X03
- #define IIC_WRITE 0 //数据方向 写入
- #define IIC_READ 1 //数据方向 读取
- //extern float temperature;
- void shutdown(void);
- void max_init (void);
- void I2CwriteByte(u8 address,u8 subAddress,u8 data);
- void I2Cwriteaddr(u8 address,u8 subAddress);
- u8 I2CreadByte(u8 address,u8 subAddress);
- void I2CreadBytes(u8 address,u8 subAddress,u8*dest,u8 count);
- int16_t Read_max16(u8 address,u8 subAddress);
- double GetTemperature(void);
- #endif
复制代码
IIC用的是模拟IIC,用的是原子哥的IIC底层
下面是工程代码附件
stm32体温Max30205程序.zip
(328.67 KB, 售价: 10 E币)
# stm32体温Max30205程序.zip
清除临时文件.bat
CORE
CORE\core_cm3.c
CORE\core_cm3.h
CORE\startup_stm32f10x_md.s
HARDWARE
HARDWARE\IIC
HARDWARE\IIC\IIC.c
HARDWARE\IIC\IIC.h
HARDWARE\IIC\sht31.c
HARDWARE\IIC\sht31.h
HARDWARE\led
HARDWARE\led\led.c
HARDWARE\led\led.h
HARDWARE\max30205
HARDWARE\max30205\30205.c
HARDWARE\max30205\30205.h
HARDWARE\oled
HARDWARE\oled\oled.c
HARDWARE\oled\oled.h
HARDWARE\timer
HARDWARE\timer\timer.c
HARDWARE\timer\timer.h
OBJ
OBJ\Bliz.hex
STM32F10x_FWLib
STM32F10x_FWLib\inc
STM32F10x_FWLib\inc\misc.h
STM32F10x_FWLib\inc\stm32f10x_adc.h
STM32F10x_FWLib\inc\stm32f10x_bkp.h
STM32F10x_FWLib\inc\stm32f10x_can.h
STM32F10x_FWLib\inc\stm32f10x_cec.h
STM32F10x_FWLib\inc\stm32f10x_crc.h
STM32F10x_FWLib\inc\stm32f10x_dac.h
STM32F10x_FWLib\inc\stm32f10x_dbgmcu.h
STM32F10x_FWLib\inc\stm32f10x_dma.h
STM32F10x_FWLib\inc\stm32f10x_exti.h
STM32F10x_FWLib\inc\stm32f10x_flash.h
STM32F10x_FWLib\inc\stm32f10x_fsmc.h
STM32F10x_FWLib\inc\stm32f10x_gpio.h
STM32F10x_FWLib\inc\stm32f10x_i2c.h
STM32F10x_FWLib\inc\stm32f10x_iwdg.h
STM32F10x_FWLib\inc\stm32f10x_pwr.h
STM32F10x_FWLib\inc\stm32f10x_rcc.h
STM32F10x_FWLib\inc\stm32f10x_rtc.h
STM32F10x_FWLib\inc\stm32f10x_sdio.h
STM32F10x_FWLib\inc\stm32f10x_spi.h
STM32F10x_FWLib\inc\stm32f10x_tim.h
STM32F10x_FWLib\inc\stm32f10x_usart.h
STM32F10x_FWLib\inc\stm32f10x_wwdg.h
STM32F10x_FWLib\src
STM32F10x_FWLib\src\misc.c
STM32F10x_FWLib\src\stm32f10x_adc.c
STM32F10x_FWLib\src\stm32f10x_bkp.c
STM32F10x_FWLib\src\stm32f10x_can.c
STM32F10x_FWLib\src\stm32f10x_cec.c
STM32F10x_FWLib\src\stm32f10x_crc.c
STM32F10x_FWLib\src\stm32f10x_dac.c
STM32F10x_FWLib\src\stm32f10x_dbgmcu.c
STM32F10x_FWLib\src\stm32f10x_dma.c
STM32F10x_FWLib\src\stm32f10x_exti.c
STM32F10x_FWLib\src\stm32f10x_flash.c
STM32F10x_FWLib\src\stm32f10x_fsmc.c
STM32F10x_FWLib\src\stm32f10x_gpio.c
STM32F10x_FWLib\src\stm32f10x_i2c.c
STM32F10x_FWLib\src\stm32f10x_iwdg.c
STM32F10x_FWLib\src\stm32f10x_pwr.c
STM32F10x_FWLib\src\stm32f10x_rcc.c
STM32F10x_FWLib\src\stm32f10x_rtc.c
STM32F10x_FWLib\src\stm32f10x_sdio.c
STM32F10x_FWLib\src\stm32f10x_spi.c
STM32F10x_FWLib\src\stm32f10x_tim.c
STM32F10x_FWLib\src\stm32f10x_usart.c
STM32F10x_FWLib\src\stm32f10x_wwdg.c
SYSTEM
SYSTEM\delay
SYSTEM\delay\delay.c
SYSTEM\delay\delay.h
SYSTEM\sys
SYSTEM\sys\sys.c
SYSTEM\sys\sys.h
SYSTEM\usart
SYSTEM\usart\usart.c
SYSTEM\usart\usart.h
USER
USER\JLinkSettings.ini
USER\main.c
USER\Mini_balance_car.uvgui._xiaolong
USER\Mini_balance_car.uvgui._xiaolong_PC
USER\Mini_balance_car.uvguix.Administrator
USER\Mini_balance_car.uvopt
USER\Mini_balance_car.uvoptx
USER\Mini_balance_car.uvproj.saved_uv4
USER\Mini_balance_car.uvprojx
USER\stm32f10x.h
USER\stm32f10x_conf.h
USER\stm32f10x_it.c
USER\stm32f10x_it.h
USER\system_stm32f10x.c
USER\system_stm32f10x.h
【必读】版权免责声明
1、本主题所有言论和内容纯属会员个人意见,与本论坛立场无关。2、本站对所发内容真实性、客观性、可用性不做任何保证也不负任何责任,网友之间仅出于学习目的进行交流。3、对提供的数字内容不拥有任何权利,其版权归原著者拥有。请勿将该数字内容进行商业交易、转载等行为,该内容只为学习所提供,使用后发生的一切问题与本站无关。 4、本网站不保证本站提供的下载资源的准确性、安全性和完整性;同时本网站也不承担用户因使用这些下载资源对自己和他人造成任何形式的损失或伤害。 5、本网站所有软件和资料均为网友推荐收集整理而来,仅供学习用途使用,请务必下载后两小时内删除,禁止商用。6、如有侵犯你版权的,请及时联系我们(电子邮箱1370723259@qq.com)指出,本站将立即改正。
|
|