Having been in communications since 1962 when NSA recruited me into the Army Security agency and my career after that
as a consultant, WSP communications engineering, WSDOT, and WSCTC consultant, I am particularly interested in how devices talk
So, lacking any reply from TI to questions on protocol, I am looking for myself.
The following Program is not intended to be fancy but gives out some communications protocol
that TI has not published yet! TI has stated their intent to publish the full communications protocol
for the MSP230 communication with the i2c. As written it works on my RPi B
import serial
import binascii
#sample program to read Texas Instruments HDC1000EVM
#initialization and open the port
#possible timeout values:
# 1. None: wait forever, block call
# 2. 0: non-blocking mode, return immediately
# 3. x, x is bigger than 0, float allowed, timeout block call
ser = serial.Serial()
#ser.port = "/dev/ttyUSB0"
#ser.port = "COM4:"
#ser.port = "/dev/ttyACM1"
ser.port = "/dev/serial/by-path/platform-bcm2708_usb-usb-0:1.2:1.0"
ser.baudrate = 115200
ser.bytesize = serial.EIGHTBITS #number of bits per bytes
ser.parity = serial.PARITY_NONE #set parity check: no parity
ser.stopbits = serial.STOPBITS_ONE #number of stop bits
#ser.timeout = None #block read
#ser.timeout = 1 #non-block read
ser.timeout = 2 #timeout block read
ser.xonxoff = False #disable software flow control
ser.rtscts = False #disable hardware (RTS/CTS) flow control
ser.dsrdtr = False #disable hardware (DSR/DTR) flow control
ser.writeTimeout = 2 #timeout for write
try:
ser.open()
except Exception as e:
print ("error open serial port: " + str(e))
exit()
if ser.isOpen():
try:
ser.flushInput() #flush input buffer, discarding all its contents
ser.flushOutput()#flush output buffer, aborting current output
#and discard all that is in buffer
#write data
ser.write(serial.to_bytes([0x4C,0x12,0x01,0x00,0x03,0x40,0xFB,0x02,0x7a]))
response = ser.readline()
print("read Serial Number MSB = : 0x" + str(binascii.hexlify(response[7])) + str(binascii.hexlify(response[8])))
ser.write(serial.to_bytes([0x4C,0x12,0x01,0x00,0x03,0x40,0xFc,0x02,0x11]))
response = ser.readline()
print("read Serial Number MID = : 0x" + str(binascii.hexlify(response[7])) + str(binascii.hexlify(response[8])))
ser.write(serial.to_bytes([0x4C,0x12,0x01,0x00,0x03,0x40,0xFd,0x02,0x04]))
response = ser.readline()
print("read Serial Number LSB = : 0x" + str(binascii.hexlify(response[7])) + str(binascii.hexlify(response[8])))
ser.write(serial.to_bytes([0x4C,0x12,0x01,0x00,0x03,0x40,0xFe,0x02,0x3b]))
response = ser.readline()
print("read Manufacturer = :" + str(response[7]) + str(response[8]))
ser.write(serial.to_bytes([0x4C,0x12,0x01,0x00,0x03,0x40,0xFF,0x02,0x2e]))
response = ser.readline()
print("read Device ID = : 0x" + str(binascii.hexlify(response[7])) + str(binascii.hexlify(response[8])))
ser.write(serial.to_bytes([0x33]))
numOfLines = 0
while True:
response = ser.readline()
if (str(response).find(",") == -1):
print("start data: " + str(response))
else:
print(" Temperature: " + str(("{0:.2f}".format(((float(int((str(response).split(',')[0]),16))/float(65536)) * 165) -40)))+ u"\u00B0" + "C")
print(" Temperature: " + str(("{0:.2f}".format((((((float(int((str(response).split(',')[0]),16))/float(65536)) * 165) -40) * 9) / 5) + 32)))+ u"\u00B0" + "F")
print("Relative Humidity: " + str(("{0:.2f}".format((float(int((str(response).split(',')[1]),16))/float(65536)) * 100)))+ "%")
numOfLines = numOfLines + 1
if (numOfLines > 10):
#ser.write(bytes(44))
ser.write(serial.to_bytes([0x34]))
response = ser.readline()
print("read data: " + str(response))
break
ser.close()
except Exception as e1:
print ("error " + str(e1))
#ser.write(bytes(44))
ser.write(serial.to_bytes([0x34]))
response = ser.readline()
print("last data: " + str(response))
ser.close()
else:
print ("cannot open serial port ")
Top Comments