// mode: 0 = temperature; 1 = humidity
unsigned short int SHT15::getraw (unsigned short int * p, unsigned short int mode) {
		unsigned short int i = 0;
		txbegin ();
		* p = 0;
		mode = mode ? 0x05 : 0x03;
		if (txdata(mode)) return 1;	// write error
		
		while (i < 240) {
			delay (3);
			if (digitalRead (SHT15_DAT) == 0) {
				i = 0;
				break;
				}
			}
			i++;
			
		if (i) return 3; // timeout
		i = rxdata (1);
		*p = (i << 8) | rxdata (0);
		return 0;
		}
Example #2
0
char read(uint8_t address)
{
	//returns the contents of any 1 byte register from any address
	//sets the MSB for every address byte (READ mode)

	char byte;

	address &= 0x7F;

	cbi(CSPORT,CS);
	txdata(address);
	byte = rxdata();
	sbi(CSPORT,CS);

	return byte;
}