@@ -72,6 +72,7 @@ struct ds18b20_data {
72
72
};
73
73
74
74
static int ds18b20_configure (const struct device * dev );
75
+ static int ds18b20_read_scratchpad (const struct device * dev , struct ds18b20_scratchpad * scratchpad );
75
76
76
77
/* measure wait time for 9-bit, 10-bit, 11-bit, 12-bit resolution respectively */
77
78
static const uint16_t measure_wait_ds18b20_ms [4 ] = { 94 , 188 , 376 , 750 };
@@ -104,14 +105,30 @@ static int ds18b20_write_scratchpad(const struct device *dev,
104
105
struct ds18b20_data * data = dev -> data ;
105
106
const struct ds18b20_config * cfg = dev -> config ;
106
107
const struct device * bus = cfg -> bus ;
108
+ int ret ;
107
109
uint8_t sp_data [4 ] = {
108
110
DS18B20_CMD_WRITE_SCRATCHPAD ,
109
111
scratchpad .alarm_temp_high ,
110
112
scratchpad .alarm_temp_low ,
111
113
scratchpad .config
112
114
};
113
115
114
- return w1_write_read (bus , & data -> config , sp_data , sizeof (sp_data ), NULL , 0 );
116
+ ret = w1_write_read (bus , & data -> config , sp_data , sizeof (sp_data ), NULL , 0 );
117
+ if (ret != 0 ) {
118
+ return ret ;
119
+ }
120
+
121
+ ret = ds18b20_read_scratchpad (dev , & scratchpad );
122
+ if (ret != 0 ) {
123
+ return ret ;
124
+ }
125
+
126
+ if ((sp_data [3 ] & DS18B20_RESOLUTION_MASK ) !=
127
+ (scratchpad .config & DS18B20_RESOLUTION_MASK )) {
128
+ return - EIO ;
129
+ }
130
+
131
+ return 0 ;
115
132
}
116
133
117
134
static int ds18b20_read_scratchpad (const struct device * dev ,
0 commit comments