//Read digital pressure value
unsigned int I2CreadP_digital(void)
{
// Two bytes have to be read
unsigned char i2c_byte1 =0;
unsigned char i2c_byte2 =0;
/*****
*
* The two most significant bits of the first byte are status bits!
* They don't contain pressure value information.
*
* Encoding of status bits:
* 00: Normal operation, good data packet
* 01: Device in Command Mode
* 10: Stale data: Data that has already been fetched since
* the last measurement cycle.
* 11: Diagnostic condition exists *
*
* For further information see Datasheet of ASIC ZSC31014
*
*******/
unsigned char status =0;
int digital_Pressure =0;
unsigned char i2c_relevant_bits = 0;
// Initialize I2C Connection
i2c_init();
// Start I2C Communication
i2c_start();
// Send Slave Adress+Read-Bit; wait for slave ACK-Bit
send_i2c_byte(0b10100001);
//Read first byte + sending ACK-Bit
//the two MSBs of this byte are status bits!!
i2c_byte1 = i2c_read_ack();
//Read second byte without sending ACK-Bit
i2c_byte2 = i2c_read_nack();
//extract status bits from first byte
strncpy(status, i2c_byte1, 2);
//extract relevant bits for pressure value from first byte
strcpy(i2c_relevant_bits, i2c_byte1 + 2);
//calculate digital pressure value
digital_Pressure = i2c_relevant_bits * 256 + i2c_byte2;
return digital_Pressure;
}
|