硬汉嵌入式论坛

 找回密码
 立即注册
查看: 5069|回复: 1
收起左侧

[有问必答] 用v3板读max6675芯片转换数据的时候遇到点问题

[复制链接]

2

主题

2

回帖

2

积分

新手上路

积分
2
发表于 2014-5-17 13:21:06 | 显示全部楼层 |阅读模式
除了芯片的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型热电偶应该是很灵敏的,但是手摸上去示数完全不变,反而剧烈晃动的时候示数变化很大,完全不明白什么原因,本来还以为热电偶换了,重新买了一套还是这个样子
回复

使用道具 举报

1万

主题

6万

回帖

10万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
107157
QQ
发表于 2014-5-17 14:56:16 | 显示全部楼层
最好用硬件SPI,使用软件方式做为片选,V3板子上这两个用来接SPI FLASH和触摸
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|Archiver|手机版|硬汉嵌入式论坛

GMT+8, 2024-5-20 20:21 , Processed in 0.155787 second(s), 31 queries .

Powered by Discuz! X3.4 Licensed

Copyright © 2001-2023, Tencent Cloud.

快速回复 返回顶部 返回列表