Im playing about with the DS18B20 using the oneWire library. I am trying to change the resolution of the sensor to ,say 11bit and I'm a bit stuck:
I understand to do this I need to write to the scratchpad with "4E write to scratch pad", and that this addresses starting at the TH, then TL users locations (where I can put more of less anything), and then where I need to write 5F into the configuration register to set to 11bit resolution.
What I need help with is, how do I do that, what does the syntax look like to do this ?
ds.write(0x4E); //write to scratch pad
... but then what??
ds.reset();
I know I can do this with the Dallas library, but I'm trying to cut down on included libraries and also learn a bit more. Any pointers and positive stuff would be very useful.
#define ALARM_T_HIGH 2
#define ALARM_T_LOW 3
#define CONFIGURATION 4
// --------------------------------------------------------------------------------------
//
// **********************
// * write_scratchpad *
// **********************
//
// Write device scratchpad
void DallasThermometer::write_scratchpad(uint8_t *device_ROM_code, uint8_t *scratchpad)
{
/* WRITE SCRATCHPAD [4Eh]
It allows to write 3 bytes (DS18S20 only 2 bytes) of data to the scratchpad, 1st byte
is written into the TH register (byte 2 of the scratchpad), 2nd into the TL register
(byte 3), and the 3rd into the configuration register (byte 4; DS18B20 & DS1822 only).
Data must be transmitted least significant bit first. All three bytes must be written
before the master issues a reset, or the data may be corrupted.
*/
this->init(); // initialization (reset presence pulse)
this->match(device_ROM_code); // MATCH ROM command
this->write(DS_WRITE_SCRATCHPAD); // WRITE SCRATCHPAD function command
/* scratchpad sending */
this->write(scratchpad[ALARM_T_HIGH]);
this->write(scratchpad[ALARM_T_LOW]);
if(device_ROM_code[0] != DS18S20)
this->write(scratchpad[CONFIGURATION]);
}