CE85395 - SMBus Slave using PSoC 1

SMBus Slave using PSoC® 1
Example Name: CE85395
Programming Language: C
Associated Part Families: CY8C28xxx, CY8C29x66/27x43/24xxx,
CY8C23x33, CY8C21x34,CY8C21x23
®
Software Version: PSoC Designer™ 5.3
Related Hardware: CY8CKIT-001
Author: Keerthi Raj N
Objective
®
This project demonstrates how to implement a SMBus Slave device using PSoC 1, and explains different SMBus commands
and their usage with the Bridge Control Panel (BCP) tool.
Overview
The SMBusSlave user module (UM) is a digital communication user module similar to I2C Slave. At the physical layer, multiple
devices, both masters and slaves, will be connected to the same bus. The SMBus Slave UM in PSoC 1 uses I2C Controller as
its physical layer and firmware-based data link layer. This code example discusses how to use the SMBus Slave user module
and its commands to communicate to a host SMBus device.
The BCP software tool that simulates a SMBus Master has been used to demonstrate how the SMBus commands work.
User Module List and Placement
The following table lists the hardware resources occupied by the user module:
User Module
Instance Name
Placement
SMBusSlave
SMBus_Slave
I2C Controller 0
SAR10
SAR10
SAR ADC
LCD
LCD
Port 2
User Module Parameter Settings
The following table lists the SMBus Slave user module parameter settings:
I2CHW
Parameter
Value
Comments
Slave Address
4
7-bit address of the SMBus Slave device in decimal
Hardwired Slave Address
Disable
Slave address is not selected through hardwired GPIO‟s.
Packet Error Check
Enable
Packet Error Check (PEC) feature of SMBus protocol is enabled. This slave can
process PEC bytes received by the master and also send PEC bytes for all commands.
Block Write Buffer Length
6
Length of the buffer (in bytes) shared between the master for Block Write Operation
Block Read Buffer Length
6
Length of the buffer (in bytes) shared between the master for Block Read Operation
SMBALERT Port
None
SMBLERT pin is disabled.
SMBALERT Pin
None
SMBLERT pin is disabled.
Slave Address Pin 0 Port
None
Hardwired Slave Address GPIO is disabled.
Slave Address Pin 0
None
Hardwired Slave Address GPIO is disabled.
Slave Address Pin 1 Port
None
Hardwired Slave Address GPIO is disabled.
Slave Address Pin 1
None
Hardwired Slave Address GPIO is disabled.
Auto Address Check
Enable
Hardware Address Comparison is enabled.
SMBus Clock
100K Standard
SMBus Slave operating clock speed
SMBus Pins
P1[0]-P1[0]
SMBDAT and SMBCLK Pins for SMBus Slave
March 12, 2013
Document No. 001-85395 Rev **
1
CE85395 – SMBus Slave using PSoC 1
The following table lists the SAR ADC user module parameter settings:
UART
Parameter
Value
Comments
Run Mode
One-shot
ADC will convert only when triggered manually.
Resolution
10 bits
The digital value range is 0000h to 03FFh.
ADC Clock
Divide By 12
Sysclk is divided by 12 and used as clock for ADC.
Input
Port_0_5
Analog input to the ADC.
Auto Trigger Global Enable
Disable
The hardware trigger is disabled. ADC must be triggered through firmware.
Select Auto Trigger Source
Don‟t Care
This value does not affect any functionality because the hardware trigger is disabled.
The following table lists the LCD user module parameter settings:
LCD
Parameter
Value
Comments
LCD Port
Port_2
LCD will use P2[0] to P2[7] of the PSoC.
Bar Graph
Disable
Bar Graph is not needed for this project
Global Resources
Important Global Resources
Parameter
Value
Comments
PSoC Power (Vdd) is 5.0V and Internal Oscillator generates 24 MHz clock.
Power Setting
[Vcc / SysClk freq ]
5.0 / 24 MHz
CPU_Clock
SysClk/1
Sets the CPU frequency to 24 MHz.
Ref Mux
1.6 BandGap +/1.6 BandGap
Sets the range of 0 to 4.16 V (2 x 1.6 x BandGap) for SAR ADC.
Note Leave all other global resources at their default.
Pin Configuration
Pin
Select
Drive
Interrupt
P0[5]
Analog Input
High Z Analog
DisableInt
P1[0]
SMBus_Slave_SMBDAT
Open Drain Low
DisableInt
P1[1]
SMBus_Slave_SMBCLK
Open Drain Low
Disable Int
P1[7]
StdCPU
Strong
DisableInt
P2[0] to P2[6]
StdCPU
Strong
DisableInt
P2[7]
StdCPU
Pull Up
Disbale Int
Hardware Connections
You can test the code using the CY8CKIT-001 and CY3240-I2USB kits. The CY8CKIT-001 hosts the CY8C28xxx Processor
Module, which acts as an SMBus Slave. The CY3240-I2USB kit consists of the I2C-USB Bridge, which along with the BCP
simulates the SMBus Master. BCP is automatically installed when PSoC Programmer is installed on the machine.
The Code Example is associated with the IIC file which has specific commands to be used in BCP to communicate with the
Slave device. The IIC file is located at:
C:\Program
Files
(x86)\Cypress\PSoC
Designer\5.3\PSoC
Examples\SMBus_Slave_using_PSoC_1\Commands.iic.
Designer
5\Start
Page\Solutions\Code
The CY8C28xxx Processor Module must be programmed with the code example‟s hex file.
March 12, 2013
Document No. 001-85395 Rev **
2
CE85395 – SMBus Slave using PSoC 1
To test the code using the kits mentioned in this section, make the following connections in CY8CKIT-001:




