Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: NUCLEO_F410RB_MAX6675 PanelaSTM
Fork of max6675 by
max6675.cpp
00001 00002 #include <mbed.h> 00003 #include "max6675.h" 00004 00005 max6675::max6675(SPI& _spi, PinName _ncs) : spi(_spi), ncs(_ncs) { 00006 00007 } 00008 00009 float max6675::read_temp() { 00010 short value = 0; 00011 float temp = 0; 00012 00013 uint8_t highByte=0; 00014 uint8_t lowByte=0; 00015 00016 select(); //выбор чипа устанавливает CS в 0 00017 wait(.25); //Эта задержка нужна для обновления данных о температуре 00018 00019 highByte = spi.write(0); // отправляем два пустых 00020 lowByte = spi.write(0); // байта, при этом одновременно получаем два байта с данными 00021 deselect(); //устанавливаем CS в 1 (освобождаем SPI интерфейс) после того как считали температуру. 00022 00023 00024 if (lowByte & (1<<2)) { // проверяем третий бит, если равен 1, то термопара отключена 00025 return -1; 00026 } else { 00027 value = (highByte << 5 | lowByte>>3); // выделим из полученных данных инф. о температуре (с 3 по 14 бит) 00028 } 00029 00030 temp = (value*0.25); // умножаем значение на чтобы получить ˚C или 00031 // * (9.0/5.0)) + 32.0; // чтобы получить ˚F 00032 00033 return temp; 00034 } 00035 00036 void max6675::select() { 00037 ncs = 0; 00038 } 00039 00040 void max6675::deselect() { 00041 ncs = 1; 00042 }
Generated on Sat Jul 23 2022 11:25:23 by
1.7.2
