@@ -72,6 +72,7 @@ struct ds18b20_data {
7272};
7373
7474static int ds18b20_configure (const struct device * dev );
75+ static int ds18b20_read_scratchpad (const struct device * dev , struct ds18b20_scratchpad * scratchpad );
7576
7677/* measure wait time for 9-bit, 10-bit, 11-bit, 12-bit resolution respectively */
7778static 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,
104105 struct ds18b20_data * data = dev -> data ;
105106 const struct ds18b20_config * cfg = dev -> config ;
106107 const struct device * bus = cfg -> bus ;
108+ int ret ;
107109 uint8_t sp_data [4 ] = {
108110 DS18B20_CMD_WRITE_SCRATCHPAD ,
109111 scratchpad .alarm_temp_high ,
110112 scratchpad .alarm_temp_low ,
111113 scratchpad .config
112114 };
113115
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 ;
115132}
116133
117134static int ds18b20_read_scratchpad (const struct device * dev ,
0 commit comments