Symbian3/PDK/Source/GUID-9986DCC6-EE73-59FB-BDAC-9B09DC64FBCE.dita
author Dominic Pinkman <Dominic.Pinkman@Nokia.com>
Thu, 11 Mar 2010 18:02:22 +0000
changeset 3 46218c8b8afa
parent 1 25a17d01db0c
permissions -rw-r--r--
week 10 bug fix submission (SF PDK version): Bug 1892, Bug 1897, Bug 1319. Also 3 or 4 documents were found to contain code blocks with SFL, which has been fixed. Partial fix for broken links, links to Forum Nokia, and the 'Symbian platform' terminology issues.

<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2007-2010 Nokia Corporation and/or its subsidiary(-ies) All rights reserved. -->
<!-- This component and the accompanying materials are made available under the terms of the License 
"Eclipse Public License v1.0" which accompanies this distribution, 
and is available at the URL "http://www.eclipse.org/legal/epl-v10.html". -->
<!-- Initial Contributors:
    Nokia Corporation - initial contribution.
Contributors: 
-->
<!DOCTYPE concept
  PUBLIC "-//OASIS//DTD DITA Concept//EN" "concept.dtd">
<concept xml:lang="en" id="GUID-9986DCC6-EE73-59FB-BDAC-9B09DC64FBCE"><title>Client of IIC Master Channel Implementation Tutorial</title><prolog><metadata><keywords/></metadata></prolog><conbody><p>This document describes a simple implementation of an IIC client using the master channel functionality. </p> <section><title>Purpose</title> <p>This tutorial explains how to use the IIC master side API to communicate with a peripheral using half-duplex. </p> <p><b>Intended Audience</b> </p> <p>Device driver writers. </p> <p><b>Required Background</b> </p> <p>Before you start, you must: </p> <ul><li id="GUID-E339C63B-A5B2-535A-9EEB-E42F5913695F"><p>Have installed the platform specific implementation of IIC channels that is required to support the IIC API. </p> </li> <li id="GUID-BF87DA07-52AD-5B46-BA69-61AB6E23CA38"><p>The IIC.dll has been included in the kernel.iby file. </p> </li> <li id="GUID-DE66833F-6DE6-5068-BE7B-A748ABFE9915"><p>Include the iic.h and iic_channel.h header files. </p> </li> </ul> <p> <note>Note:</note> The code example fragments are for synchronous operation. For asynchronous operation, the buffers must be allocated on the heap. </p> </section> <section><title>Implementing IIC user-side</title> <p>The Following tasks will be covered in this tutorial: </p> <ul><li id="GUID-FF0DF82E-6D88-5C58-844C-2E1036816FAD"><p>Performing read/write operations. </p> </li> </ul> <p><b>Basic Procedure</b> </p> <p>The high level steps to performing read/write operations are shown here: </p> <ol id="GUID-0080AB2C-6DC5-5128-B2FB-7E1D81859F7B"><li id="GUID-3C607C4B-20B8-5ED7-8A82-BF75CC2C5286"><p>First set the bus type, the channel number and the slave address. </p> <p>An example of this, is : </p> <codeblock id="GUID-A66F8DD0-A870-5210-9AAB-D3B837D0E831" xml:space="preserve">// Configure the port.
    busId.SetBusType(DIicBusChannel::ESpi);        // Specify which multi-wire bus is to be used. in this example, SPI.
    busId.SetChanNum(0);                                                                                    // Set the channel number.
    busId.SetSlaveAddr(13);                                                                     // Set the slave address. </codeblock> </li> <li id="GUID-27D5A0ED-818B-51AE-BB48-32929DB3E134"><p>Configure the channel. </p> <p>An example of which, is : </p> <codeblock id="GUID-43A34CF2-6324-5026-BC9E-28CE4B8D95A6" xml:space="preserve">// create header - this configures a SPI port.
    const TConfigSpiV01 TestHeader =
        {
        ESpiWordWidth_8,                                                 // Set the word width. In this example, 8 bits.
        260000,                                                                                     // Set the clock speed of the port. In this example, 260KHz.
        ESpiPolarityLowRisingEdge,         // Set the clock mode value. In this example, Active high, odd edges.
        500,                                                                                                 // Set the timeout period. In this example, 500msec.
        EBigEndian,                                                                     // Set which endian is to be used. In this example, BigEndian is used.
        EMsbFirst,                                                                         // Set which bit order is to be used. In this example, the Msb is first.
        0,                                                                                                         // Set the number of transaction wait cycles. In this example, 0.
        ESpiCSPinActiveLow                                         // Set the Chip select active mode. In this example, chip select is active low.
        };</codeblock> </li> <li id="GUID-6748A0B1-6A37-50AB-9D93-A230F419059A"><p>Make linked lists of the transfers that are to be carried out. </p> <p>An example of this, is : </p> <codeblock id="GUID-C112BD53-C69C-595B-8452-82826AEC37B3" xml:space="preserve">// Set the transaction header.
    TPckgBuf&lt;TConfigSpiV01&gt; header(TestHeader);

    // Set up a transmit transaction.
    // This txTransfer buffer acts as the start of the transaction linked list.
    TIicBusTransfer txTransfer(TIicBusTransfer::EMasterWrite, 8, &amp;txTransferBuf);

    // Set up a receive transaction.
    TIicBusTransfer rxTransfer(TIicBusTransfer::EMasterRead, 8, &amp;rxTransferBuf);

    // Add to the receive transaction to the transaction linked list.
    txTransfer.LinkAfter(&amp;rxTransfer);

    // Create a transaction using header and the transaction linked list.
    TIicBusTransaction transaction(&amp;header, &amp;txTransfer);</codeblock> </li> <li id="GUID-B750A2D0-CFE2-584F-B2CF-5F19293B88BC"><p>Use the QueueTransaction method, specifying the configuration of the port and the start location of the transaction linked lists. This queues the transactions onto the selected IIC channel. </p> <p>An example of this, is : </p> <codeblock id="GUID-5F929F5F-D8B3-5471-B65A-86D5D9DC8D7C" xml:space="preserve">// Queue the transaction.
 // Once this command has been executed, the value of r should be KErrNone.
    r = IicBus::QueueTransaction(busId.GetConfig(), &amp;transaction);</codeblock> </li> </ol> </section> </conbody><related-links><link href="GUID-F461CBB3-F8D1-5961-AD51-5741143A1CB1.dita"><linktext>Client
                of Slave User Side Tutorial</linktext> </link> <link href="GUID-C0803997-F111-52C8-9F18-9138F02BCED5.dita"><linktext>IIC
                Implementation Tutorial</linktext> </link> <link href="GUID-B2F86F54-EF50-56DB-ADF7-15325AC9324D.dita"><linktext>IIC Guide</linktext> </link> <link href="GUID-99FC067C-0AED-5373-AF63-8DB7FF5C1F7E.dita"><linktext>SPI Technology Guide</linktext> </link> <link href="GUID-3A30DA16-ECA8-5639-A9DC-6BE2AD55420B.dita"><linktext>I2C Technology Guide</linktext> </link> </related-links></concept>