One Byte I2C

pha555

Senior Member
I am writing an application for an I2C slave device which requires a one byte measurement request. This consists of the START, slave address plus 0, a Nack and STOP.

The following is what I would like to do, but this does not work.

HI2COut $28

I note at

http://www.kranenborg.org/ee/picaxe/i2c.htm

that a one byte write is not supported.

Does anyone know if this is still true?

I can bit bang, but would rather use the command if it is supported.

Thanks.

Peter Anderson
 

kranenborg

Senior Member
Hello Peter,

According to specs I presume that one-byte should definitely be possible. I think I need to remove my webpage since the information depicted there is really old and incomplete now, I actually had forgotten about its existence ... . The current implementation of writei2c and readi2c (which are deprectated commands and replaced by the new hi2cin/out) support one-byte commands, so the newer i2c commands should definitely support them too, me thinks ...

/Jurjen
 
Last edited:

hippy

Ex-Staff (retired)
I believe all I2CREAD/I2CWRITE and HI2CIN/HI2COUT commands prefix the slave address and then can read or write at least one byte of location address / data.

Perhaps the easiest solution is to bit-bang the I2C ?

However; if this single byte initiates the measurement then does it not also receive some data back via I2C ? Perhaps it can be done by adjusting the HI2CSETUP device address and using an I2CREAD or HI2CIN command without a location address ?

Perhaps let us know what the I2C device is or provide a link to its datasheet.
 
Last edited by a moderator:

Technical

Technical Support
Staff member
HI2COut $28
Hi2cout should work on one data byte - simply don't forget your brackets!
HI2COut ($28)

This gives a one byte write, but that is not the same as what you have asked for, which is an unusual '0 byte' of data write, which doesn't seem to a valid i2c transaction at all (according to Microchip's interpretation):

The I2C bus specifies three message protocols;
• Single message where a master writes data to a
slave.
• Single message where a master reads data from
a slave.
• Combined message where a master initiates a
minimum of two writes, or two reads, or a
combination of writes and reads, to one or more
slaves.
HI2COut ($28) is
START, slave address plus 0, an ack, 0X28, nack and STOP
not the desired
START, slave address plus 0, a Nack and STOP.


Normally you would have to actually receive the single byte of data requested??? - which would be

HI2CIn (b1) which is
START, slave address plus 1, an ack, receive b1, nack and STOP

If you really need what you do (which is very unusual) then you can probably just force that byte sequence by loading the internal SFR registers via pokesfr's (setup the i2c bus as normal first using hi2csetup)

Set Bit SEN of the SSP1CON2, via pokesfr to SSP1CON2
Write byte to SSP1BUF, via pokesfr to SSP1BUF
Set Bit PEN of the SSP1CON2, via pokesfr to SSP1CON2

The pokesfr will take longer than the actual i2c, so probably no need to worry about timing.
 
Last edited:

pha555

Senior Member
Thanks.

The device is a Honeywell HIH-6130 Humidity / Temp Sensor.

http://www.mouser.com/HoneywellHumidicon/?cm_sp=homepage-_-newproducts-_-Honeywell+HumidIcon+HumidityTemperature+Sensor

I just can't find the docs on the Honeywell site.

The measurement sequence is under I2C Communications. Para 2.3 is the Meas Request. The format surprised me.

Programming the EEPROM is under Command Mode Instructions. But, this is for later.

The info you have given me is priceless. I will try the peeksfr / pokesfr and if all else fails will bit bang. Will let you know.

Thanks again.

Peter Anderson
 

Technical

Technical Support
Staff member
$28 is probably not correct, as the small prints say 01 -7F is available upon special request. So they are talking about $27 being a 7 bit address - that needs to be shifted left to become the full i2c 8 bit address.

0010 0111 << 1 = 0100 1110 = $4E

We would just try

hi2csetup i2cmaster, $4E, i2cbyte, i2cslow
hi2cout ($4E)
pause 37 ; required_time
hi2cin (hum_high, hum_low, temp_high, temp_low)
;Don't forget to shift temp value right by dividing word value by 4

The hi2cout would be start - $4E - ack - $4E - nack - stop, not exactly the same as figure 2 but with a bit of luck may work!
 
Last edited:

Goeytex

Senior Member
@Peter

Honeywell has the worst site for finding & retrieving technical docs.

I got some of these a while back for testing and have the technical docs on my hard drive.
This includes the datasheet, and two I2C Technical Notes.

Give me an Email Address and I'll send them to you.

The Forum SW finally allowed me to attach files. Was broken all night.
 

Attachments

Last edited:
Top