Online Development Notebook > Index > Programming Overview > Device Commands > Wire2Data

Wire2Data - Send 2-wire data (8 or 9 bits) to the 2-wire port, receive data


VERSION 3.35+ of the firmware, VERSION 65+ of the DLL

Description:

This function sends data to the 2-wire port. Eight bits of data are clocked out the 2-wire port. The 2-wire data line toggles to match the bits in the command as the clock line pulses high. Optionally a 9th data bit can be sent. For I2C this command is good for transmitting⁄receiving a byte (8 bits) of data, as well as an optional 'ACK' bit.

Command Syntax: (USBm.dll)

USBm_Wire2Data( device, dataarray )

The USBm_Wire2Data function syntax has these parts:

Part Description
device A zero-based index to address the appropriate USB device.
dataarray A byte array that contains the specific settings of this command, the data to send, and the data received. The minimum size of this array must be 6 bytes.

Remarks:

Data is shifted onto the 2-wire data line most-significant bit first. The data bit is set on the data line, the clock line is set high. The data line is read (the device that you are communicating with may be pulling that line low) and the clock line is set low. The 8 bits of the data byte are sent this way. The 9th bit would be sent after the data byte is finished. The 9th bit is optional.

The data array contains data for this command. Byte 0 is set to 0. Byte 1 bit 0 of the array is the value (1 or 0) of the 9th bit. Byte 1 bit 1 is a bit that suppresses 9th bit if set to 1, but allows the 9th bit of set to 0. The 9th bit is often used in I2C communication as the 'ACK' bit. Byte 2 of the data array is the 8 bits of data to send in the command.

After completion of this command, byte 0 of the array will contain the 8-bit value read from the 2-wire data port. Byte 1 bit 0 will contain the value of the 9th bit.

Performing a read of the 2-wire bus is done by setting the byte value to all 1. (FFh or 0xFF) This is essentially writing 1s to the data line, which in the open collector⁄drain hardware configuration of the 2-wire bus lines will let the 2-wire device that you are talking to pull the lines low for the 0s that it wishes to transmit.


VB Declaration

Public Declare Function USBm_Wire2Data _
    Lib "USBm.dll" _
        (ByVal device As Byte, _
               ByRef dataarray As Byte) _
    As Integer

VB Example

Dim dataaray(8) As Byte

    dataarray(0) = 0
    dataarray(1) = 1
    dataarray(2) = &H10
    USBm_Wire2Data 0, dataarray(0)

This code fragment sends a byte of value 10h to device 0, plus the 9th bit set as 1. Dataarray(0) will contain the value read from the bus, which will be the 10h sent, unless there is bus contention. Bit 0 of dataarray(1) will have the value of the 9th bit. A 1 was sent for this bit, and the returned 9th bit will be a 1, unless the 2-wire device pulled that bit to a 0.


C Prototype

int USBm_Wire2Data( unsigned char device, unsigned char *dataarray );

C Example

 


RobotBASIC

-TBD-


Raw Command  Format:

Byte Number Description
0 19h: Wire2Data
1 00h
2 Bit 0: State of the 9th bit. Transmitting a 0 will pull the 2-wire data line to ground. Transmitting a 1 will allow that line to float high, or be pulled to ground by the 2-wire device.
Bit 1: 9th bit suppression. Setting this bit to 1 stops the 9th bit. (Only 8 bits transmitted) Setting the bit to 0 allows the 9th bit to be sent.
3 Byte (8 bits) of data to shift onto the data line.
4 <not used>
5 <not used>
6 <not used>
7 <not used>

Raw Command  Format Details:

Byte 0 contains the command. Byte 1 contains 00h. Byte 2, bit 0 is the value for the 9th bit. Byte 2 bit 1 controls the 9th bit - set to 0 to transmit the 9th bit. Byte 3 is the data byte to shift out the 2-wire bus. Byte 4 through byte 7 are unused.

Raw Command Response Format:

Byte Number Description
0 19h: Wire2Data
1 Data read from line
2 Bit 0: The value of the 9th bit
3 <not used>
4 <not used>
5 <not used>
6 <not used>
7 <not used>

Raw Command Response Format Details:

Byte 0 contains the command. Byte 1 contains the byte read from the 2-wire bus. Byte 2 contains the value of the 9th bit. Byte 3 through byte 7 are unused.

Raw Command Example Usage:

-TBD-


Hardware:  U401 USB Interface    U421 USB Interface   U451 USB Interface

Programming:  USBm DLL Programming    Download Files

Application Notes:  U4x1 Application Notes    Misc Applications and Information    FAQ

While every effort has been made to make sure that the information posted on this site is correct, the author can not be held liable for any damages whatsoever for losses as a result of the application of this information. Use this information at your own risk.

USBmicro can design your custom and semi-custom USB product. Email about USB design can be directed to " Robert " at usbmicro.com.

Copyright © USBmicro, L.L.C., 2002-2010

Previous  |  Next ]     [ Up  |  First  |  Last ]     (Article 79 of 126)

This page is created with TreePad