ds18b20-MODBUS/john103C6T6/Core/Inc/onewire.h
2025-06-24 19:06:17 +03:00

78 lines
2.9 KiB
C
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/**
******************************************************************************
* @file onewire.h
* @brief This file contains all the constants parameters for the OneWire
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef ONEWIRE_H
#define ONEWIRE_H
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "ow_port.h"
/* Driver Selection ----------------------------------------------------------*/
//#define LL_Driver
//#define CMSIS_Driver
/* OneWire Timings -----------------------------------------------------------*/
#define ONEWIRE_RESET_PULSE_US 480 // Длительность импульса сброса
#define ONEWIRE_PRESENCE_WAIT_US 70 // Ожидание ответа от датчика
#define ONEWIRE_PRESENCE_DURATION_US 410 // Длительность сигнала присутствия
#define ONEWIRE_WRITE_1_US 8 // Длительность записи "1"
#define ONEWIRE_WRITE_0_US 57 // Длительность записи "0"
#define ONEWIRE_READ_CMD_US 2 // Время комманды чтения бита
#define ONEWIRE_READ_DELAY_US 6 // Задержка перед считыванием бита
#define ONEWIRE_COMMAND_SLOT_US 58 // Общее время комманды OneWire
#define ONEWIRE_RECOVERY_TIME_US 1 // Восстановление перед следующим слотом
/* Common Register -----------------------------------------------------------*/
#define ONEWIRE_CMD_SEARCHROM 0xF0
#define ONEWIRE_CMD_READROM 0x33
#define ONEWIRE_CMD_MATCHROM 0x55
#define ONEWIRE_CMD_SKIPROM 0xCC
/* Data Structure ------------------------------------------------------------*/
typedef enum
{
Input,
Output
} PinMode;
typedef struct
{
uint8_t LastDiscrepancy;
uint8_t LastFamilyDiscrepancy;
uint8_t LastDeviceFlag;
uint8_t RomByte[8];
uint8_t RomCnt;
uint16_t DataPin;
GPIO_TypeDef *DataPort;
} OneWire_t;
/* External Function ---------------------------------------------------------*/
void OneWire_Init(OneWire_t* OW);
uint8_t OneWire_Search(OneWire_t* OW, uint8_t Cmd);
void OneWire_GetDevRom(OneWire_t* OW, uint8_t *dev);
uint8_t OneWire_Reset(OneWire_t* OW);
uint8_t OneWire_ReadBit(OneWire_t* OW);
uint8_t OneWire_ReadByte(OneWire_t* OW);
void OneWire_WriteByte(OneWire_t* OW, uint8_t byte);
void OneWire_MatchROM(OneWire_t* OW, uint8_t *Rom);
void OneWire_Skip(OneWire_t* OW);
uint8_t OneWire_CRC8(uint8_t *addr, uint8_t len);
void OneWire_Pin_Mode(OneWire_t* OW, PinMode Mode);
void OneWire_Pin_Level(OneWire_t* OW, uint8_t Level);
uint8_t OneWire_Pin_Read(OneWire_t* OW);
void OneWire_WriteBit(OneWire_t* OW, uint8_t bit);
#ifdef __cplusplus
}
#endif
#endif /* ONEWIRE_H */