Test 1-wire , working wtih parasite power and few sensors with mixed power supply.

Dependencies:   mbed

Committer:
rainerraul
Date:
Wed May 18 10:09:56 2022 +0000
Revision:
1:f8aa0ff8d04a
Parent:
0:1197076b78f4
test

Who changed what in which revision?

UserRevisionLine numberNew contents of line
macraj 0:1197076b78f4 1 typedef unsigned char BYTE;
macraj 0:1197076b78f4 2
macraj 0:1197076b78f4 3
macraj 0:1197076b78f4 4 #define MAXSENSORS 8
macraj 0:1197076b78f4 5 // rom-code size including CRC
macraj 0:1197076b78f4 6 #define OW_ROMCODE_SIZE 8
macraj 0:1197076b78f4 7
macraj 0:1197076b78f4 8
macraj 0:1197076b78f4 9
macraj 0:1197076b78f4 10
macraj 0:1197076b78f4 11 BYTE ow_reset(void);
macraj 0:1197076b78f4 12 BYTE ow_rom_search( BYTE diff, BYTE *id );
macraj 0:1197076b78f4 13 void ow_command( BYTE command, BYTE *id );
macraj 0:1197076b78f4 14 //void DS18X20_find_sensor(BYTE *diff, BYTE id[]);
macraj 0:1197076b78f4 15 BYTE DS18X20_get_power_status(uint8_t id[]);
macraj 0:1197076b78f4 16
macraj 0:1197076b78f4 17 extern void DS18X20_show_id_uart( uint8_t *id, size_t n );
macraj 0:1197076b78f4 18 extern void DS18X20_find_sensor(uint8_t *diff, uint8_t id[]);
macraj 0:1197076b78f4 19 extern uint8_t DS18X20_get_power_status(uint8_t id[]);
macraj 0:1197076b78f4 20 extern uint8_t DS18X20_start_meas( uint8_t with_external, uint8_t id[]);
macraj 0:1197076b78f4 21 extern uint8_t DS18X20_read_meas(uint8_t id[], uint8_t *subzero, uint8_t *cel, uint8_t *cel_frac_bits);
macraj 0:1197076b78f4 22 extern uint8_t DS18X20_read_meas_single(uint8_t familycode, uint8_t *subzero, uint8_t *cel, uint8_t *cel_frac_bits);
macraj 0:1197076b78f4 23 extern uint8_t DS18X20_meas_to_cel( uint8_t fc, uint8_t *sp, uint8_t* subzero, uint8_t* cel, uint8_t* cel_frac_bits);
macraj 0:1197076b78f4 24 extern uint16_t DS18X20_temp_to_decicel(uint8_t subzero, uint8_t cel, uint8_t cel_frac_bits);
macraj 0:1197076b78f4 25 extern int8_t DS18X20_temp_cmp(uint8_t subzero1, uint16_t cel1, uint8_t subzero2, uint16_t cel2);
macraj 0:1197076b78f4 26
macraj 0:1197076b78f4 27
macraj 0:1197076b78f4 28 extern void ow_parasite_enable(void);
macraj 0:1197076b78f4 29 extern void ow_parasite_disable(void);
macraj 0:1197076b78f4 30
macraj 0:1197076b78f4 31 #define DEBUG 1
macraj 0:1197076b78f4 32
macraj 0:1197076b78f4 33 #define ONEWIRE_PIN p12
macraj 0:1197076b78f4 34
macraj 0:1197076b78f4 35
macraj 0:1197076b78f4 36 #define OW_MATCH_ROM 0x55
macraj 0:1197076b78f4 37 #define OW_SKIP_ROM 0xCC
macraj 0:1197076b78f4 38 #define OW_SEARCH_ROM 0xF0
macraj 0:1197076b78f4 39
macraj 0:1197076b78f4 40
macraj 0:1197076b78f4 41 #define OW_SHORT_CIRCUIT 0xFF
macraj 0:1197076b78f4 42 #define OW_SEARCH_FIRST 0xFF // start new search
macraj 0:1197076b78f4 43 #define OW_PRESENCE_ERR 0x01
macraj 0:1197076b78f4 44 #define OW_DATA_ERR 0xFE
macraj 0:1197076b78f4 45 #define OW_LAST_DEVICE 0x00 // last device found
macraj 0:1197076b78f4 46 // 0x01 ... 0x40: continue searching
macraj 0:1197076b78f4 47
macraj 0:1197076b78f4 48 // rom-code size including CRC
macraj 0:1197076b78f4 49 #define OW_ROMCODE_SIZE 8
macraj 0:1197076b78f4 50
macraj 0:1197076b78f4 51
macraj 0:1197076b78f4 52 #define DS18X20_POWER_PARASITE 0x00
macraj 0:1197076b78f4 53 #define DS18X20_POWER_EXTERN 0x01
macraj 0:1197076b78f4 54
macraj 0:1197076b78f4 55 /* DS18X20 specific values (see datasheet) */
macraj 0:1197076b78f4 56 #define DS18S20_ID 0x10
macraj 0:1197076b78f4 57 #define DS18B20_ID 0x28
macraj 0:1197076b78f4 58 #define DS18X20_CONVERT_T 0x44
macraj 0:1197076b78f4 59 #define DS18X20_READ 0xBE
macraj 0:1197076b78f4 60 #define DS18X20_WRITE 0x4E
macraj 0:1197076b78f4 61 #define DS18X20_EE_WRITE 0x48
macraj 0:1197076b78f4 62 #define DS18X20_EE_RECALL 0xB8
macraj 0:1197076b78f4 63 #define DS18X20_READ_POWER_SUPPLY 0xB4
macraj 0:1197076b78f4 64
macraj 0:1197076b78f4 65 #define DS18X20_OK 0x00
macraj 0:1197076b78f4 66 #define DS18X20_ERROR 0x01
macraj 0:1197076b78f4 67 #define DS18X20_START_FAIL 0x02
macraj 0:1197076b78f4 68 #define DS18X20_ERROR_CRC 0x03
macraj 0:1197076b78f4 69
macraj 0:1197076b78f4 70
macraj 0:1197076b78f4 71 #define DS18B20_CONF_REG 4
macraj 0:1197076b78f4 72 #define DS18B20_9_BIT 0
macraj 0:1197076b78f4 73 #define DS18B20_10_BIT (1<<5)
macraj 0:1197076b78f4 74 #define DS18B20_11_BIT (1<<6)
macraj 0:1197076b78f4 75 #define DS18B20_12_BIT ((1<<6)|(1<<5))
macraj 0:1197076b78f4 76
macraj 0:1197076b78f4 77 // indefined bits in LSB if 18B20 != 12bit
macraj 0:1197076b78f4 78 #define DS18B20_9_BIT_UNDF ((1<<0)|(1<<1)|(1<<2))
macraj 0:1197076b78f4 79 #define DS18B20_10_BIT_UNDF ((1<<0)|(1<<1))
macraj 0:1197076b78f4 80 #define DS18B20_11_BIT_UNDF ((1<<0))
macraj 0:1197076b78f4 81 #define DS18B20_12_BIT_UNDF 0
macraj 0:1197076b78f4 82
macraj 0:1197076b78f4 83 // conversion times in ms
macraj 0:1197076b78f4 84 #define DS18B20_TCONV_12BIT 750
macraj 0:1197076b78f4 85 #define DS18B20_TCONV_11BIT DS18B20_TCONV_12_BIT/2
macraj 0:1197076b78f4 86 #define DS18B20_TCONV_10BIT DS18B20_TCONV_12_BIT/4
macraj 0:1197076b78f4 87 #define DS18B20_TCONV_9BIT DS18B20_TCONV_12_BIT/8
macraj 0:1197076b78f4 88 #define DS18S20_TCONV DS18B20_TCONV_12_BIT
macraj 0:1197076b78f4 89
macraj 0:1197076b78f4 90 // constant to convert the fraction bits to cel*(10^-4)
macraj 0:1197076b78f4 91 #define DS18X20_FRACCONV 625
macraj 0:1197076b78f4 92
macraj 0:1197076b78f4 93 #define DS18X20_SP_SIZE 9
macraj 0:1197076b78f4 94
macraj 0:1197076b78f4 95 // DS18X20 EEPROM-Support
macraj 0:1197076b78f4 96 #define DS18X20_WRITE_SCRATCHPAD 0x4E
macraj 0:1197076b78f4 97 #define DS18X20_COPY_SCRATCHPAD 0x48
macraj 0:1197076b78f4 98 #define DS18X20_RECALL_E2 0xB8
macraj 0:1197076b78f4 99 #define DS18X20_COPYSP_DELAY 10 /* ms */
macraj 0:1197076b78f4 100 #define DS18X20_TH_REG 2
macraj 0:1197076b78f4 101 #define DS18X20_TL_REG 3