<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://community.element14.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>PSoC4 Smarter Life Challenge - DAS Project :Example 7 Energy Efficient I2C Command Dispatcher</title><link>https://community.element14.com/products/devtools/psoc4pioneerkit/w/documents/16290/psoc4-smarter-life-challenge---das-project-example-7-energy-efficient-i2c-command-dispatcher</link><description /><dc:language>en-US</dc:language><generator>Telligent Community 12</generator><item><title>PSoC4 Smarter Life Challenge - DAS Project :Example 7 Energy Efficient I2C Command Dispatcher</title><link>https://community.element14.com/products/devtools/psoc4pioneerkit/w/documents/16290/psoc4-smarter-life-challenge---das-project-example-7-energy-efficient-i2c-command-dispatcher</link><pubDate>Tue, 19 Nov 2013 01:46:21 GMT</pubDate><guid isPermaLink="false">93d5dcb4-84c2-446f-b2cb-99731719e767:ef57117b-232b-421c-96f6-345d2008b15e</guid><dc:creator>bose</dc:creator><comments>https://community.element14.com/products/devtools/psoc4pioneerkit/w/documents/16290/psoc4-smarter-life-challenge---das-project-example-7-energy-efficient-i2c-command-dispatcher#comments</comments><description>Current Revision posted to Documents by bose on 11/19/2013 1:46:21 AM&lt;br /&gt;
&lt;p style="margin:0;"&gt;This example show the implementation of I2C Slave based Command Dispatcher using the PSoC 4 Pioneer Kit with energy efficiency in mind.&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;Here is the Application Schematics:&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span&gt;&lt;a href="https://community.element14.com/resized-image/__size/523x368/__key/communityserver-wikis-components-files/00-00-00-01-62/8561.contentimage_5F00_28540.png"&gt;&lt;img alt="image" src="https://community-storage.element14.com/communityserver-components-secureimagefileviewer/communityserver/wikis/components/files/00/00/00/01/62/8561.contentimage_28540.png-523x368.png?sv=2016-05-31&amp;amp;sr=b&amp;amp;sig=s9Kj5nQfh1X57L7BWPgHdzp39Gignv0eQD2PyuXjRWs%3D&amp;amp;se=2026-06-15T23%3A59%3A59Z&amp;amp;sp=r&amp;amp;_=e65rOM9xMGMBRq2cfwquBg==" style="max-height: 368px;max-width: 523px;" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span&gt;&lt;a href="https://community.element14.com/resized-image/__size/1275x702/__key/communityserver-wikis-components-files/00-00-00-01-62/4341.contentimage_5F00_28541.png"&gt;&lt;img loading="lazy" alt="image" src="https://community-storage.element14.com/communityserver-components-secureimagefileviewer/communityserver/wikis/components/files/00/00/00/01/62/4341.contentimage_28541.png-620x341.png?sv=2016-05-31&amp;amp;sr=b&amp;amp;sig=b04TK2b0AybbwKfYN4YHa%2BPEwtXJei1mGmcpYKszLJE%3D&amp;amp;se=2026-06-15T23%3A59%3A59Z&amp;amp;sp=r&amp;amp;_=1P+cNwbVYjUXFUR6wkK4ig==" style="max-height: 341px;max-width: 620px;" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;In this example we use the SCB based I2C Slave module to perform communication Via the PSoC 4 Pioneer Kit Bridge Interface.&lt;/p&gt;&lt;p style="margin:0;"&gt;This is done internally on the Kit as the PSoC5 is connected to the pins P3.0 and P3.1 with I2C Pull-ups to the PSoC4.&lt;/p&gt;&lt;p style="margin:0;"&gt;Hence no external circuitry in required.&lt;/p&gt;&lt;p style="margin:0;"&gt;The settings for the I2C Slave module { &lt;strong&gt;I2C (SCB mode) [v1.10]&lt;/strong&gt; } is as follows:&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span&gt;&lt;a href="https://community.element14.com/resized-image/__size/515x418/__key/communityserver-wikis-components-files/00-00-00-01-62/3755.contentimage_5F00_28542.png"&gt;&lt;img loading="lazy" alt="image" src="https://community-storage.element14.com/communityserver-components-secureimagefileviewer/communityserver/wikis/components/files/00/00/00/01/62/3755.contentimage_28542.png-515x418.png?sv=2016-05-31&amp;amp;sr=b&amp;amp;sig=y3%2BKdo%2FGAGN8SJ08hjTC%2BIG8hAp9TlxPkFnt62FN3f8%3D&amp;amp;se=2026-06-15T23%3A59%3A59Z&amp;amp;sp=r&amp;amp;_=mqNmBFNKnThonVzxU893rg==" style="max-height: 418px;max-width: 515px;" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;Apart from the I2C Slave we also use a Single pin LED connection for the Green color in the RGB LED P0.2 as shown in the earlier examples.&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;Now for the source code we plan to have engage the Deep Sleep mode for the PSoC4 when the I2C Slave is not busy.&lt;/p&gt;&lt;p style="margin:0;"&gt;This is achieved by activating the &lt;strong&gt;&lt;em&gt;&amp;#39;Enable wakeup from Sleep Mode&amp;#39;&lt;/em&gt;&lt;/strong&gt; option in the I2C module and applying proper API sleep for I2C module.&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;The communication I2C protocol Chosen here is as follows:&lt;/p&gt;&lt;ul&gt;&lt;li&gt;Transmit:&lt;ul&gt;&lt;li&gt;{ 4 Byte } 32-bit Commands&lt;/li&gt;&lt;li&gt;{ 6 Byte } 8-bit Parameters (1byte to 6bytes)&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;li&gt;Receive:&lt;ul&gt;&lt;li&gt;{ 4 Byte } 32-bit Commands&lt;/li&gt;&lt;li&gt;{ 1 Byte } 8-bit Status&lt;/li&gt;&lt;li&gt;{ 5 Byte } 8-bit Return Parameters (optional)&lt;/li&gt;&lt;/ul&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;This is also followed while we use the Bridge Interface shown later.&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;Here is the Source Code:&lt;/p&gt;&lt;p&gt;&lt;pre class="ui-code" data-mode="c_cpp"&gt;#include &amp;lt;project.h&amp;gt;
#include &amp;lt;cyPm.h&amp;gt;
#define RESPONSE_LOC    4
volatile uint32_t command;  // 32bit Commands for Command Dispatcher
volatile uint8_t params[6]; // 6byte Parameter Structure
uint8 u8wBuffer[10];        // I2C Write Buffer
uint8 u8rBuffer[10];        // I2C Read  Buffer
void CommandDispatcher()
{
    u8rBuffer[RESPONSE_LOC] = 0x00; // Default there are No Errors initially
    // Depending on the Command Perform Actions
    switch(command)
    {
        case 0x0001:
            u8rBuffer[RESPONSE_LOC+1] = 0xAA;
            break;
        case 0x0002:
            u8rBuffer[RESPONSE_LOC+1] = 0xBB;
            break;
        case 0x0003:            
            u8rBuffer[RESPONSE_LOC+1] = 0xCC;
            break;
        default:
            u8rBuffer[RESPONSE_LOC] = 0x01; // In case of Error command not ok
            break;
    }
}
int main()
{
    uint8 i;            // Local counter
    uint32 byteCnt;     // Used to store the size of data written into the I2C Buffer
    CyGlobalIntEnable;  // Enable the Interrupts for I2C Processing
    I2CS_Start();
    Pin_LED_Write(1);
    I2CS_I2CSlaveInitWriteBuf(u8wBuffer,10);    // Setup Slave I2C Buffer
    I2CS_I2CSlaveInitReadBuf(u8rBuffer,10);     
    for(;;)
    {   
        if(I2CS_I2CSlaveStatus()&amp;amp;I2CS_I2C_SSTAT_RD_CMPLT) // If Buffer was Read by Master
        {
            I2CS_I2CSlaveClearReadBuf();
            I2CS_I2CSlaveClearReadStatus();
        }
        if(!(I2CS_I2CSlaveStatus()&amp;amp;
            (I2CS_I2C_SSTAT_RD_BUSY|I2CS_I2C_SSTAT_RD_BUSY|
                I2CS_I2C_SSTAT_WR_BUSY|I2CS_I2C_SSTAT_WR_CMPLT|
                I2CS_I2C_SSTAT_RD_CMPLT))) // If Not busy
        {
            I2CS_Sleep();       //I2C Module Sleep
            CySysPmDeepSleep(); // Got to Deep Sleep
            I2CS_Wakeup();      // Wakeup on Address Match + Clock Stretch
            CyGlobalIntEnable;  // Enable Interrupts to enable processing
        }
        if(I2CS_I2CSlaveStatus()&amp;amp;I2CS_I2C_SSTAT_WR_CMPLT) // If Buffer was Written by Master
        {
            Pin_LED_Write(0);
            // Get the Write Buffer Size
            byteCnt = I2CS_I2CSlaveGetWriteBufSize();
            
            // 32bit Command (4)bytes
            command=(u8wBuffer[0]&amp;lt;&amp;lt;24)|(u8wBuffer[1]&amp;lt;&amp;lt;16)|(u8wBuffer[2]&amp;lt;&amp;lt;8)|(u8wBuffer[3]);
            // Get Parameters (6)bytes
            for(i=RESPONSE_LOC;i&amp;lt;byteCnt;i++)
            {
                params[i-RESPONSE_LOC]=u8wBuffer[i];
            }
            // Copy the Last Buffer to Rx
            for(i=0;i&amp;lt;byteCnt;i++)
            {
                u8rBuffer[i]=u8wBuffer[i];
            }
            // Call the Command Dispatcher - Blocking
            CommandDispatcher();
            // Clear the Write Status
            I2CS_I2CSlaveClearWriteStatus();
            I2CS_I2CSlaveClearWriteBuf();
            // Clear Read Buffer to help in Transmission
            I2CS_I2CSlaveClearReadBuf();
            Pin_LED_Write(1);
        }        
    }
}&lt;/pre&gt;&lt;/p&gt;&lt;div style="display:none;"&gt;&lt;/div&gt;&lt;p style="margin:0;"&gt;After successfully building and loading this code the Cypress Bridge Control Panel needs to be used.&lt;/p&gt;&lt;p style="margin:0;padding:0px;"&gt;&amp;nbsp;&lt;/p&gt;&lt;p style="margin:0;"&gt;Here is the Settings for the Bridge Control Panel:&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span&gt;&lt;a href="https://community.element14.com/resized-image/__size/305x253/__key/communityserver-wikis-components-files/00-00-00-01-62/5074.contentimage_5F00_28543.png"&gt;&lt;img loading="lazy" alt="image" src="https://community-storage.element14.com/communityserver-components-secureimagefileviewer/communityserver/wikis/components/files/00/00/00/01/62/5074.contentimage_28543.png-305x253.png?sv=2016-05-31&amp;amp;sr=b&amp;amp;sig=i%2FBVDp3fO%2FCl8HaMbkju7kB49JD9cKZ0RvlVacQGJKU%3D&amp;amp;se=2026-06-15T23%3A59%3A59Z&amp;amp;sp=r&amp;amp;_=KjMjXHgyKdiqH9I46k9bBw==" style="max-height: 253px;max-width: 305px;" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;The two commands used to subsequently Write and Read the I2C data are as follows:&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:14pt;font-family:courier new,courier;"&gt;w 48 00 00 00 01 00 00 p&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span style="font-size:14pt;font-family:courier new,courier;"&gt;r 48 x x x x x x x x p&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;These commands need be entered in to the Editor plane of the Bridge Control Panel. &lt;em&gt;In order to go to Next line use &lt;strong&gt;Ctrl + Enter&lt;/strong&gt; in the Edition pane of the Bridge Control Panel&lt;/em&gt;.&lt;/p&gt;&lt;p style="margin:0;"&gt;Also make shire that the &lt;strong&gt;&amp;#39;Send all Strings&amp;#39; check-box is selected as ON&lt;/strong&gt;.&lt;/p&gt;&lt;p style="margin:0;"&gt;Here is a snapshot of the Communications:&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span&gt;&lt;a href="https://community.element14.com/resized-image/__size/862x679/__key/communityserver-wikis-components-files/00-00-00-01-62/3821.contentimage_5F00_28544.png"&gt;&lt;img loading="lazy" alt="image" src="https://community-storage.element14.com/communityserver-components-secureimagefileviewer/communityserver/wikis/components/files/00/00/00/01/62/3821.contentimage_28544.png-620x488.png?sv=2016-05-31&amp;amp;sr=b&amp;amp;sig=O1eFGOEMse0VVIFLCFgxql6mWFUH%2FcOpbVIIAxxjRVs%3D&amp;amp;se=2026-06-15T23%3A59%3A59Z&amp;amp;sp=r&amp;amp;_=mSfbLdlcy7CnK6IzQKfbFA==" style="max-height: 488px;max-width: 620px;" /&gt;&lt;/a&gt;&lt;/span&gt;&lt;/p&gt;&lt;p style="margin:0;"&gt;In order to demonstrate the Power efficiency of this example below is a video showing current consumption of PSoC4 in various communication loads (All measurements are in mA) :&lt;/p&gt;&lt;p style="margin:0;"&gt;&lt;span id="04eadd44_fd7b_4c84_b54f_d733848b6b73"&gt;&lt;span&gt;&lt;a href="https://players.brightcove.net/1362235890001/NkxiVJdjx_default/index.html?videoId=2849458370001"&gt;players.brightcove.net/.../index.html&lt;/a&gt;&lt;/span&gt;&lt;/span&gt;&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;

&lt;div style="font-size: 90%;"&gt;Tags: psoc4, examples, smarter, das_project, smarter_life&lt;/div&gt;
</description></item></channel></rss>