Take me home
Projects:
CDi4.P8 Flowmeter, Keller Communicator
LD Series Pressure Transmitters
Keller LD
FlyportPRO
Internet of Things - BME
Internet Enabled, Tomato Garden Watering Thing
ZDL Potential Boards
P5 Evolution Project
SCi:
CDi3.FTe Submersible, Universal Gas-Field Controller
Keller Digital Pressure Transducers/Transmitters
Burkert Solenoid Modifications
PDL/CDi History: Pembina Lake Erie Datalogger
LD Series Pressure Transmitters
Interfacing the Keller I2C LD series transmitters
Keller LD (Laser Digital) Series


Code:
#include "9ld.h"
#include "i2c.h"

float Pmin, Pmax;				
unsigned char ZSSCget[5]; 						//array to receive data frame

BYTE get_PnT_GPIO(BYTE ADDR, BYTE MODE);
BYTE ld_busy(BYTE ADDR);

//CODE**********************************************************************
BYTE get_PnT_GPIO(BYTE ADDR, BYTE MODE)
{
float ZI_pressure; 								//single float (IEEE 754) in bar
float ZI_temperature; 							//single float (IEEE 754) in degC
BYTE ZI_status=0; 								//8 bit status variable

union {
FL floatingpoint;
UL twotimesU16;
      } cast;

BYTE ZSSCerror;

if (MODE) {                 					//Only have to read Pmin and Pmax once, every power up,
												//the code here can be used to emulate function 48 of the
												//Keller protocol used in the 33X RS485 transmitters...
												//Function 48: Initialize and Release

												//Read Pmin from 16bit locations 0x13 (MSB) and 0x14 (LSB)
												//Cast into 32bit (IEEE 754) single float
WriteI2CAddressed(ADDR, 0x13);
while (ld_busy(ADDR)) wait; 					//poll ~9mS 
ReadI2CAddressed(ADDR, (char*)ZSSCget,3);
cast.twotimesU16 = (((UL)(ZSSCget[1]))<<24) + (((UL)(ZSSCget[2]))<<16);
WriteI2CAddressed(ADDR, 0x14);
while (ld_busy(ADDR)) wait; 					//poll ~9mS
ReadI2CAddressed(ADDR, (char*)ZSSCget,3);
cast.twotimesU16 += (((UL)(ZSSCget[1]))<<8) + ((UL)(ZSSCget[2]));
Pmin=cast.floatingpoint;
												//Read Pmax from 16bit locations 0x15 (MSB) and 0x16 (LSB)
												//Cast into 32bit (IEEE 754) single float
WriteI2CAddressed(ADDR, 0x15);
while (ld_busy(ADDR)) wait; 					//poll ~9mS
ReadI2CAddressed(ADDR, (char*)ZSSCget,3);
cast.twotimesU16 = (((UL)(ZSSCget[1]))<<24) + (((UL)(ZSSCget[2]))<<16);
WriteI2CAddressed(ADDR, 0x16);
while (ld_busy(ADDR)) wait; 					//poll ~9mS
ReadI2CAddressed(ADDR, (char*)ZSSCget,3);
cast.twotimesU16 += (((UL)(ZSSCget[1]))<<8) + ((UL)(ZSSCget[2]));
Pmax=cast.floatingpoint;
}  


WriteI2CAddressed(ADDR, 0xAC);  				//request new conversion
while (ld_busy(ADDR)) wait; 					//poll ~9mS
ReadI2CAddressed(ADDR, (char*)ZSSCget,5);       //read results (5 bytes)

												//interpret
ZI_status      =                                               ZSSCget[0]; //status
ZI_pressure    = (float) ( (((US) (ZSSCget[1]))<<8) + (US) (ZSSCget[2]) ); //P[U16]
ZI_temperature = (float) ( (((US) (ZSSCget[3]))<<8) + (US) (ZSSCget[4]) ); //T[U16]

ZI_pressure    = (ZI_pressure-16384) * (Pmax-Pmin)/32768+Pmin;             //P[bar]
ZI_temperature = (((((US)ZI_temperature)>>4)-24)*0.05)-50;                 //T[C]

chs[1].result = (ZI_pressure-Pmin)*14.5;        //Convert bar  to psi
chs[4].result= (ZI_temperature * 9/5)+32.0F; 	//Convert degC to degF
return ZSSCerror;
}



BYTE ld_busy(BYTE ADDR)
{

BYTE st;
BYTE ts[3];
ReadI2CAddressed(ADDR, (char*)ts, 1);			//read the status byte
st = ts[0] & 0x20;      						//bit 5, 1=busy
if (st) return 1;
return 0;
}

Contact:
SCi.RS Cloud (Mirror of singlechips.com)SingleChips Greece Cloud (Mirror of SingleChips Greece)NuovoPicus CanadaXYZ CanadaSingleChips GreeceSCi.RSCensors!!!Censors!!!Censors!!!
Copyright © 1991-2024 AdamG Last Update: Saturday, June 20, 2020 9:08:13 PM