Beispiel #1
0
uint8_t DS18x20_Get_Conversion_Result_by_ROM_CRC(uint8_t (*serial)[DS18x20_SERIAL_NUM_SIZE], int32_t* temperature)
{
    uint8_t cnt;
    uint8_t pad[DS18x20_STRATCHPAD_SIZE];

    /* Reset bus */
    cnt = One_Wire_Reset();

    if (cnt != ONE_WIRE_SUCCESS) {
        return cnt;
    }

    One_Wire_Write_Byte(ONE_WIRE_MATCH_ROM);

    for(cnt = 0; cnt != 8; cnt++) {
        One_Wire_Write_Byte((*serial)[cnt]);
    }
    One_Wire_Write_Byte(DS18x20_READ_STRATCHPAD_CMD);

    for(cnt = 0; cnt != DS18x20_STRATCHPAD_SIZE; cnt++) {
        pad[cnt] = One_Wire_Read_Byte();
    }

    /* Verify CRC checksum */
    if (Crc8Dallas(DS18x20_STRATCHPAD_SIZE, pad)) {
        return ONE_WIRE_CRC_ERROR;
    }

    *temperature = DS18x20_Convert_Temperature(pad, serial);

    return ONE_WIRE_SUCCESS;
}
unsigned char DS1821_Read_Status(unsigned int * status, GPIO_TypeDef * GPIOx, unsigned long PINx)
{
	unsigned char tmp;
	tmp=One_Wire_Reset(GPIOx, PINx);
	if (tmp!=One_Wire_Success) return tmp;
	One_Wire_Write_Byte(DS1821_READ_STATUS,GPIOx, PINx);
	* status = One_Wire_Read_Byte(GPIOx, PINx);
	return One_Wire_Success;
}
unsigned char DS1821_Read_Counter(unsigned int * counter, GPIO_TypeDef * GPIOx, unsigned long PINx)
{
	unsigned char tmp;
	tmp=One_Wire_Reset(GPIOx, PINx);
	if (tmp!=One_Wire_Success) return tmp;
	One_Wire_Write_Byte(DS1821_READ_COUNTER,GPIOx, PINx);
	* counter = One_Wire_Read_Byte(GPIOx, PINx);
	return One_Wire_Success;
}
unsigned char DS1821_Read_Temp(unsigned int * temperature, GPIO_TypeDef * GPIOx, unsigned long PINx)
{
	unsigned char tmp;
	tmp=One_Wire_Reset(GPIOx, PINx);
	if (tmp!=One_Wire_Success) return tmp;
	One_Wire_Write_Byte(DS1821_READ_TEMPERATURE, GPIOx, PINx);
	* temperature = One_Wire_Read_Byte(GPIOx, PINx);
	return One_Wire_Success;
}
Beispiel #5
0
uint8_t DS18x20_Start_Conversion_Skip_Rom(void)
{
    uint8_t tmp;

    /* Reset bus */
    tmp = One_Wire_Reset();

    if (tmp != ONE_WIRE_SUCCESS) {
       return tmp;
    }

    One_Wire_Write_Byte(ONE_WIRE_SKIP_ROM);
    One_Wire_Write_Byte(DS18x20_CONVERT_T_CMD);

    if (One_Wire_Read_Byte()) {
        return ONE_WIRE_DEVICE_BUSY;
    }

    return ONE_WIRE_SUCCESS;
}
Beispiel #6
0
uint8_t DS18x20_Read_Temp_NoCRC_Skip_Rom(uint8_t (*serial)[DS18x20_SERIAL_NUM_SIZE], int32_t* temperature)
{
    uint8_t tmp, cnt;
    uint8_t pad[DS18x20_STRATCHPAD_SIZE];

    /* Reset bus */
    tmp = One_Wire_Reset();

    if (tmp != ONE_WIRE_SUCCESS) {
       return tmp;
    }

    One_Wire_Write_Byte(ONE_WIRE_SKIP_ROM);
    One_Wire_Write_Byte(DS18x20_READ_STRATCHPAD_CMD);

    for (cnt = 0; cnt != DS18x20_STRATCHPAD_SIZE; cnt++) {
        pad[cnt] = One_Wire_Read_Byte();
    }

    *temperature = DS18x20_Convert_Temperature(pad, serial);

    return ONE_WIRE_SUCCESS;
}