예제 #1
0
static void ds18x20GetAllTemps()
{
	uint8_t i, j;
	uint8_t crc;
	static uint8_t arr[DS18X20_SCRATCH_LEN];

	for (i = 0; i < devCount; i++) {
		if (ds18x20IsOnBus()) {
			ds18x20Select(&devs[i]);
			ds18x20SendByte(DS18X20_CMD_READ_SCRATCH);

			// Control scratchpad checksum
			crc = 0;
			for (j = 0; j < DS18X20_SCRATCH_LEN; j++) {
				arr[j] = ds18x20GetByte();
				crc = _crc_ibutton_update(crc, arr[j]);
			}

			if (crc == 0) {
				// Save first 2 bytes (temperature) of scratchpad
				for (j = 0; j < DS18X20_SCRATCH_TEMP_LEN; j++)
					devs[i].sp[j] = arr[j];
			}
		}
	}

	return;
}
예제 #2
0
파일: ds18x20.c 프로젝트: WiseLord/fm7segm
void ds18x20GetAllTemps()
{
	uint8_t i, j;

	uint8_t arr[9];

	for (i = 0; i < devCount; i++) {
		if (ds18x20IsOnBus()) {
			ds18x20Select(&devs[i]);
			ds18x20SendByte(DS18X20_CMD_READ_SCRATCH);

			for (j = 0; j < 9; j++)
				arr[j] = ds18x20GetByte();

			if (!calcCRC8(arr, sizeof(arr))) {
				for (j = 0; j < 9; j++)
					devs[i].sp[j] = arr[j];
			}
		}
	}

	return;
}