{"id":2009,"date":"2023-09-28T06:05:26","date_gmt":"2023-09-28T06:05:26","guid":{"rendered":"https:\/\/blog.embeddedexpert.io\/?p=2009"},"modified":"2023-09-28T06:05:30","modified_gmt":"2023-09-28T06:05:30","slug":"revised-working-with-stm32-and-sensors-thermocouple-typek","status":"publish","type":"post","link":"https:\/\/blog.embeddedexpert.io\/?p=2009","title":{"rendered":"[Revised] Working with STM32 and Sensors: Thermocouple TypeK"},"content":{"rendered":"\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"1024\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/AdobeStock_330551998-1024x1024.jpeg\" alt=\"\" class=\"wp-image-2010\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/AdobeStock_330551998-1024x1024.jpeg 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/AdobeStock_330551998-300x300.jpeg 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/AdobeStock_330551998-150x150.jpeg 150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/AdobeStock_330551998-768x768.jpeg 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/AdobeStock_330551998-1536x1536.jpeg 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/AdobeStock_330551998-2048x2048.jpeg 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/AdobeStock_330551998-1150x1150.jpeg 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/AdobeStock_330551998-750x750.jpeg 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/AdobeStock_330551998-400x400.jpeg 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/AdobeStock_330551998-250x250.jpeg 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>In this guide, we shall take a look at the thermocouple and how this type of sensor works and use MAX6675 thermocouple to measure the temperature.<\/p>\n\n\n\n<p>In this guide, we shall cover the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Thermocouple typeK<\/li><li>MAX6675.<\/li><li>Connection MAX6675 with STM32.<\/li><li>Code.<\/li><li>Result<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">1. Thermocouple Type K:<\/h2>\n\n\n\n<p>ype K Thermocouple provides widest operating temperature range. It consist of positive leg which is non-magnetic and negative leg which is magnetic.In K Type Thermocouple &nbsp;traditional base metal is used due to which it can work at high temperature and can provide widest operating temperature range. One of the constituent metal in K Type Thermocouple is&nbsp;Nickel, which is magnetic in nature.<\/p>\n\n\n\n<p>The characteristic shown by K Type Thermocouple is that they undergo a deviation in output when magnetic material reaches its Curie Point, at around &nbsp;185 \u00b0C. K Type &nbsp;thermocouple &nbsp;work very well in oxidizing atmosphere at temperatures up to 1260\u00b0C (2300\u00b0F) and its tolerance class is \u00b1 1.5 K between -40 and 375 \u00b0C.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/tempsens.com\/pub\/media\/images\/image_2021_01_22T06_17_12_860Z.png\" alt=\"Type K Thermocouple International Color Code \" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\">Why To prefer K Type Thermocouple<\/h2>\n\n\n\n<ul class=\"wp-block-list\"><li>One of the major advantage of K type thermocouple over other thermocouple&#8217;s is it can function in rugged environmental condition &amp; in various atmospheres<\/li><li>It has integrated composition of Chromel and Alumel wires has a range of -270 \u00b0C to 1260\u00b0C&nbsp;and&nbsp;an&nbsp;output&nbsp;of&nbsp;-6.4&nbsp;to&nbsp;9&nbsp;mV&nbsp;over&nbsp;maximum&nbsp;temperature&nbsp;range.<\/li><li>Also known as general purpose thermocouple due to its wide range of&nbsp; temperature<\/li><li>Type K has a longer life than Type J as in Type J Fe (iron) wire oxidizes rapidly, especially at higher temperature<\/li><li>They are inexpensive.<\/li><li>Have a fast response<\/li><li>Small in size and are reliable.<\/li><li>Generally used at temperatures above 540 degrees C<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Composition of K Type Thermocouple<\/h3>\n\n\n\n<p>In K Type Thermocouple positive leg is composed of 90% nickel, 10%chromium and a negative leg is composed of 95% nickel, 2% aluminum, 2% manganese and 1% silicon. These are the most common general purpose thermocouple with a sensitivity of approx 41\u00b5V\/\u00b0C.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\">Type K Insulation Material<\/h4>\n\n\n\n<p>In Type K Thermocouple mainly two type of insulation is used firstly Ceramic beads &nbsp;insulation is used as it is a lightweight insulating product. It is made from high purity alumino-silicate materials. It has low thermal mass which means that it does not retain heat, low thermal conductivity and is an extremely effective insulation material as it can withstand high&nbsp;temperature&nbsp;of&nbsp;1260&nbsp;\u00b0C&nbsp;so&nbsp;it&nbsp;it&nbsp;best&nbsp;suited&nbsp;material&nbsp;for&nbsp;Type&nbsp;K&nbsp;thermocouple.<\/p>\n\n\n\n<p>Secondly compacted mineral insulation and outer metal sheath (MgO) is used. Magnesium Oxide has a high dielectric strength, responds quickly to temperature changes and is very durable. It has typical Composition of the Standard Quality MgO (97%) and the High Purity MgO and AI2O3.<\/p>\n\n\n\n<p>Magnesium Oxide insulation is recommended for K Type thermocouple when Thermocouple are to be immersed in liquids, high moisture, corrosive gases or high pressures. The thermocouple can be formed to reach otherwise inaccessible areas.<\/p>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/tempsens.com\/pub\/media\/blog\/type-k-thermocouple-tolerance-class.jpg\" alt=\"Type K Thermocouple Tolerance Class\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Temperature Range<\/h3>\n\n\n\n<p>To find appropriate range of thermocouple we should use appropriate wire because different wires measure various temperature ranges. Of the four major thermocouple types, type K covers the widest range :<em>&#8211;<\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Thermocouple grade wire, \u2013454 to 2,300F (\u2013270 to1260\u00b0C)<\/li><li>Extension wire, 32 to 392F (0 to200\u00b0C)<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Accuracy (whichever is greater)<\/h3>\n\n\n\n<ul class=\"wp-block-list\"><li>Standard: +\/- 2.2\u00b0C or +\/-.75%<\/li><li>Special Limits of Error: +\/<em>&#8211;&nbsp;<\/em>l\u00b0C or0.4%<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Tolerance Class<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/tempsens.com\/pub\/media\/blog\/type-k-insulation-material.jpg\" alt=\"Type K Insulation Material\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">EMF Vs Temperature Graph for K Type Thermocouple<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img decoding=\"async\" src=\"https:\/\/tempsens.com\/pub\/media\/blog\/emf-temperature-graph-k-type-thermocouple.jpg\" alt=\"EMF Vs Temperature Graph for K Type Thermocouple\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Pros And Cons:<\/h3>\n\n\n\n<h4 class=\"wp-block-heading\">Pros<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>To measure temperature it provide good linearity of emf<\/li><li>It provide good resistance aganist oxidation below 1000 \u00b0C(1600\u00b0F).<\/li><li>Highly stable output<\/li><li>Comparitively cost effective than other thermocouple.<\/li><\/ul>\n\n\n\n<h4 class=\"wp-block-heading\">Cons<\/h4>\n\n\n\n<ul class=\"wp-block-list\"><li>Not suitable for reducing atmosphere but can withstand metallic<\/li><li>Aging of the emf characteristic, when compared to noble metal thermocouples (B, R, andS).<\/li><li>Not suitable for vacuum applications due to vaporization of chromium in the positive element.<\/li><li>Green-Rotis phenomenon may occur due to low oxygen level for the thermocouples which are used between 815\u00b0C to 1040\u00b0C (1500\u00b0F to1900\u00b0F).<\/li><li>Type K thermocouples should not be used in Sulphuric environment since both elements will rapidly corrode and the negative element will eventually fail mechanically due to becoming brittle.<\/li><\/ul>\n\n\n\n<h3 class=\"wp-block-heading\">Uses of K Type Thermocouple<\/h3>\n\n\n\n<p>They are mostly used for applications at temperatures above 550 \u00b0C up to the maximum working pressure of the thermocouple.<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>They are used in many industries like Steel &amp; Iron to monitor temperature &amp; chemistry through out the steel making process<\/li><li>Used for testing temperatures associated with process plants e.g. chemical production and petroleum refineries<\/li><li>Used for Testing of heating appliance safety<\/li><li>Type K is commonly used in nuclear applications because of its relative radiation hardness.<\/li><\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2. MAX6675:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>he MAX6675 performs cold-junction compensation and digitizes the signal from a type-K thermocouple. The data is output in a 12-bit resolution, SPI-compatible, read-only format.<\/p>\n\n\n\n<p>This converter resolves temperatures to 0.25\u00b0C, allows readings as high as +1024\u00b0C, and exhibits thermocouple accuracy of 8 LSBs for temperatures ranging from 0\u00b0C to +700\u00b0C.<\/p>\n\n\n\n<p><strong>Applications<\/strong><\/p>\n\n\n\n<p>\u25cf&nbsp;Industrial&nbsp;\u25cf&nbsp;Appliances&nbsp;\u25cf&nbsp;HVAC<\/p>\n\n\n\n<p><strong>Features<\/strong><\/p>\n\n\n\n<p>\u25cf&nbsp;Direct Digital Conversion of Type -K Thermocouple Output<\/p>\n\n\n\n<p>\u25cf&nbsp;Cold-Junction Compensation<br>\u25cf&nbsp;Simple SPI-Compatible Serial Interface&nbsp;\u25cf&nbsp;12-Bit, 0.25\u00b0C Resolution<br>\u25cf&nbsp;Open Thermocouple Detection<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Pin Configuration:<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"677\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM-1024x677.png\" alt=\"\" class=\"wp-image-807\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM-1024x677.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM-300x198.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM-768x508.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM-750x496.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM-400x264.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM-250x165.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.09.22-PM.png 1104w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<h3 class=\"wp-block-heading\">Typical connection:<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"754\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM-1024x754.png\" alt=\"\" class=\"wp-image-808\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM-1024x754.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM-300x221.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM-768x566.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM-750x553.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM-400x295.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM-250x184.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.10.34-PM.png 1094w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>As seen, it requires minimal external components to make the converter works with our STM32.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Serial Output of MAX6675:<\/h3>\n\n\n\n<div class=\"wp-block-image\"><figure class=\"aligncenter\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"288\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-1024x288.png\" alt=\"\" class=\"wp-image-809\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-1024x288.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-300x84.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-768x216.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-1536x432.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-2048x576.png 2048w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-1150x323.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-750x211.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-400x112.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2022\/03\/Screen-Shot-2022-03-08-at-4.12.21-PM-250x70.png 250w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure><\/div>\n\n\n\n<p>As seen from the picture, the converter requires CLK, CS and SO.<\/p>\n\n\n\n<p>This can be achieved SPI driver.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">3. MAX6675 connection with STM32F4:<\/h2>\n\n\n\n<p>In this guide, we need the following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>STM32F411RE Nucleo64.<\/li><li>SSD1306 OLED display.<\/li><li>MAX6675 breakout board with Thermocouple Type K.<\/li><li>Breadboard.<\/li><li>Hookup wires.<\/li><\/ul>\n\n\n\n<p>The connection as following:<\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"549\" src=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/Screen-Shot-2022-03-08-at-4.25.59-PM-2048x1097-1-1024x549.png\" alt=\"\" class=\"wp-image-2011\" srcset=\"https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/Screen-Shot-2022-03-08-at-4.25.59-PM-2048x1097-1-1024x549.png 1024w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/Screen-Shot-2022-03-08-at-4.25.59-PM-2048x1097-1-300x161.png 300w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/Screen-Shot-2022-03-08-at-4.25.59-PM-2048x1097-1-768x411.png 768w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/Screen-Shot-2022-03-08-at-4.25.59-PM-2048x1097-1-1536x823.png 1536w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/Screen-Shot-2022-03-08-at-4.25.59-PM-2048x1097-1-1150x616.png 1150w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/Screen-Shot-2022-03-08-at-4.25.59-PM-2048x1097-1-750x402.png 750w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/Screen-Shot-2022-03-08-at-4.25.59-PM-2048x1097-1-400x214.png 400w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/Screen-Shot-2022-03-08-at-4.25.59-PM-2048x1097-1-250x134.png 250w, https:\/\/blog.embeddedexpert.io\/wp-content\/uploads\/2023\/09\/Screen-Shot-2022-03-08-at-4.25.59-PM-2048x1097-1.png 2048w\" sizes=\"(max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<p>For the  SSD1306 driver, refer to this code <a href=\"https:\/\/blog.embeddedexpert.io\/?p=613\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=613\" target=\"_blank\" rel=\"noreferrer noopener\">here<\/a>.<\/p>\n\n\n\n<p>For SPI configuration, please refer to <a href=\"https:\/\/blog.embeddedexpert.io\/?p=1750\" data-type=\"URL\" data-id=\"https:\/\/blog.embeddedexpert.io\/?p=1750\" target=\"_blank\" rel=\"noreferrer noopener\">this<\/a> guide.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>The connection as following:<\/p>\n\n\n\n<figure class=\"wp-block-table is-style-stripes\"><table><tbody><tr><td>MAX6675<\/td><td>STM32F411<\/td><\/tr><tr><td>SCK<\/td><td>PA5<\/td><\/tr><tr><td>SO<\/td><td>PA6<\/td><\/tr><tr><td>CS<\/td><td>PA9<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">4. Code:<\/h2>\n\n\n\n<p>Since the MAX6675 uses SPI, we shall use SPI1 of STM32F411 to handle the reading of the MCU.<\/p>\n\n\n\n<p>We start off by creating new header file with name of max6675.h header file.<\/p>\n\n\n\n<p>Within the header file:<\/p>\n\n\n\n<p>Include the header guard:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#ifndef MAX6675_H_\n#define MAX6675_H_\n\n\n\n\n#endif \/* MAX6675_H_ *\/<\/pre><\/div>\n\n\n\n<p>Within the header guard, include the following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;stdint.h&quot;<\/pre><\/div>\n\n\n\n<p>Define NAN to be -1000 for thermocouple not connected:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#define NAN -1000<\/pre><\/div>\n\n\n\n<p>Declare the following functions:<\/p>\n\n\n\n<p>MAX6675 SPI Initializing:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void max6675_spi_init(void);<\/pre><\/div>\n\n\n\n<p>Read MAX6675 to get the temperature both in Celsius or Fahrenheit:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">float readMax6675_C(void);\n\nfloat readMax6675_F(void);<\/pre><\/div>\n\n\n\n<p>Hence, the entire header file as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#ifndef MAX6675_H_\n#define MAX6675_H_\n\n#include &quot;stdint.h&quot;\n\n#define NAN -1000\n\nvoid max6675_spi_init(void);\n\nfloat readMax6675_C(void);\n\nfloat readMax6675_F(void);\n\n#endif \/* MAX6675_H_ *\/<\/pre><\/div>\n\n\n\n<p>Thats all for the header file.<\/p>\n\n\n\n<p>Now, create new source file with name of max6675.c source file.<\/p>\n\n\n\n<p>Within the source file, include the following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;max6675.h&quot;\n#include &quot;stm32f4xx.h&quot;<\/pre><\/div>\n\n\n\n<p>Define two macros for CS pin handling as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#define CS_LOW()\tGPIOA-&gt;BSRR|=GPIO_BSRR_BR9\n\n#define CS_HIGH()\tGPIOA-&gt;BSRR|=GPIO_BSRR_BS9<\/pre><\/div>\n\n\n\n<p>For the initializing function:<\/p>\n\n\n\n<p>Start with enabling clock access to GPIOA:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/*Enable Clock Access to GPIOA*\/\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOAEN;<\/pre><\/div>\n\n\n\n<p>Set PA5 to PA5 to alternate function and which alternate function:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/*Set PA5,PA6 and PA7 alternate function*\/\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE5_1|GPIO_MODER_MODE6_1|GPIO_MODER_MODE7_1;\n\tGPIOA-&gt;MODER&amp;=~(GPIO_MODER_MODE5_0|GPIO_MODER_MODE6_0|GPIO_MODER_MODE7_0);\n\n\t#define AF05 0x05\n\n\tGPIOA-&gt;AFR[0]|=(AF05&lt;&lt;GPIO_AFRL_AFSEL5_Pos)|(AF05&lt;&lt;GPIO_AFRL_AFSEL6_Pos)|(AF05&lt;&lt;GPIO_AFRL_AFSEL7_Pos);<\/pre><\/div>\n\n\n\n<p>Set PA9 as output:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/*Set PA0=9 as Output*\/\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE9_0;\n\tGPIOA-&gt;MODER&amp;=~GPIO_MODER_MODE9_1;\n<\/pre><\/div>\n\n\n\n<p>Then enable clock access to SPI1 as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/*Enable clock access to SPI1*\/\n\tRCC-&gt;APB2ENR|=RCC_APB2ENR_SPI1EN;<\/pre><\/div>\n\n\n\n<p>Configure the SPI as following:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>Mode: Master<\/li><li>Divide the buad by 16 (to get 3 MHz since the APB2 bus is running at 50MHz and maximum frequency for MAX6675 is 4MHz).<\/li><li>Software slave management.<\/li><li>Data size to be 16-bit.<\/li><li>Finally enable the module.<\/li><\/ul>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">\t\/*Set the mode to master*\/\n\tSPI1-&gt;CR1|=SPI_CR1_MSTR;\n\n\t\/*Set Buadrate to be Fclk\/16*\/\n\t#define Fclk16\t0x03\n\tSPI1-&gt;CR1|=(Fclk16&lt;&lt;SPI_CR1_BR_Pos);\n\n\t\/*Set the slave for software management*\/\n\tSPI1-&gt;CR1|=SPI_CR1_SSM|SPI_CR1_SSI;\n\n\t\/*Set data to be 16-bit*\/\n\tSPI1-&gt;CR1|=SPI_CR1_DFF;\n\n\t\/*Enable SPI1*\/\n\tSPI1-&gt;CR1|=SPI_CR1_SPE;<\/pre><\/div>\n\n\n\n<p>Hence, the initializing function as following:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">void max6675_spi_init(void)\n{\n\t\/*Enable Clock Access to GPIOA*\/\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOAEN;\n\n\t\/*Set PA5,PA6 and PA7 alternate function*\/\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE5_1|GPIO_MODER_MODE6_1|GPIO_MODER_MODE7_1;\n\tGPIOA-&gt;MODER&amp;=~(GPIO_MODER_MODE5_0|GPIO_MODER_MODE6_0|GPIO_MODER_MODE7_0);\n\n\t#define AF05 0x05\n\n\tGPIOA-&gt;AFR[0]|=(AF05&lt;&lt;GPIO_AFRL_AFSEL5_Pos)|(AF05&lt;&lt;GPIO_AFRL_AFSEL6_Pos)|(AF05&lt;&lt;GPIO_AFRL_AFSEL7_Pos);\n\n\t\/*Set PA0=9 as Output*\/\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE9_0;\n\tGPIOA-&gt;MODER&amp;=~GPIO_MODER_MODE9_1;\n\n\t\/*Configure SPI1*\/\n\n\t\/*Enable clock access to SPI1*\/\n\tRCC-&gt;APB2ENR|=RCC_APB2ENR_SPI1EN;\n\n\t\/*Set the mode to master*\/\n\tSPI1-&gt;CR1|=SPI_CR1_MSTR;\n\n\t\/*Set Buadrate to be Fclk\/16*\/\n\t#define Fclk16\t0x03\n\tSPI1-&gt;CR1|=(Fclk16&lt;&lt;SPI_CR1_BR_Pos);\n\n\t\/*Set the slave for software management*\/\n\tSPI1-&gt;CR1|=SPI_CR1_SSM|SPI_CR1_SSI;\n\n\t\/*Set data to be 16-bit*\/\n\tSPI1-&gt;CR1|=SPI_CR1_DFF;\n\n\t\/*Enable SPI1*\/\n\tSPI1-&gt;CR1|=SPI_CR1_SPE;\n\n}<\/pre><\/div>\n\n\n\n<p>Now, we need a static function that will read the SPI bus as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">static uint16_t readMax6675(void)\n{\n\n\tSPI1-&gt;DR =0;\n\t\/*Wait for RXNE flag to be set*\/\n\twhile(!(SPI1-&gt;SR &amp; (SPI_SR_RXNE))){}\n\t\/*Read data from data register*\/\n\treturn SPI1-&gt;DR;\n}<\/pre><\/div>\n\n\n\n<p>To read the temperature in Celsius:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">float readMax6675_C(void)\n{\n\t\/*Set CS to LOW*\/\n\tCS_LOW();\n\n\t\/*Read Max6675*\/\n\tuint16_t data=readMax6675();\n\n\t\/*Set CS to HIGH*\/\n\tCS_HIGH();\n\n\tfloat temp;\n\n\tif (data &amp; 0x4)return (NAN);\n\tdata &gt;&gt;= 3;\n\n\ttemp=data*0.20;\n\treturn temp ;\n}<\/pre><\/div>\n\n\n\n<p>In Fahrenheit:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">float readMax6675_F(void)\n{\n\treturn (readMax6675_C() * 9.0 \/ 5.0 + 32);\n}<\/pre><\/div>\n\n\n\n<p>Hence, the entire source code as following:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;max6675.h&quot;\n#include &quot;stm32f4xx.h&quot;\n\n\n#define CS_LOW()\tGPIOA-&gt;BSRR|=GPIO_BSRR_BR9\n\n#define CS_HIGH()\tGPIOA-&gt;BSRR|=GPIO_BSRR_BS9\n\n\n\nvoid max6675_spi_init(void)\n{\n\t\/*Enable Clock Access to GPIOA*\/\n\tRCC-&gt;AHB1ENR|=RCC_AHB1ENR_GPIOAEN;\n\n\t\/*Set PA5,PA6 and PA7 alternate function*\/\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE5_1|GPIO_MODER_MODE6_1|GPIO_MODER_MODE7_1;\n\tGPIOA-&gt;MODER&amp;=~(GPIO_MODER_MODE5_0|GPIO_MODER_MODE6_0|GPIO_MODER_MODE7_0);\n\n\t#define AF05 0x05\n\n\tGPIOA-&gt;AFR[0]|=(AF05&lt;&lt;GPIO_AFRL_AFSEL5_Pos)|(AF05&lt;&lt;GPIO_AFRL_AFSEL6_Pos)|(AF05&lt;&lt;GPIO_AFRL_AFSEL7_Pos);\n\n\t\/*Set PA0=9 as Output*\/\n\tGPIOA-&gt;MODER|=GPIO_MODER_MODE9_0;\n\tGPIOA-&gt;MODER&amp;=~GPIO_MODER_MODE9_1;\n\n\t\/*Configure SPI1*\/\n\n\t\/*Enable clock access to SPI1*\/\n\tRCC-&gt;APB2ENR|=RCC_APB2ENR_SPI1EN;\n\n\t\/*Set the mode to master*\/\n\tSPI1-&gt;CR1|=SPI_CR1_MSTR;\n\n\t\/*Set Buadrate to be Fclk\/16*\/\n\t#define Fclk16\t0x03\n\tSPI1-&gt;CR1|=(Fclk16&lt;&lt;SPI_CR1_BR_Pos);\n\n\t\/*Set the slave for software management*\/\n\tSPI1-&gt;CR1|=SPI_CR1_SSM|SPI_CR1_SSI;\n\n\t\/*Set data to be 16-bit*\/\n\tSPI1-&gt;CR1|=SPI_CR1_DFF;\n\n\t\/*Enable SPI1*\/\n\tSPI1-&gt;CR1|=SPI_CR1_SPE;\n\n}\n\n\nstatic uint16_t readMax6675(void)\n{\n\n\tSPI1-&gt;DR =0;\n\t\/*Wait for RXNE flag to be set*\/\n\twhile(!(SPI1-&gt;SR &amp; (SPI_SR_RXNE))){}\n\t\/*Read data from data register*\/\n\treturn SPI1-&gt;DR;\n}\n\nfloat readMax6675_C(void)\n{\n\t\/*Set CS to LOW*\/\n\tCS_LOW();\n\n\t\/*Read Max6675*\/\n\tuint16_t data=readMax6675();\n\n\t\/*Set CS to HIGH*\/\n\tCS_HIGH();\n\n\tfloat temp;\n\n\tif (data &amp; 0x4)return (NAN);\n\tdata &gt;&gt;= 3;\n\n\ttemp=data*0.20;\n\treturn temp ;\n}\n\nfloat readMax6675_F(void)\n{\n\treturn (readMax6675_C() * 9.0 \/ 5.0 + 32);\n}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<p>In main.c:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre class=\"CodeMirror\" data-setting=\"{&quot;showPanel&quot;:true,&quot;languageLabel&quot;:&quot;language&quot;,&quot;fullScreenButton&quot;:true,&quot;copyButton&quot;:true,&quot;mode&quot;:&quot;clike&quot;,&quot;mime&quot;:&quot;text\/x-csrc&quot;,&quot;theme&quot;:&quot;dracula&quot;,&quot;lineNumbers&quot;:false,&quot;styleActiveLine&quot;:false,&quot;lineWrapping&quot;:false,&quot;readOnly&quot;:true,&quot;fileName&quot;:&quot;&quot;,&quot;language&quot;:&quot;C&quot;,&quot;maxHeight&quot;:&quot;400px&quot;,&quot;modeName&quot;:&quot;c&quot;}\">#include &quot;oled.h&quot;\n#include &quot;max6675.h&quot;\n#include &quot;stdio.h&quot;\nextern void SysClockConfig(void);\n\nchar data_print[30];\nfloat temp;\nint main(void)\n{\n\tSCB-&gt;CPACR |= ((3UL &lt;&lt; 10*2)|(3UL &lt;&lt; 11*2));\n\tSysClockConfig();\n\tSSD1306_Init();\n\tmax6675_spi_init();\n\twhile(1)\n\t{\n\t\tSSD1306_Clear();\n\t\ttemp=readMax6675_C();\n\t\tSSD1306_GotoXY(0,0);\n\t\tsprintf(data_print,&quot;T=%0.2fC  &quot;,temp);\n\t\tSSD1306_Puts(data_print,&amp;Font_11x18, 1);\n\t\tSSD1306_UpdateScreen();\n\t\tdelay(333);\n\t}\n\n\t}\n<\/pre><\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\">5. Results:<\/h2>\n\n\n\n<p><\/p>\n\n\n\n<p>When you upload the code, you should get the following:<\/p>\n\n\n\n<p><\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"MAX6675 Interface with STM32F4\" width=\"1170\" height=\"658\" src=\"https:\/\/www.youtube.com\/embed\/4rv5D2Xyl-c?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>In this guide, we shall take a look at the thermocouple and how this type of sensor works and use MAX6675 thermocouple to measure the temperature. In this guide, we shall cover the following: Thermocouple typeK MAX6675. Connection MAX6675 with STM32. Code. Result 1. Thermocouple Type K: ype K Thermocouple provides widest operating temperature range. [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,19,11,12],"tags":[],"class_list":["post-2009","post","type-post","status-publish","format-standard","hentry","category-embedded-systems","category-lcd","category-peripheral-drivers","category-stm32"],"_links":{"self":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2009"}],"collection":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=2009"}],"version-history":[{"count":1,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2009\/revisions"}],"predecessor-version":[{"id":2012,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=\/wp\/v2\/posts\/2009\/revisions\/2012"}],"wp:attachment":[{"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=2009"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=2009"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.embeddedexpert.io\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=2009"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}