Name:
hi2cout
Syntax:

HI2COUT location,(variable,...)

HI2COUT (variable,...)

HI2COUT [newslave],location,(variable,...) (X2 parts only)

HI2COUT [newslave],(variable,...) (X2 parts only)

Location - is a variable/constant specifying a byte or word address.

Variable(s) - contains the data byte(s) to be written.

Newslave - is an optional new slave address for this (and all future) commands (X2 parts only)

Description:

Write to i2c bus when acting as an i2c master device.

Use of i2c parts is covered in more detail in the separate 'i2c Tutorial' datasheet.

This command is used to write byte data to an i2c slave. Location defines the start address of the data to be written, although it is also possible to write more than one byte sequentially (if the i2c device supports sequential writes).

Location must be a byte or word as defined within the hi2csetup command. A hi2csetup command must have been issued before this command is used. The hi2csetup commands sets the default slave address for this command. However when addressing multiple parts it may be necessary to repeatedly change the default slave address. This can be achieved via the optional [newslave] variable.

Applies To:
08M2, 14M2, 18M2, 18X, 20M2, 20X2, 28X1, 28X2, 40X1, 40X2
See Also:
Related Create:
Share:
Print:

Example of how to use DS1307 Real Time Clock

This program sets the time and date in a DS1307 Real Time Clock. Note the data is sent/received in BCD format. Note that seconds, mins etc are variables that need defining e.g. symbol seconds = b0 etc.

Code Example:
		hi2csetup i2cmaster, %11010000, i2cslow, i2cbyte		; set PICAXE as master and DS1307 slave address

; write time and date e.g. to 11:59:00 on Thurs 25/12/03

start_clock:	let seconds = $00						; 00 Note all BCD format
		let mins = $59							; 59 Note all BCD format
		let hour = $11							; 11 Note all BCD format
		let day = $03							; 03 Note all BCD format
		let date = $25							; 25 Note all BCD format
		let month = $12							; 12 Note all BCD format
		let year = $03							; 03 Note all BCD format
		let control = %00010000						; Enable output at 1Hz
		hi2cout 0,(seconds,mins,hour,day,date,month,year,control)
		end
Copy Code Submit an Example

Submit Your Own Code!

You must be logged in to submit code examples. Login now.

Comments

  • Posted by Yoppy

    I'm using a PICAXE (20M2) to control a Sparkfun i2c display (https://www.sparkfun.com/products/11443).

    I noticed that when using this command to control the display, it seems to use the location parameter as an actual data byte, messing up the displayed value:

    hi2cout 0, ("x", "0", "x", "0")

    but using it without the location does work:

    hi2cout ("x", "0", "x", "0")

    I'm not sure why that is, but leaving out the location parameter seems to work so I'll just leave it like that. Or doesn't i2c see this as something different on protocol level? Which would mean that some i2c devices really must not be used with a location parameter.

  • Posted by Yoppy

    The description says: "This can be achieved via the optional [newslave] variable."

    But the syntax says that's only available on X2 parts. Does that mean you need to do explicit hi2csetup commands on non-X2 parts to switch between different slaves? That's not expained clearly on this or the hi2csetup page.

  • Posted by hippy

    On parts which do not support [newslave] addresses a 'hi2csetup' command must be issued to communicate with a differently addressed slave.

  • Login to leave a comment.