max31865模塊RTD測溫注意事項
注意事項1 參考電阻
注意事項2 接線
注意事項3 電氣連接
注意事項4 max31865模塊重要細節(jié)
注意事項5 SPI時序間隔
注意事項6 max31865讀取不到寄存器數(shù)據(jù)的原因
參考代碼
注意事項1 參考電阻
The PT100 version of the breakout uses 430Ω
The PT1000 version uses 4300Ω
一般PT100選400歐姆參考電阻,但是板子上給的是4300,也就是430Ω。程序里需要設(shè)置參考電阻為430,PT1000選擇4300Ω。
#define REF_RES 430
注意事項2 接線
板子上有三個位置用于設(shè)置線的。
注意事項3 電氣連接
Power Pins:
Vin - this is the power pin. Since the chip uses 3 VDC, we have included a voltage regulator on board that will take 3-5VDC and safely convert it down. To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V micro like Arduino, use 5V
3Vo - this is the 3.3V output from the voltage regulator, you can grab up to 100mA from this if you like
GND - common ground for power and logic
SPI Logic pins:
All pins going into the breakout have level shifting circuitry to make them 3-5V logic level safe. Use whatever logic level is on Vin!
SCK - This is the SPI Clock pin, its an input to the chip
SDO - this is the Serial Data Out / Microcontroller In Sensor Out pin, for data sent from the MAX31865 to your processor
SDI - this is the Serial Data In / Microcontroller Out Sensor In pin, for data sent from your processor to the MAX31865
CS - this is the Chip Select pin, drop it low to start an SPI transaction. Its an input to the chip
If you want to connect multiple MAX31865’s to one microcontroller, have them share the SDI, SDO and SCK pins. Then assign each one a unique CS pin.
RDY (Ready) - is a data-ready indicator pin, you can use this pin to speed up your reads if you are writing your own driver. Our Arduino driver doesn’t use it to save a pin.
注意事項4 max31865模塊重要細節(jié)
SPI對其寄存器進行讀寫,寄存器如下圖。
配置寄存器,想讀就讀0x00,想寫就寫0x80。
轉(zhuǎn)化后的RTD數(shù)值存放于0x01和0x02這2個8位寄存器。
可以設(shè)置錯誤報警門限上限和下限,通俗來說,比如一個PT100能測溫范圍是-200℃到420℃,用戶想設(shè)置下限報警值為-180℃,上限報警值為400℃,那么當max31865轉(zhuǎn)換RTD后,會將0x01和0x02寄存器結(jié)果與上限值和下限值比較,如果不在設(shè)置的范圍,就會產(chǎn)生錯誤標志。
錯誤標志存在0x07寄存器中。
讀取溫度過程:
(1)讀取0x07寄存器,看是不是等于0x00,即是說無錯誤標志。有錯誤標志時,0x07寄存器里面某個值就是1。
錯誤標志可以手動清除,但如果沒實際解決問題,下次檢測這個標志還是會被模塊拉起。
(2)如果能過錯誤檢測,就開始下面的過程。向0x80寫入配置,這里寫入的是說進行一次轉(zhuǎn)換(One_Shot_Conversion ),然后等待DRDY 引腳變成低電平(意味轉(zhuǎn)換結(jié)束)。然后讀取0x01和0x02這2個8位寄存器,0x02的最低位裝的是錯沒錯的標志,沒錯的話就可以利用0x01和0x02這2個8位寄存器合成電阻數(shù)值。
4)PT100電阻變成溫度
這個就各顯神通了,有各種各樣的轉(zhuǎn)換公式。
注意事項5 SPI時序間隔
注意事項6 max31865讀取不到寄存器數(shù)據(jù)的原因
從機發(fā)數(shù)據(jù)也是需要主機提供時鐘信號的
參考代碼
//使用RT1052 LPSPI3
//LPSPI3:讀寫一個字節(jié)
//TxData:要寫入的字節(jié)
//返回值:讀取到的字節(jié)
uint8_t LPSPI3_ReadWriteByte(uint8_t TxData)
{
uint8_t spirxdata=0;
uint8_t spitxdata=TxData;
lpspi_transfer_t spi_tranxfer;
lpspi_master_handle_t master_handle;
spi_tranxfer.configFlags=kLPSPI_MasterPcs1|kLPSPI_MasterPcsContinuous; //PCS1
spi_tranxfer.txData=&spitxdata; //要發(fā)送的數(shù)據(jù)
spi_tranxfer.rxData=&spirxdata; //要接收到的數(shù)據(jù)
spi_tranxfer.dataSize=1; //數(shù)據(jù)長度
LPSPI_MasterTransferBlocking(LPSPI3,&spi_tranxfer); //SPI阻塞發(fā)送
// LPSPI_MasterTransferNonBlocking(LPSPI3, &master_handle, &spi_tranxfer);
return spirxdata;
}
uint8_t max31685_ReadRegister8(uint8_t addr)
{
uint8_t ret;
GPIO_PinWrite(BOARD_USER_SPI_CS0, BOARD_USER_SPI_CS0_PIN, 1U);
SysTick_DelayTicks(1U);
GPIO_PinWrite(BOARD_USER_SPI_CS0, BOARD_USER_SPI_CS0_PIN, 0U);
SysTick_DelayTicks(1U);
ret = LPSPI3_ReadWriteByte(addr);
SysTick_DelayTicks(1U);
ret = LPSPI3_ReadWriteByte(0xff);
SysTick_DelayTicks(1U);
GPIO_PinWrite(BOARD_USER_SPI_CS0, BOARD_USER_SPI_CS0_PIN, 1U);
return ret;
}
uint8_t max31685_WriteRegister8(uint8_t addr, uint8_t data)
{
uint8_t ret;
GPIO_PinWrite(BOARD_USER_SPI_CS0, BOARD_USER_SPI_CS0_PIN, 1U);
SysTick_DelayTicks(1U);
GPIO_PinWrite(BOARD_USER_SPI_CS0, BOARD_USER_SPI_CS0_PIN, 0U);
SysTick_DelayTicks(1U);
ret = LPSPI3_ReadWriteByte(addr | 0x80);
SysTick_DelayTicks(1U);
ret = LPSPI3_ReadWriteByte(data);
SysTick_DelayTicks(1U);
GPIO_PinWrite(BOARD_USER_SPI_CS0, BOARD_USER_SPI_CS0_PIN, 1U);
return ret;
}
void max31865_Init(void)
{
uint8_t ret; //for test
GPIO_PinWrite(BOARD_USER_SPI_CS0, BOARD_USER_SPI_CS0_PIN, 1U);
SysTick_DelayTicks(10U);
//BIAS ON,自動,三線,50Hz
max31685_WriteRegister8(MAX31856_CONFIG_REG, MAX31856_CONFIG_BIAS | MAX31856_CONFIG_MODEAUTO | MAX31856_CONFIG_3WIRE | MAX31856_CONFIG_FILT50HZ);
ret = max31685_ReadRegister8(MAX31856_CONFIG_REG);
}
uint8_t max31865_ReadFault(void)
{
}
void max31865_ClearFault(void)
{
}
void max31865_Config(uint8_t reg, uint8_t cfgValue)
{
}
uint16_t max31865_ReadRTD(void)
{
uint16_t rtd = 0;
rtd = max31685_ReadRegister8(MAX31856_RTDMSB_REG) << 8;
rtd |= max31685_ReadRegister8(MAX31856_RTDLSB_REG);
rtd = rtd >> 1;
return rtd;
}