你的浏览器版本过低,可能导致网站不能正常访问!
为了你能正常使用网站功能,请使用这些浏览器。

查看: 2290|回复: 10

ARM®mbed OS入门开发 DS18B20测温实验

[复制链接]

61

主题

1071

回帖

17

蝴蝶豆

论坛元老

最后登录
2020-12-9
发表于 2016-10-21 11:03:24 | 显示全部楼层 |阅读模式
/**

    NUCLEO-F070R + DS18B20

Date:     Oct.2016
Version:  1.0
Name:     NUCLEO-F070R-DS1820
NOTE:     For more info see here: http://www.emcu.it/NUCLEOevaBoards/mBed/QSG-Mbed-Library.pdf
          原程序带NTC测温,本人将已其删除

UART   
    Baud Rate:    9600
    Data Bit:     8
    Parity:       NONE
    Stop Bit:     1
    Flow Control: NONE


Connect to the NUCLEO-F070R8 the DS18B20 sensor (see the schematic below).
The temperature sampling time is 1 sec.

DS18B20 front view
    __________
   |          |
   |    DS    |
   |   18B20  |   
   |          |
   |__________|
     |   |   |
     1   2   3
    GND  DQ VCC (3V3)
     |   |   |______________ to VCC (3.3V on the NUCLEO-F070R)  
     |   |  _|_
     |   |  | |
     |   |  | | 4K7
     |   |  | |
     |   |  -|-
     |   |___|______________ to A1 (on the NUCLEO-F070RE)
     |
     |
     |______________________ to GND (on the NUCLEO-F070RE)   

This SW is just for only one DS18B20
This SW is a derivative of:: http://developer.mbed.org/users/Sissors/code/DS1820_HelloWorld/
On the: http://developer.mbed.org/users/Sissors/code/DS1820_HelloWorld/ there is a multi sensor (DS18B20) example.


*/

#define MULTIPLE_PROBES
#define DATA_PIN        A1

#ifdef MULTIPLE_PROBES

#include "mbed.h"
#include "DS1820.h"

#define MAX_PROBES      16

float get_temperature(void);


float temp=0;
float tempArr[100];
int n=0;//n个测温设备
Serial pc(SERIAL_TX, SERIAL_RX); // 虚拟 USART2 tx, rx
DS1820* probe[MAX_PROBES];

int main()
{  
    // Initialize the probe array to DS1820 objects
    int num_devices = 0;
    while(DS1820::unassignedProbe(DATA_PIN)) //检测测温设备
    {
        probe[num_devices] = new DS1820(DATA_PIN);
        num_devices++;
        if (num_devices == MAX_PROBES)
            break;
    }

    printf("Found %d device(s)\r\n\n", num_devices);//检测到n个测温设备

    while(1)
    {
        probe[0]->convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
        for (int i = 0; i<num_devices; i++)
            printf("Device %d returns %3.3f oC\r\n", i, probe->temperature());

        wait(1);
    }

}

#else
#include "mbed.h"
#include "DS1820.h"

DS1820 probe(DATA_PIN);

int main() {
    while(1) {
        probe.convertTemperature(true, DS1820::all_devices);         //Start temperature conversion, wait until ready
        printf("It is %3.3f oC\r\n", probe.temperature());
        wait(1);
    }
}

#endif

413204538946456073.jpg

微信截图_20161021110214.png

<
回复

使用道具 举报

61

主题

1071

回帖

17

蝴蝶豆

论坛元老

最后登录
2020-12-9
 楼主| 发表于 2016-10-21 11:10:31 | 显示全部楼层
先占楼 u=397720390,2098644530&amp;fm=21&amp;gp=0.jpg
回复 支持 反对

使用道具 举报

6

主题

446

回帖

0

蝴蝶豆

金牌会员

最后登录
2017-5-24
发表于 2016-10-21 12:03:40 | 显示全部楼层
楼主大神,您好6666
回复 支持 反对

使用道具 举报

0

主题

159

回帖

0

蝴蝶豆

高级会员

最后登录
2017-3-9
发表于 2016-10-21 18:24:55 | 显示全部楼层
谢谢分享
回复 支持 反对

使用道具 举报

29

主题

290

回帖

15

蝴蝶豆

论坛元老

最后登录
2020-12-3
发表于 2016-10-21 20:17:48 | 显示全部楼层
为什么显示的是负温度?
回复 支持 反对

使用道具 举报

61

主题

1071

回帖

17

蝴蝶豆

论坛元老

最后登录
2020-12-9
 楼主| 发表于 2016-10-21 20:27:22 | 显示全部楼层
回头继续调试
回复 支持 反对

使用道具 举报

64

主题

744

回帖

23

蝴蝶豆

实习版主

最后登录
2020-12-8
发表于 2016-10-22 12:50:35 | 显示全部楼层
回复 支持 反对

使用道具 举报

13

主题

695

回帖

0

蝴蝶豆

金牌会员

最后登录
2020-6-7
发表于 2016-10-22 17:42:21 | 显示全部楼层
:):)
回复 支持 反对

使用道具 举报

23

主题

588

回帖

0

蝴蝶豆

高级会员

最后登录
2018-4-11
发表于 2016-10-22 23:51:53 | 显示全部楼层
希望有一块这样的开发板!!!!
回复 支持 反对

使用道具 举报

4

主题

484

回帖

0

蝴蝶豆

金牌会员

最后登录
2020-8-12
发表于 2016-11-18 07:15:56 来自手机 | 显示全部楼层
谢楼主分享
回复 支持 反对

使用道具 举报

关于
我们是谁
投资者关系
意法半导体可持续发展举措
创新与技术
意法半导体官网
联系我们
联系ST分支机构
寻找销售人员和分销渠道
社区
媒体中心
活动与培训
隐私策略
隐私策略
Cookies管理
行使您的权利
官方最新发布
STM32N6 AI生态系统
STM32MCU,MPU高性能GUI
ST ACEPACK电源模块
意法半导体生物传感器
STM32Cube扩展软件包
关注我们
st-img 微信公众号
st-img 手机版