|
除了芯片的vcc和GND之外,把cs也接地了(低电平选中)。把时钟接在了pb6,miso接到了pb5(引脚上串的电阻已经拿掉了)。虚拟spi来读数据。程序如下
#include "stm32f10x_it.h"
#include "max6675.h"
void max6675_Init(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
/* 打开GPIOB的时钟 */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB|RCC_APB2Periph_AFIO , ENABLE);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_6 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_5 ;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IPU;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
}
void delay(unsigned int ms)
{
unsigned int i,j;
for(i=0;i<ms;i++)
{
for(j=0;j<39;j++);
}
}
uint16_t read(void )
{
uint16_t wendu=0;
int i;
max6675_Init();
for(i=0;i<16;i++)
{
GPIO_SetBits(GPIOB,GPIO_Pin_6); // SCK=1
delay(1);
GPIO_ResetBits(GPIOB,GPIO_Pin_6); //SCK=0
delay(1);
if (GPIO_ReadInputDataBit(GPIOB, GPIO_Pin_5) == Bit_SET) //1
{
wendu=wendu|0x0001;
}
wendu=wendu<<1;
}
wendu=wendu>>3;
return wendu;
}
照理6675接k型热电偶应该是很灵敏的,但是手摸上去示数完全不变,反而剧烈晃动的时候示数变化很大,完全不明白什么原因,本来还以为热电偶换了,重新买了一套还是这个样子 |
|