Objective
The Code Example demonstrates the I2C Communication between FM4 and PSoC 4. In this example, FM4 acts the I2C Master and PSoC 4 acts as the I2C Slave.
OverviewFM4 has configurable MFS (Multi-Function Serial Interface) Blocks that can be configured to works as I2C. Here FM4 acts as the I2C Master. PSoC 4 is a EzI2C based I2C Slave.
Polling method is used to establish communication between the two devices. The data which PSoC 4 receives from FM4 and the data which FM4 reads from PSoC 4 is also sent over UART in the respective kits to demonstrate successful operation between the two devices.
Requirements- Design Tool: PSoC Creator 3.3 SP2 or above, IAR Embedded Workbench for ARM, PDL 2.1.0
- Programming Language: C (ARM GCC 4.9-2015-q1-update – included with PSoC Creator), C for IAR
- Associated Devices: PSoC 4, MB9BF56xR
- Required Hardware: CY8CKIT – 042, FM4-U120-9B560 - ARM® Cortex®-M4 MCU Starter Kit with USB and CMSIS-DAP
The project can be tested on the CY8CKIT – 042 and FM4-U120-9B560 Kits. Please ensure that both the Kits Operate at 5V Supply.
As you know, I2C requires Pull-Up resistors on the SCL and SDA Lines. CY8CKIT – 042 has on-board pull-ups on P4.0 and P4.1. Hence these pins are used for I2C Communication.
Make the following connections between the two kits:
The projects can be ported to any PSoC 4 or FM4 device (or Kit) by making necessary changes in the Pins. Also ensure that jumpers in FM4-U120-9B560 are correctly placed as shown under “Jumper – Default (Run mode, CMSIS-DAP)” in the Kit –User Guide that can be downloaded from here.
Here is a hardware connection diagram between the two kits.
PSoC 4 EzI2C Slave
PSoC 4 is used as the EzI2C Slave with 7 bit Slave address 0x3A and Data Rate 100 Kbps. A 10 byte buffer is used for Read and Write access. After a successful write from the master, the received data is send over UART for demonstration purposes.
PSoC Creator Schematic
FM4 I2C Master
FM4 is used as the I2C Master. I2C is configured using the MFS Block. In the master project, we specify the same slave address (0x3A). Also, this slave address is converted to 8 bit slave address for Write and Read access by appending the Read or Write Bit at the LSB.
MFS 6 is used to configure the I2C. Hence SOT6_1 and SCK6_1 Pins are used. Necessary codes are provided for initializing the I2C Master, I2C Start and Stop conditions and I2C Read and Write access.
Also, UART is used to display the data which FM4 reads from PSoC 4. MFS 0 is used for UART. For this project, only UART transmission is needed. The associated Pin is SOT0_0. This pin is already connected to the Virtual COM Port in the FM4 Kit. Also necessary codes are added for UART Initialization and transmission.
Build the ProjectsThe slave project can be easily programmed to CY8CKIT – 042 after building the project. However, for the FM4 Master project you need to consider the following:
1. The Master project attached here is based on PDL 2.1 template. The folder has three sub-folders names cmsis, drivers and mb9bf56xr (device folder). IAR was used for testing the project. Ensure that you set the necessary directory paths under “Preprocessor” in the Project Build Settings. Please provide the paths to these folders. This depends on where you save the project.
2. Ensure that mfs.c, pdl.c and pdl_user.h files are added to the Workspace:
3. For more details, you can refer to the PDL 2.1 Guide which can be downloaded from here.
Testing
1. Make the necessary connections between the Master and Slave.
2. Program the slave project to the -042 Kit. Also, open an instance of any UART console (like HyperTerminal, Tera term, Cool Term etc.). Connect to the enumerated COM port number for the -042 Kit. You can check the Device Manager for the COM Port Number. Set the Baud Rate to 115200.
3. Program the Master project to the FM4 device. You can use CN3 for programming the Kit using the On-Board CMSIS DAP Debugger. In IAR, you can use the option “Download and Debug”. Also open another instance of COM Port and connect to the enumerated COM port number for the FM4 Kit. You can check the Device Manager for the COM Port Number. Set the Baud Rate to 115200.
4. Resume the execution of the FM4 Project. On the two consoles, you can see the following:
Slave Console:
Master Console:









Comments