1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- #include "global.h"
- /**
- * 读MAX6675原始16位数据
- *
- * @author yyq (2024/9/11/周三)
- *
- * @param port spi设备号 0、1、2
- *
- * @return value 原始16位数据
- */
- static unsigned short max6675_ReadReg(int port)
- {
- unsigned short value;
- if(port < HW_SPI_DEVICE_NUMBER)
- {
- hw_spi_device_take(port);
- hw_spi_readwrite(port, 0, (unsigned char*)&value, 2);
- hw_spi_device_release(port);
- return value;
- }
- return 0xffff;
- }
- /**
- * 读MAX6675温度值
- *
- * @author yyq (2024/9/11/周三)
- *
- * @param port spi设备号 0、1、2
- * @param value 读到的温度值
- *
- * @return int 数据有效性:1有效 0无效
- */
- int max6675_ReadTemp(int port,float* value)
- {
- unsigned short temp;
- int data_valid;
- temp = max6675_ReadReg(port);
- temp <<= 1;
- if(temp&0x08)
- {
- data_valid=0;
- }
- else
- {
- temp >>= 4;
- *value = (temp & 0x0fff)*0.25;
- data_valid=1;
- }
- return data_valid;
- }
|