HI2CSend

Syntax:

    HI2CSend data

Command Availability:

Only available for microcontrollers with the hardware I2C or TWI module.

Explanation:

The HI2CSend command will send data through the I2C connection. If in master mode, HI2CSend will send the data immediately. If in slave mode, HI2CSend will wait for the master to request the data before sending.

Note:

This command is also available on microcontrollers with a second hardware I2C port.

    HI2C2Send  data

Example:

This example code retrieves multiple bytes from an EEPROM memory device.

	do
	  HI2CReStart                         ;generate a start signal
	  HI2CSend(eepDev)                    ;indicate a write          ' <<< the HI2CSend instruction
	loop While HI2CAckPollState

	HI2CSend(eepAddr_H)                   ;as two bytes
	HI2CSend(eepAddr)
	HI2CReStart
	HI2CSend(eepDev + 1)                  ;indicate a read

	eep_i = 0                             ;loop consecutively
	do while (eep_i < eepLen)             ;these many bytes
	  eep_j = eep_i + 1                   ;arrays begin at 1 not 0
	  if (eep_i  < (eepLen - 1)) then
		HI2CReceive(eepArray(eep_j), ACK)  ;more data to get
	  else
		HI2CReceive(eepArray(eep_j), NACK ) ;send NACK on last byte
	  end if
	  eep_i++                             ;get set for next
	loop
	HI2CStop

Key line: HI2CSend(eepDev) — sends the device address byte with the write bit set; the loop retries until the device ACKs (HI2CAckPollState returns false).

See Also:

  • HI2CStart / HI2CRestart — generating the start/restart condition used above
  • HI2CReceive — the receiving counterpart used later in the example
  • HI2CStop — ending the transaction
  • HI2CAckPollState — checking for a device ACK, as polled by the retry loop above
  • HI2CMode — selecting master/slave mode before sending

Supported in <HI2C.H>