日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

max31865芯片读取pt100

發布時間:2023/12/20 编程问答 24 豆豆
生活随笔 收集整理的這篇文章主要介紹了 max31865芯片读取pt100 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
  • 引入max31865.c和.h文件,引入spi.h和.c文件

  • 在主函數調用初始化函數MAX31865_init(3);//3線制

  • #include "MAX31865.h"

    #include "spi.h"

    /*********************** Global variables *************************/

    void max31865_cs_init(void)//溫度采集放大器 片選初始化

    {

    GPIO_InitTypeDef GPIO_InitStructure;

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA, ENABLE); //使能PA端口時鐘

    RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB, ENABLE); //使能PB端口時鐘

    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12; //LED0-->PB.12 端口配置

    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; //推挽輸出

    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; //IO口速度為50MHz

    GPIO_Init(GPIOB, &GPIO_InitStructure); //根據設定參數初始化GPIOB.12

    }

    /*********************** Begin Private functions *************************/

    void MAX31865_read(uint8_t ch, uint8_t addr, uint8_t *buffer, uint8_t len)

    {

    addr &= ~MAX31865_READ; // Force read bit on address

    if (ch == 1)

    {

    MAX31865_CH1_CS;

    }

    else if(ch == 2)

    {

    MAX31865_CH2_CS;

    }

    spi_write(&addr, 1);// Write addr

    spi_read(buffer, len);// Read data

    MAX31865_CS_NULL;

    }

    /************************************************

    void MAX31865_write(uint8_t ch, uint8_t addr, uint8_t data)

    {

    addr |= MAX31865_WRITE; // Force write bit on address

    if (ch == 1)

    {

    MAX31865_CH1_CS;

    }

    else if(ch == 2)

    {

    MAX31865_CH2_CS;

    }

    spi_write(&addr, 1); // Write addr

    spi_write(&data, 1); // Write data

    MAX31865_CS_NULL;

    }

    void enableBias(uint8_t ch, uint8_t enable)//Disable bias voltage使能d7

    {

    uint8_t status;

    MAX31865_read(ch,MAX31856_CONFIG_REG, &status, 1);

    if (enable)

    {

    status |= MAX31856_CONFIG_BIAS;

    } else

    {

    status &= ~MAX31856_CONFIG_BIAS;

    }

    MAX31865_write(ch,MAX31856_CONFIG_REG, status);

    }

    /**********************************

    void autoConvert(uint8_t ch, uint8_t enable)//設置轉換模式開關

    {

    uint8_t status;

    MAX31865_read(ch,MAX31856_CONFIG_REG, &status, 1);

    if (enable)

    {

    status |= MAX31856_CONFIG_MODEAUTO;

    } else

    {

    status &= ~MAX31856_CONFIG_MODEAUTO;

    }

    MAX31865_write(ch,MAX31856_CONFIG_REG, status);

    }

    /********************************************************

    void setWires(uint8_t ch, uint8_t numwires)//設置幾線制接法

    {

    uint8_t status;

    MAX31865_read(ch,MAX31856_CONFIG_REG, &status, 1);

    if (numwires == 3) // 3-wire

    {

    status |= MAX31856_CONFIG_3WIRE;

    } else // 2-4 wire

    {

    status &= ~MAX31856_CONFIG_3WIRE;

    }

    MAX31865_write(ch,MAX31856_CONFIG_REG, status);

    }

    /****************************

    void single_shot(uint8_t ch)//讀取溫度,一次讀取溫度值

    {

    uint8_t status;

    // Read config register

    MAX31865_read(ch,MAX31856_CONFIG_REG, &status, 1);

    // Enable 1shot bit, and write back

    status |= MAX31856_CONFIG_1SHOT;

    MAX31865_write(ch,MAX31856_CONFIG_REG, status);

    }

    /*********************** End Private functions *************************/

    void MAX31865_init(uint8_t wires)//溫度采集 支持2-4線RTD選擇

    {

    spi1_init();//SDI SCL SDO io初始化

    max31865_cs_init(); //片選io初始化

    setWires(1,wires); // Set 2,3 or 4 wire sensor

    enableBias(1,OFF); // Disable bias voltage

    autoConvert(1,OFF); // Disable auto conversion

    }

    /**

    float MAX31865_readTemp(uint8_t ch)//讀取溫度函數

    {

    uint8_t buffer[2];

    uint16_t data = 0;

    float resistance = 0;

    float temp = 0;

    // Activate bias voltage to read sensor data, and wait for the capacitors to fill

    enableBias(ch,ON);

    DELAY(10);

    // Perform a single conversion, and wait for the result

    single_shot(ch);

    DELAY(65);

    // Read data from max31865 data registers

    MAX31865_read(ch,MAX31856_RTDMSB_REG, buffer, 2);

    // Combine 2 bytes into 1 number, and shift 1 down to remove fault bit

    data = buffer[0] << 8;

    data |= buffer[1];

    data >>= 1;

    // Calculate the actual resistance of the sensor

    resistance = ((float) data * RREF) / FACTOR;

    // Calculate the temperature from the measured resistance

    temp = ((resistance / 100) - 1) / ALPHA;

    // Disable bias voltage to reduce power usage

    enableBias(ch,OFF);

    return temp;

    }

    在主函數調用MAX31865_readTemp(1);即可讀取溫度

    總結

    以上是生活随笔為你收集整理的max31865芯片读取pt100的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。