CE211423 CY8CKIT-042-BLE F-RAM™ I2C.pdf

CE211423 - CY8CKIT-042-BLE – F-RAM™ I2C
Objective
®
This example project is based on a PSoC Creator™ starter design for the PSoC 4 device. It demonstrates how an F-RAM
device can be used with a PSoC device to read and write data. In this project, the PSoC device scans though the F-RAM
address space writing the address and then reading it back.
Development Kit Configuration
This example project is designed to run on the CY8CKIT-042-BLE kit from Cypress Semiconductor. A description of the kit,
along
with
more
example
programs
and
ordering
information,
can
be
found
at
http://www.cypress.com/documentation/development-kitsboards/cy8ckit-042-ble-bluetooth-low-energy-ble-pioneer-kit.
The project requires configuration settings changes to run on other kits from Cypress Semiconductor. Table 1 lists supported
kits. To use any other kit, change the project’s device with the help of Device Selector called from the project’s context menu.
Table 1. Development Kits and Parts
Development Kit
Device
CY8CKIT-042-BLE
CY8C4247LQI-BL483
CY8CKIT-044
CY8C4247AZI-M485
CY8CKIT-046
CY8C4248BZI-L489
Pin assignments for the supported kits are in Table 2.
Table 2. Pin Assignments for Supported Kits
Development Kit
Pin Name
CY8CKIT-042
CY8CKIT-042 BLE
CY8CKIT-044
CY8CKIT-046
\I2C_1:scl\
P5[1]
P5[1]
P5[1]
P5[1]
\I2C_1:sda\
P5[0]
P5[0]
P5[0]
P5[0]
Set jumper J9 (J16 for CY8CKIT-042-BLE) to 3.3V position.
www.cypress.com
Document No. 002-11423 Rev.**
1
CY8CKIT-042-BLE – F-RAM™ I2C
Project Configuration
2
This example project consists of an I C master and a slave F-RAM device. The top design schematic is shown in Figure 1.
Figure 1. Top Design Schematic
www.cypress.com
Document No. 002-11423 Rev.**
2
CY8CKIT-042-BLE – F-RAM™ I2C
2
2
The I C master is used to move data to and from the F-RAM device. The I C Component configuration is shown in Figure 2.
2
Figure 2. I C Component Configuration Window
Project Description
2
In the main function, the I C master is started. The “for” loop in main.c loops the address space of the F-RAM and writes the
address value. . Please refer to the project files included with this project.
Expected Results
There is no output from the PSoC device. This project is designed to be a starting template to show how the F-RAM device is
accessed via the PSoC device.
www.cypress.com
Document No. 002-11423 Rev.**
3
CY8CKIT-042-BLE – F-RAM™ I2C
Schematic
Figure 3. Connection Schematic
Using I2C to Communicate with the F-RAM Device
2
2
This example project communicates with the F-RAM device using I C. I C is a simple Clock/Data bus using 8-bit serial words.
2
Code 1 and Code 2 perform the Write and Read operations for the I C master to access the F-RAM device.
2
Code 1. I C F-RAM Write
/******************************************************************************
* Function Name: FRAM_Write
*******************************************************************************
*
* Summary:
* F-RAM Byte Write Command
* uint16 address - address in the F-RAM array
* uint8 data - data to be written
*
******************************************************************************/
void FRAM_Write(uint16 address, uint8 data)
{
uint8 txBuffer[BUFFER_SIZE];
txBuffer[0] = address >> 8;
txBuffer[1] = address;
txBuffer[2] = data;
/* Clear any previous status */
I2C_1_I2CMasterClearStatus();
/* I2C Wrtie Command */
status = I2C_1_I2CMasterWriteBuf(SLAVE_ADDRESS, (uint8 *) txBuffer, BUFFER_SIZE,
I2C_1_I2C_MODE_COMPLETE_XFER);
for(;;)
{
if(0u != (I2C_1_I2CMasterStatus() & I2C_1_I2C_MSTAT_WR_CMPLT))
{
/* Transfer complete. Check Master status to make sure that transfer
www.cypress.com
Document No. 002-11423 Rev.**
4
CY8CKIT-042-BLE – F-RAM™ I2C
completed without errors. */
break;
}
}
}
2
Code 2. I C F-RAM Read
/******************************************************************************
* Function Name: FRAM_Read
*******************************************************************************
*
* Summary:
* F-RAM Byte Read Command
* uint16 address - address in the F-RAM array
* uint8 retrun - data to be read
*
******************************************************************************/
uint8 FRAM_Read(uint16 address)
{
uint8 rxBuffer[BUFFER_SIZE-2];
uint8 txBuffer[2];
txBuffer[0] = address >> 8;
txBuffer[1] = address;
/* Clear any previous status */
I2C_1_I2CMasterClearStatus();
/* I2C Wrtie Command to Set the Address*/
status = I2C_1_I2CMasterWriteBuf(SLAVE_ADDRESS, (uint8 *) txBuffer, 0x2,
I2C_1_I2C_MODE_COMPLETE_XFER);
for(;;)
{
if(0u != (I2C_1_I2CMasterStatus() & I2C_1_I2C_MSTAT_WR_CMPLT))
{
/* Transfer complete. Check Master status to make sure that transfer
completed without errors. */
break;
}
}
/* Clear any previous status */
I2C_1_I2CMasterClearStatus();
/* I2C Read Command */
status = I2C_1_I2CMasterReadBuf(SLAVE_ADDRESS, (uint8 *) rxBuffer, 1, I2C_1_I2C_MODE_COMPLETE_XFER);
for(;;)
{
if(0u != (I2C_1_I2CMasterStatus() & I2C_1_I2C_MSTAT_RD_CMPLT))
{
/* Transfer complete. Check Master status to make sure that transfer
completed without errors. */
break;
}
}
return rxBuffer[0];
}
www.cypress.com
Document No. 002-11423 Rev.**
5
CY8CKIT-042-BLE – F-RAM™ I2C
Document History
2
Document Title: CE211423 - CY8CKIT-042-BLE – F-RAM™ I C
Document Number: 002-11423
Revision
ECN
**
5160314
www.cypress.com
Orig. of
Change
JLTO
Submission
Date
03/23/2016
Description of Change
New code example
Document No. 002-11423 Rev.**
6
CY8CKIT-042-BLE – F-RAM™ I2C
Worldwide Sales and Design Support
Cypress maintains a worldwide network of offices, solution centers, manufacturer’s representatives, and distributors. To find
the office closest to you, visit us at Cypress Locations.
PSoC® Solutions
Products
®
®
ARM Cortex Microcontrollers
cypress.com/arm
psoc.cypress.com/solutions
Automotive
cypress.com/go/automotive
PSoC 1 | PSoC 3 | PSoC 4 | PSoC 5LP
Clocks & Buffers
cypress.com/go/clocks
Interface
cypress.com/go/interface
Lighting & Power Control
cypress.com/go/powerpsoc
Memory
cypress.com/go/memory
Technical Support
PSoC
cypress.com/go/psoc
cypress.com/go/support
Touch Sensing
cypress.com/go/touch
USB Controllers
cypress.com/go/usb
Wireless/RF
cypress.com/go/wireless
Cypress Developer Community
Community | Forums | Blogs | Video | Training
PSoC is a registered trademark and PSoC Creator is a trademark of Cypress Semiconductor Corp. All other trademarks or registered trademarks
referenced herein are the property of their respective owners.
Cypress Semiconductor
198 Champion Court
San Jose, CA 95134-1709
Phone
Fax
Website
: 408-943-2600
: 408-943-4730
: www.cypress.com
© Cypress Semiconductor Corporation, 2016. This document is the property of Cypress Semiconductor Corporation and its subsidiaries, including
Spansion LLC (“Cypress”). This document, including any software or firmware included or referenced in this document (“Software”), is owned by
Cypress under the intellectual property laws and treaties of the United States and other countries worldwide. Cypress reserves all rights under such
laws and treaties and does not, except as specifically stated in this paragraph, grant any license under its patents, copyrights, trademarks, or other
intellectual property rights. If the Software is not accompanied by a license agreement and you do not otherwise have a written agreement with
Cypress governing the use of the Software, then Cypress hereby grants you under its copyright rights in the Software, a personal, non-exclusive,
nontransferable license (without the right to sublicense) (a) for Software provided in source code form, to modify and reproduce the Software solely for
use with Cypress hardware products, only internally within your organization, and (b) to distribute the Software in binary code form externally to end
users (either directly or indirectly through resellers and distributors), solely for use on Cypress hardware product units. Cypress also grants you a
personal, non-exclusive, nontransferable, license (without the right to sublicense) under those claims of Cypress’s patents that are infringed by the
Software (as provided by Cypress, unmodified) to make, use, distribute, and import the Software solely to the minimum extent that is necessary for you
to exercise your rights under the copyright license granted in the previous sentence. Any other use, reproduction, modification, translation, or
compilation of the Software is prohibited.
CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS DOCUMENT OR ANY SOFTWARE,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Cypress reserves the right to make changes to this document without further notice. Cypress does not assume any liability arising out of the application
or use of any product or circuit described in this document. Any information provided in this document, including any sample design information or
programming code, is provided only for reference purposes. It is the responsibility of the user of this document to properly design, program, and test
the functionality and safety of any application made of this information and any resulting product. Cypress products are not designed, intended, or
authorized for use as critical components in systems designed or intended for the operation of weapons, weapons systems, nuclear installations, lifesupport devices or systems, other medical devices or systems (including resuscitation equipment and surgical implants), pollution control or hazardous
substances management, or other uses where the failure of the device or system could cause personal injury, death, or property damage (“Unintended
Uses”). A critical component is any component of a device or system whose failure to perform can be reasonably expected to cause the failure of the
device or system, or to affect its safety or effectiveness. Cypress is not liable, in whole or in part, and Company shall and hereby does release Cypress
from any claim, damage, or other liability arising from or related to all Unintended Uses of Cypress products. Company shall indemnify and hold
Cypress harmless from and against all claims, costs, damages, and other liabilities, including claims for personal injury or death, arising from or related
to any Unintended Uses of Cypress products.
Cypress, the Cypress logo, Spansion, the Spansion logo, and combinations thereof, PSoC, CapSense, EZ-USB, F-RAM, and Traveo are trademarks or
registered trademarks of Cypress in the United States and other countries. For a more complete list of Cypress trademarks, visit cypress.com. Other
names and brands may be claimed as property of their respective owners.
www.cypress.com
Document No. 002-11423 Rev.**
7