Connect P1[7] to LED4
Connect P2[7] to SW1
Connect P0[5] to VR
Ensure the following jumpers are populated with the given settings:
J8 – 5V SOURCE - VREG
J7 – VDD_DIG SELECT - VDD
J6 – VDD_ANLG SELECT - VDD
J12 – LCD POWER – ON
Populate J11
All other jumper positions are don‟t care.


Select SW3 Position such that the PSoC is powered by 5V.
Connect the I2C USB Bridge to your PC using the USB cable shipped with the CY3240 Kit, and connect the other end of
the I2C USB Bridge to PROG port on the CY8C28xxx Processor Module.
Operation
After the hardware settings are completed, follow these steps to set up BCP:


Open the BCP software tool. Connect to the I2C-USB Bridge listed.
Power up CY8CKIT-001 through a 12V-DC Adapter. The BCP detects the power and the status bar displays “Connected”
and “Powered” messages.
Figure 1. Bridge Control Panel
March 12, 2013
Document No. 001-85395 Rev **
3
CE85395 – SMBus Slave using PSoC 1




Go to File > Open File > Browse for the Commands.iic file and click Open. The commands are loaded to the BCP tool.
Go to Tools > Protocol Configuration > I2C and select 100 KHz clock.
Click List to check the presence of the slave device. The BCP must list the 7-bit device address as 04. This confirms that
the SMBus slave is up and running.
Now each command can be sent one after another to communicate with the slave. The commands and their
functionalities are explained in the following section.
Test Commands







