element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Cypress Kits
  • Products
  • Dev Tools
  • Cypress Kits
  • More
  • Cancel
Cypress Kits
Documents PSoC4 Smarter Life Challenge - DAS Project :Example 7 Energy Efficient I2C Command Dispatcher
  • Blog
  • Forum
  • Documents
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Cypress Kits to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Engagement
  • Author Author: bose
  • Date Created: 19 Nov 2013 1:23 AM Date Created
  • Last Updated Last Updated: 19 Nov 2013 1:46 AM
  • Views 464 views
  • Likes 0 likes
  • Comments 0 comments
Related
Recommended

PSoC4 Smarter Life Challenge - DAS Project :Example 7 Energy Efficient I2C Command Dispatcher

This example show the implementation of I2C Slave based Command Dispatcher using the PSoC 4 Pioneer Kit with energy efficiency in mind.

 

Here is the Application Schematics:

image

image

In this example we use the SCB based I2C Slave module to perform communication Via the PSoC 4 Pioneer Kit Bridge Interface.

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.

Hence no external circuitry in required.

The settings for the I2C Slave module { I2C (SCB mode) [v1.10] } is as follows:

image

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.

 

Now for the source code we plan to have engage the Deep Sleep mode for the PSoC4 when the I2C Slave is not busy.

This is achieved by activating the 'Enable wakeup from Sleep Mode' option in the I2C module and applying proper API sleep for I2C module.

 

The communication I2C protocol Chosen here is as follows:

  • Transmit:
    • { 4 Byte } 32-bit Commands
    • { 6 Byte } 8-bit Parameters (1byte to 6bytes)
  • Receive:
    • { 4 Byte } 32-bit Commands
    • { 1 Byte } 8-bit Status
    • { 5 Byte } 8-bit Return Parameters (optional)

 

This is also followed while we use the Bridge Interface shown later.

 

Here is the Source Code:

#include <project.h>
#include <cyPm.h>
#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()&I2CS_I2C_SSTAT_RD_CMPLT) // If Buffer was Read by Master
        {
            I2CS_I2CSlaveClearReadBuf();
            I2CS_I2CSlaveClearReadStatus();
        }
        if(!(I2CS_I2CSlaveStatus()&
            (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()&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]<<24)|(u8wBuffer[1]<<16)|(u8wBuffer[2]<<8)|(u8wBuffer[3]);
            // Get Parameters (6)bytes
            for(i=RESPONSE_LOC;i<byteCnt;i++)
            {
                params[i-RESPONSE_LOC]=u8wBuffer[i];
            }
            // Copy the Last Buffer to Rx
            for(i=0;i<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);
        }        
    }
}

After successfully building and loading this code the Cypress Bridge Control Panel needs to be used.

 

Here is the Settings for the Bridge Control Panel:

image

The two commands used to subsequently Write and Read the I2C data are as follows:

w 48 00 00 00 01 00 00 p

r 48 x x x x x x x x p

These commands need be entered in to the Editor plane of the Bridge Control Panel. In order to go to Next line use Ctrl + Enter in the Edition pane of the Bridge Control Panel.

Also make shire that the 'Send all Strings' check-box is selected as ON.

Here is a snapshot of the Communications:

image

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) :

You don't have permission to edit metadata of this video.
Edit media
x
image
Upload Preview
image

  • psoc4
  • examples
  • smarter
  • das_project
  • smarter_life
  • Share
  • History
  • More
  • Cancel
  • Sign in to reply
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube