包含MAX6675资料
stm32单片机源程序如下:
- /*********************************************************************************
- * 文件名 :main.c
- * 描述 :通过stm32的spi1读取max6675的温度值,并通过uart1发送出来
- *
- * 实验平台:STM32开发板
- * 库版本 :ST3.0.0
- * 硬件连接: ------------------------------------
- * |PA6-SPI1-MISO:MAX6675-SO |
- * |PA7-SPI1-MOSI:MAX6675-SI |
- * |PA5-SPI1-SCK :MAX6675-SCK |
- * |PA4-SPI1-NSS :MAX6675-CS |
- * ------------------------------------
- **********************************************************************************/
- #include "stm32f10x.h"
- #include "usart1.h"
- #define MAX6675_CS GPIO_Pin_4
- #define MAX6675_CSL() GPIOA->BRR = MAX6675_CS;
- #define MAX6675_CSH() GPIOA->BSRR = MAX6675_CS;
- /*
- * 函数名:SPI1_Init
- * 描述 MAX6675 接口初始化
- * 输入 :无
- * 输出 :无
- * 返回 :无
- */
- void SPI_MAX6675_Init(void)
- {
- GPIO_InitTypeDef GPIO_InitStructure;
- SPI_InitTypeDef SPI_InitStructure;
-
- /* 使能 SPI1 时钟 */
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_SPI1, ENABLE);
- /* ---------通信I/O初始化----------------
- * PA5-SPI1-SCK :MAX6675_SCK
- * PA6-SPI1-MISO:MAX6675_SO
- * PA7-SPI1-MOSI:MAX6675_SI
- */
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 | GPIO_Pin_6 | GPIO_Pin_7;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_PP; // 复用输出
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- /* ---------控制I/O初始化----------------*/
- /* PA4-SPI1-NSS:MAX6675_CS */ // 片选
- GPIO_InitStructure.GPIO_Pin = GPIO_Pin_4;
- GPIO_InitStructure.GPIO_Speed = GPIO_Speed_10MHz;
- GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; // 推免输出
- GPIO_Init(GPIOA, &GPIO_InitStructure);
- GPIO_SetBits(GPIOA, GPIO_Pin_4); // 先把片选拉高,真正用的时候再拉低
-
- /* SPI1 配置 */
- SPI_InitStructure.SPI_Direction = SPI_Direction_2Lines_FullDuplex;
- SPI_InitStructure.SPI_Mode = SPI_Mode_Master;
- SPI_InitStructure.SPI_DataSize = SPI_DataSize_8b;
- SPI_InitStructure.SPI_CPOL = SPI_CPOL_Low;
- SPI_InitStructure.SPI_CPHA = SPI_CPHA_1Edge;
- SPI_InitStructure.SPI_NSS = SPI_NSS_Soft;
- SPI_InitStructure.SPI_BaudRatePrescaler = SPI_BaudRatePrescaler_8;
- SPI_InitStructure.SPI_FirstBit = SPI_FirstBit_MSB;
- SPI_InitStructure.SPI_CRCPolynomial = 7;
- SPI_Init(SPI1, &SPI_InitStructure);
-
-
- /* 使能 SPI1 */
- SPI_Cmd(SPI1, ENABLE);
- }
- /*
- *
- *
- *
- */
- unsigned char MAX6675_ReadByte(void)
- {
-
- /* Loop while DR register in not emplty */
- while(SPI_I2S_GetFlagStatus(SPI1,SPI_I2S_FLAG_TXE) == RESET);
-
- /* Send byte through the SPI1 peripheral */
- SPI_I2S_SendData(SPI1, 0xff);
-
- /* Wait to receive a byte */
- while(SPI_I2S_GetFlagStatus(SPI1, SPI_I2S_FLAG_RXNE) == RESET);
-
- /* Return the byte read from the SPI bus */
- return SPI_I2S_ReceiveData(SPI1);
- }
- /*
- * 函数名:main
- * 描述 :主函数
- * 输入 :无
- * 输出 :无
- */
- main (void)
- {
- unsigned int t,i;
- unsigned char c;
- unsigned char flag;
- float temprature;
- /* 配置系统时钟为72M */
- SystemInit();
-
- /* MAX6675 SPI 接口初始化 */
- SPI_MAX6675_Init();
- USART1_Config();
-
- while(1)
- {
-
- MAX6675_CSL();
- c = MAX6675_ReadByte();
- i = c;
- i = i<<8;
- c = MAX6675_ReadByte();
- MAX6675_CSH();
-
- i = i|((unsigned int)c); //i是读出来的原始数据
- flag = i&0x04; //flag保存了热电偶的连接状态
- t = i<<1;
- t = t>>4;
- temprature = t*0.25;
- if(i!=0) //max6675有数据返回
- {
- if(flag==0) //热电偶已连接
- {
- printf("原始数据是:%04X, 当前温度是:%4.2f。\r\n",i,temprature);
- }
- else //热电偶掉线
- {
- printf("未检测到热电偶,请检查。\r\n");
- }
-
- }
- else //max6675没有数据返回
- {
- printf("max6675没有数据返回,请检查max6675连接。\r\n");
- }
- for(i=0;i<0x2fffff;i++); //max6675的转换时间是0.2秒左右,所以两次转换间隔不要太近
- ……………………
- …………限于本文篇幅 余下代码请从51黑下载附件…………
复制代码 MAX6675_51例程\
MAX6675_STM32例程\
K型热电偶和MAX6675简介.doc
MAX6675.pdf
MAX6675的原理及应用.pdf
一种简易的高精度测温系统研制.pdf
关于MAX6675应用的实验.doc
利用热电偶转换器的单片机温度测控系统_max6675[2页].pdf
单片K型热电偶放大与数字转换器MAX6675.pdf
基于89C51的温度控制器设计_文献检索[1].doc
基于K型热电偶与MAX6675多路温度采集系统.pdf
基于MAX6675的分布式高精度温度采集系统(1).pdf
基于MAX6675的温度采集系统的设计(1).pdf
基于_MAX6675的温度控制器设计.pdf
基于单片机的发动机尾气参数采集系统的设计.pdf
基于单片机的注塑机温度采集系统的设计.pdf
基于单片机的电阻炉温度控制系统设计.pdf
热电偶温度表测量电路的设计.doc
电阻加热炉温度控制系统.doc
所有资料51hei提供下载:
MAX6675.zip
(6.71 MB, 下载次数: 501)
|