All numbers within the command are in hex format.
„w‟ indicates write operation.
„r‟ indicates read operation.
„p‟ indicates stop bit.
„04‟ after the write (w) or read (r) byte is the slave address of SMBus.
Each command has a PEC byte before the stop bit (s) which is an 8-bit CRC remainder byte calculated over all the bytes
in the transaction, including the slave address and R/W bit. The CRC Polynomial is (x^8) + (x^2) + x + 1.
If any byte in the transaction or slave address of the device is changed, the CRC byte must be recalculated and entered in
the command. Otherwise, the PEC byte is NACK‟ed by PSoC.
Command Name
Command Format in BCP
PSoC Response
Comments
w 04 BB 80 p
Turns on LED4
“bb” is the first data byte which indicates PSoC to
turn on LED. “80” is the PEC for whole command.
w 04 BA 87 p
Turns off LED4
“ba” is the first data byte which indicates PSoC to
turn off LED. “87” is the PEC for the whole
command.
Receive Byte
r 04 x x p
Reports status of Switch at P2 [7].
First data byte:
“00” indicates "Pressed"
”80” indicates "Not Pressed"
Second received byte will be PEC.
Write Byte
w 04 40 b6 01 p
The byte is received by PSoC and the
nibbles are swapped and reported back
during Read Byte command
“40” is the command code.
“b6” is the written byte
“01” is the PEC
Read Byte
w 04 60 r 04 x x p
The nibbles of the byte received
through Write Byte command are
swapped and sent back to master as a
response to this command.
“60” is the command code
First data byte is the byte sent to master.
Second data byte is PEC.
Write Word
w 04 50 ab cd 76 p
Displays the written word on LCD.
“50” is the command code
“ab” and “cd” are two bytes (Word) of data
written to the slave.
“76” is PEC.
Read Word
w 04 70 r 04 x x x p
Reports 10-bit digital value from 0000 to
03FF for analog input at P0[5]
“70” is the command code
First two data bytes after read correspond to the
ADC value.
Third data byte is PEC.
Process Call
w 04 80 ab cd r 04 x x x p
This command is a combination of
Write
Word
and
Read
Word
Commands. The Written word is
displayed on LCD and the ADC value is
read back by the master.
“80” is the command code.
Two data bytes after the command code
constitute the word written to slave.
Two data bytes after read constitute the word
read by master from slave
Data byte before stop bit is PEC.
Send Byte
March 12, 2013
Document No. 001-85395 Rev **
4
CE85395 – SMBus Slave using PSoC 1
Command Format in BCP
PSoC Response
Comments
Block Write
Command Name
w 04 20 04 01 02 03 04 bd p
Writes multiple bytes to a shared buffer.
The nibbles of received bytes are
swapped and stored in another shared
buffer.
“20” is the command code.
First Data byte “04” indicates the number of bytes
the master wants to write to the slave.
“01”, “02”, “03” and “04” are four data bytes
written to the slave.
“bd” is the PEC byte.
Block Read
w 04 30 r 04 x x x x x x x x p
Reads multiple bytes from a shared
buffer. The bytes have swapped nibbles
of bytes received through the Block
Write command.
“30” is the command code.
The slave sends a byte after read byte (r 04),
indicating the number of bytes it wants to send. In
the given code example, the slave is configured
to send 6 data bytes.
After 6 data bytes, a PEC is sent.
Block Process Call
w 04 10 05 02 03 04 05 06 r
04 x x x x x x x x p
This command is a combination of
Block
Write
and
Block
Read
commands. PSoC responds in the
same way as mentioned for Block Write
and Block Read commands.
“10” is the command code.
“05” indicates the number of bytes master wants
to write.
The first data byte after read byte (r 04) indicates
the number of bytes the slave wants to send.
Last data byte is PEC.
Testing the Project
1.
Set up the hardware and BCP as explained in previous sections.
2.
Place the cursor on the Send Byte command that turns on the LED, and click Send.
3.
Verify that the LED4 on CY8CKIT-001 must turn on.
4.
Place the cursor on the Send Byte command that turns off the LED, and click Send.
5.
Verify that the LED4 on CY8CKIT-001 must turn off.
6.
Place the cursor on the Receive Byte command and click Send.
7.
The received byte must be “80”, which indicates the switch is not pressed.
8.
Press and hold SW1 and send the Receive Byte command again.
9.
Verify that the received byte is “00” that indicates the switch is pressed.
10. Send the Write Byte command to write a byte to PSoC and send the Read Byte command to receive a byte that has
swapped nibbles compare to the sent byte.
11. Send the Write Word command and verify that the written word is displayed on the LCD.
12. Send the Read Word command in repeat mode by clicking Repeat. The BCP continuously sends the command and
reads back a word. Now, vary the analog value at P0[5] by rotating the potentiometer R20 on CY8CKIT-001. The
received word must vary from 0000h to 03FFh, depending on the position of the potentiometer.
13. Send the Process Call command and verify that the written word will be displayed on LCD and the received word will
be the digital equivalent of analog voltage at P0[5].
14. Send Block Write command to write 4 bytes to PSoC. Send Block Read command to receive an array of bytes that
have swapped nibbles compared to the sent bytes.
15. Send Block Process Call command to write 5 bytes to PSoC and read the swapped nibbles of the same array of
bytes.
March 12, 2013
Document No. 001-85395 Rev **
5
CE85395 – SMBus Slave using PSoC 1
The flowchart of the slave device program execution is shown in Figure 2:
Figure 2. Program Execution Flow Chart
Start
Enable Global
Interrupt
Start SMBus Slave User
Module
Set Command Codes and
buffers for each command
Start ADC
Initialize LCD
N
Read Switch Status and Store
it in Receive Byte variable
Convert Analog input at P0[5]
to digital value and store it in
Read Word Buffer
If Sent Byte is
0xbb
Y
Turn On LED
N
Y
If Sent Byte is
0xba
Turn off LED
N
Display Word written
through Write Word
command on LCD
Swap nibbles of byte received
through Write Byte command
and save it in Read Byte Buffer
Swap nibbles of array of bytes
received through Block Write
command and save it in array of
bytes to be read through Block
Read command
March 12, 2013
Document No. 001-85395 Rev **
6
CE85395 – SMBus Slave using PSoC 1
Document History
Document Title: SMBus Slave using PSoC (R)1
Document Number: 001-85395
Revision
ECN
Orig. of
Change
Submission
Date
**
3930206
KERI
03/12/2013
Description of Change
New Code Example
PSoC is a registered trademark of Cypress Semiconductor Corp. PSoC Designer 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: 408-943-2600
Fax: 408-943-4730
http://www.cypress.com/
© Cypress Semiconductor Corporation, 2013. The information contained herein is subject to change without notice. Cypress Semiconductor
Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any
license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or
safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as
critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The
inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies
Cypress against all charges.
This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to worldwide
patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a
personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative
works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conjunction with a Cypress
integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation of this Source
Code except as specified above is prohibited without the express written permission of Cypress.
Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the
right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of the application or
use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in life-support systems where a
malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress‟ product in a life-support systems
application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges.
Use may be limited by and subject to the applicable Cypress software license agreement.
March 12, 2013
Document No. 001-85395 Rev **
7
Download PDF
Similar pages