首页 > 代码库 > 驱动程序——MAX6675——基于STM32F103

驱动程序——MAX6675——基于STM32F103

MAX6675冷端温度补偿、热电偶数字转换器可进行冷端温度补偿,并将K型热电偶信号转换成数字信号。数据输出为12位分辨率、SPI兼容、只读格式。转换器温度分辨率为0.25°C,可读取温度达+1024°C,热电偶在0°C至+700°C温度范围内精度为8 LSB。
#include <stdio.h>
#include "stm32f10x.h"
#include "stm32f10x_gpio.h"
#include "MAX6675.h"
#include "Delay.h"

#define SCLK_H GPIO_SetBits(MAX6675_PORT, TC1_SCK)
#define SCLK_L GPIO_ResetBits(MAX6675_PORT, TC1_SCK)
#define DIN GPIO_ReadInputDataBit(MAX6675_PORT, TC1_SO)


void Init_MAX6675_GPIO(void)
{
  GPIO_InitTypeDef GPIO_InitStructure;
RCC_APB2PeriphClockCmd(RCC_MAX6675 , ENABLE); 


GPIO_InitStructure.GPIO_Pin = TC1_SCK | TC1_CS;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_Init(MAX6675_PORT, &GPIO_InitStructure);

GPIO_InitStructure.GPIO_Pin = TC1_SO;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU ;
GPIO_Init(MAX6675_PORT, &GPIO_InitStructure);

GPIO_SetBits(MAX6675_PORT, TC1_CS );//CS=1;
GPIO_ResetBits(MAX6675_PORT, TC1_SCK );//SCK=0;


}


uint16_t MAX6675(unsigned char channel)
{
uint16_t temp=0;
char i;
GPIO_ResetBits(MAX6675_PORT, TC1_CS);//CS=0;
for(i=0;i<=15;i++)
{
SCLK_H;//read data SO
Delay(100);
temp<<=1;
if(DIN)
temp|=0x0001;
SCLK_L;
Delay(100);
}
GPIO_SetBits(MAX6675_PORT, TC1_CS);//CS=1;
temp>>=3;//右移3位,D0,D1,D3不要
return temp;
}

驱动程序——MAX6675——基于STM32F103