Datasheet I2 C1
Datasheet I2 C1
Datasheet I2 C1
Features
Industry-standard NXP I2C bus interface
Standard SPI Master and Slave interfaces with Motorola, Texas
Instruments, and the National Semiconductor's Microwire protocols
Standard UART TX and RX interfaces with SmartCard reader and IrDA protocols
EZ I2C mode which emulates a common I2C EEPROM interface
Supports wakeup from Deep Sleep mode
Run-time reconfigurable
I2C Bootloader support
General Description
The PSoC 4 SCB component is a multifunction hardware block that implements the following
communication components: I2C, SPI, UART, and EZI2C. Each is available as a pre-configured
schematic macro in the PSoC Creator Component Catalog, labeled with SCB Mode.
Note PSoC 4000 devices support only I2C modes. The UART or SPI mode choice is not
available.
Click on one of the links below to jump to the appropriate section:
I2C
EZI2C
SPI
UART
Cypress Semiconductor Corporation 198 Champion Court San Jose, CA 95134-1709 408-943-2600
Document Number: 002-03682 Rev. **
Revised December 17, 2015
Note PSoC 4000 devices support only I2C modes. The UART or SPI mode choice is not
available.
The pre-configured modes are the typical use case. They are the simplest method to configure
the SCB into the mode of operation that is desired. The unconfigured method can be used to
create designs for multiple applications and where the specific usage of the SCB in the design is
not known when the PSoC Creator hardware design is created.
Page 2 of 200
Unconfigured SCB
The SCB can be run-time configured for operation in any of the modes(I2C, SPI, UART, EZI2C)
from the Unconfigured mode. It can also be re-configured from any of these modes to any of the
other modes during run time. For example, you can reconfigured the SCB from SPI to UART
during run time.
Input/Output Connections
This section describes the various input and output connections for the SCB component. An
asterisk (*) in the list of terminals indicates that the terminal may be hidden on the symbol under
the conditions listed in the description of that terminal.
clock Input
Clock that operates this block. This terminal is required in Unconfigured mode. For other modes
the option is provided to use an internal clock or an external clock connected to this terminal.
The interface-specific pins are buried inside the component because these pins use dedicated
connections and are not routable as general purpose signals. See the I/O System section in the
device Technical Reference Manual (TRM) for more information.
Note The input buffer of buried output pins is disabled so as not to cause current linkage in low
power mode. Reading the status of these pins always returns zero. To get the current status, the
input buffer must be enabled before status read.
Page 3 of 200
SCB Tab
Use the SCB tab to select the pins that will be used by the SCB component in Unconfigured
mode. The communication type along with the pin name is listed with a check box to enable pin.
When the pin is enabled it is reserved for the SCB, and cannot be used by other functions. To
see what pins were reserved consult the pins tab in the .cydwr file
The Enable UART RX wake adds an interrupt to the RX pin to accomplish the UART wake-up
capability. This option restricts the processing of any other pin interrupts from the port where this
RX pin is placed.
Note PSoC 4000 devices only support I2C modes. The following pin names are used for this
device:
Note PSoC 4100/PSoC 4200 devices do not support UART hardware flow control. The following
pin name changes are used for these devices:
Page 4 of 200
Note PSoC 4100 BLE/PSoC 4200 BLE devices have different locations for the SCL and SDA
pins. The following pin name changes are used for these devices:
UART RX / I2C SCL / SPI MOSI pin name is UART RX / I2C SDA / SPI MOSI
UART TX / I2C SDA / SPI MISO pin name is UART TX / I2C SCL / SPI MISO
To use the SPI interface, select the following pins on the SCB tab:
Page 5 of 200
Page 6 of 200
Run-time Configuration
Configuration structures are provided for each interface. These structures provide configuration
fields that match the selections available in the Configure dialog for the specific interface. The
description of each structure is provided in the APIs section of corresponding interface:
Allocate structures for the selected interfaces and fill the structure with the required configuration
information. A pointer to this structure is passed to the appropriate initialization function of the
selected interface. The list of initialization functions for each interface is provided above.
The following example provides configuration structures for:
The following code snippets are taken from the SCB Uncofigured example project
SCB_UnconfiguredComm.
/*******************************************************************************
* Common Definitions
*******************************************************************************/
/* Constants */
#define ENABLED
(1u)
#define DISABLED
(0u)
#define NON_APPLICABLE (DISABLED)
/* Common RX and TX buffers for I2C and UART operation */
#define COMMON_BUFFER_SIZE
(16u)
uint8 bufferTx[COMMON_BUFFER_SIZE];
/* UART RX buffer requires one extra element for proper operation. One element
* remains empty while operation. Keeping this element empty simplifies
* circular buffer operation.
*/
uint8 bufferRx[COMMON_BUFFER_SIZE + 1u];
/*******************************************************************************
Page 7 of 200
* I2C Configuration
*******************************************************************************/
#define I2C_SLAVE_ADDRESS
(0x08u)
#define I2C_SLAVE_ADDRESS_MASK (0xFEu)
#define I2C_STANDARD_MODE_MAX
(100u)
#define
#define
#define
#define
I2C_RX_BUFFER_SIZE
I2C_TX_BUFFER_SIZE
I2C_RX_BUFER_PTR
I2C_TX_BUFER_PTR
(PACKET_SIZE)
(PACKET_SIZE)
bufferRx
bufferTx
/* I2C slave desired data rate is 100 kbps. The datasheet Table 1 provides a
* range of possible clock values 1.55 - 12.8 MHz. The CommCLK = 1.6 MHz is
* selected from this range. The clock divider has to be calculated to control
* clock frequency as clock component provides interface to it.
* Divider = (HFCLK / CommCLK) = (24MHz / 1.6 MHz) = 15. But the value written
* into the register has to decremented by 1. The end result is 14.
*/
#define I2C_CLK_DIVIDER
(14u)
/* Comm_I2C_INIT_STRUCT provides the fields which match the selections available
* in the customizer. Refer to the I2C customizer for detailed description of
* the settings.
*/
const Comm_I2C_INIT_STRUCT configI2C =
{
Comm_I2C_MODE_SLAVE,
/* mode: slave */
NON_APPLICABLE,
/* oversampleLow: N/A for slave */
NON_APPLICABLE,
/* oversampleHigh: N/A for slave */
NON_APPLICABLE,
/* enableMedianFilter: N/A */
I2C_SLAVE_ADDRESS,
/* slaveAddr: slave address */
I2C_SLAVE_ADDRESS_MASK, /* slaveAddrMask: single slave address */
DISABLED,
/* acceptAddr: disabled */
DISABLED,
/* enableWake: disabled */
DISABLED,
/* enableByteMode: disabled */
I2C_STANDARD_MODE_MAX, /* dataRate: 100 kbps */
DISABLED,
/* acceptGeneralAddr */
};
/*******************************************************************************
* UART Configuration
*******************************************************************************/
#define UART_OVERSAMPLING
(16u)
#define UART_DATA_WIDTH
(8u)
#define UART_RX_INTR_MASK
(Comm_INTR_RX_NOT_EMPTY)
#define UART_TX_INTR_MASK
(0u)
#define
#define
#define
#define
UART_RX_BUFFER_SIZE
UART_TX_BUFFER_SIZE
UART_RX_BUFER_PTR
UART_TX_BUFER_PTR
(COMMON_BUFFER_SIZE)
(COMMON_BUFFER_SIZE)
bufferRx
bufferTx
/* UART desired baud rate is 115200 bps. The selected Oversampling parameter is
* 16. The CommCLK = Baud rate * Oversampling = 115200 * 16 = 1.843 MHz.
Page 8 of 200
Page 9 of 200
Page 10 of 200
The following example implements a function that changes the SCB configuration according to
the passed opMode, and returns the status of the configuration change. This function refers to
configuration structures provided for the I2C and UART previously.
The instance name of the SCB component is Comm and the instance name of the clock
component is CommCLK.
/* Operation mode: I2C slave or UART */
#define OP_MODE_UART
(0u)
#define OP_MODE_I2C
(1u)
/* Global variables to manage current operation mode and initialization state */
uint32 mode = OP_MODE_UART;
/*******************************************************************************
* Function Name: ConfigurationChange
********************************************************************************
static cystatus ConfigurationChange(uint32 opMode)
{
cystatus status = CYRET_SUCCESS;
if (OP_MODE_I2C == opMode)
{
/***********************************************************************
* Configure SCB in I2C mode and enable component after completion.
***********************************************************************/
/* Disable component before re-configuration */
Comm_Stop();
/* Set clock divider to provide clock frequency to the SCB component
* to operated with desired data rate.
*/
CommCLK_SetFractionalDividerRegister(I2C_CLK_DIVIDER, 0u);
/* Configure SCB component. The configuration is stored in the I2C
* configuration structure.
*/
Comm_I2CInit(&configI2C);
/* Set read and write buffers for the I2C slave */
Comm_I2CSlaveInitWriteBuf(I2C_RX_BUFER_PTR, I2C_RX_BUFFER_SIZE);
Comm_I2CSlaveInitReadBuf (I2C_TX_BUFER_PTR, I2C_TX_BUFFER_SIZE);
/* Start component after re-configuration is complete */
Comm_Start();
}
else if (OP_MODE_UART == opMode)
{
/***********************************************************************
* Configure SCB in UART mode and enable component after completion
***********************************************************************/
Page 11 of 200
Note The ConfigurationChange() is a custom function that is not part of the component API.
Note Before changing the configuration, the SCB component must be disabled.
Note The SCB_Init() function does not initialize the component when the mode is Unconfigured.
The SCB_ModeInit() specific APIs have to called.
API Names
Some APIs contain specific interface prefixes as part of their name. These APIs operate
correctly only when the component is configured to utilize this interface. For example, the
SCB_I2CSlaveStatus() function works with the I2C interface.
Other APIs are shared between two interfaces. In these cases, the API name contains each
interface. For example, the SCB_SpiUartWriteTxData() works with both the SPI or UART
interfaces.
APIs that do not belong to specific interfaces do not contain interface prefixes. For example,
SCB_Enable() or SCB_EnableInt().
Page 12 of 200
I2C
The I2C bus is an industry-standard, two-wire hardware interface developed by Philips. The
master initiates all communication on the I2C bus and supplies the clock for all slave devices. I2C
is an ideal solution when networking multiple devices on a single board or small system.
The component supports I2C Slave, Master, Multi-Master and Multi-Master-Slave configurations.
The component supports standard clock speeds up to 1000 kbps. It is compatible [1] with I2C
Standard-mode, Fast-mode, and Fast-mode Plus devices as defined in the NXP I2C-bus
specification [2] on the NXP web site at www.nxp.com. The component is compatible with other
third-party slave and master devices.
Input/Output Connections
This section describes the various input and output connections for the SCB component. An
asterisk (*) in the list of terminals indicates that the terminal may be hidden on the symbol under
the conditions listed in the description of that terminal.
clock Input*
Clock that operates this block. The presence of this terminal varies depending on the Clock
from terminal parameter.
The interface-specific pins are buried inside the component because these pins use dedicated
connections and are not routable as general purpose signals. See the I/O System section in the
device Technical Reference Manual (TRM) for more information.
2.
The PSoC 4 I2C peripherals are not completely compliant with the I2C specification except PSoC 4100 BLE/
PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/ PSoC 4200L which have GPIO_OVT pins. For detailed information
refer to the Device datasheet.
Refer to the I2C-Bus Specification (Rev. 6 from October 2012) on the NXP web site at www.nxp.com.
Page 13 of 200
Data rate
This parameter is used to set the I2C data rate value up to 1000 kbps (400 kbps for PSoC 4000
family); the actual data rate may differ from the selected data rate due to available clock
frequency and component settings. The standard data rates are 100 (default), 400, and 1000
kbps. This parameter has no effect if the Clock from terminal option is enabled.
Refer to the Data rate configuration section for more information about provided options of the
data rate selection.
Page 14 of 200
Page 15 of 200
on page 16 for the selected data rate. Creator creates a clock in this range and returns the clock
frequency to the GUI. The GUI uses this clock frequency and the selected data rate to calculate
the oversampling value. The oversampling values Low and High are adjusted to meet the
request data rate.
Note Refer to the Clock from terminal section to get more information about possible deviation of
requested clock frequency and actual value.
Clock from terminal
This check box allows choosing an internally configured clock (by the component) or an
externally configured clock (by the user) for component operation. Refer to the Oversampling
factor section to understand relationship between component clock frequency and the
component parameters.
When this option is enabled, the component does not control the data rate, but displays the
actual data rate based on the user-connected clock source frequency and the component
oversampling factor (only for the Master modes). When this option is not enabled, the clock
configuration is provided by the component. The clock source frequency is calculated or selected
by the component based on the Data rate parameter and Oversampling factor (only for the
Master mode).
The following tables show the valid ranges for the component clock for each data rate. When
using the Clock from terminal option, ensure that the external clock is within these ranges.
Table 1. I2C Slave clock frequency ranges
Standard-mode
Fast-mode
Fast-mode Plus
(0-100 kbps)
(0-400 kbps)
(0-1000 kbps)
Parameter
fSCB
Min
Max
Min
Max
Min
Max
Units
1.55
12.8
7.82
15.38
15.84
48.0
MHz
Note For Slave mode, if the clock frequency is less than lower limit of 1.55 MHz, an error is
generated while building the project.
Table 2. I2C Master modes clock frequency ranges
Parameter
Standard-mode
Fast-mode
Fast-mode Plus
(0-100 kbps)
(0-400 kbps)
(0-1000 kbps)
Min
Max
Min
Max
Min
Max
Units
1.55
3.2
7.82
10.00
14.32
25.8
MHz
Oversampling Low
16
13
16
16
Oversampling High
16
16
16
fSCB
Page 16 of 200
Taking into account the ranges provided in Table 2 on page 16 for clock frequency and
oversampling the calculated data rate ranges are provided in Table 3 on page 17.
It is possible to create data rates that are outside of the ranges provided in Table 3 on page 17.
However creating these data rates requires using clock frequencies or oversampling outside of
the ranges provided in Table 2 on page 16. If a clock frequency or oversampling is used outside
of the range provided in Table 2 on page 16 certain I2C parameters in the I2C specification may
be violated. To determine which specifications are violated refer to the I2C spec parameters
calculation section.
Table 3. I2C master modes data rates ranges
Parameter
Standard-mode
Fast-mode
Fast-mode Plus
(0-100 kbps)
(0-400 kbps)
(0-1000 kbps)
Min
Max
Min
Max
Min
Max
Units
48
100
244
400
447
1000
kbps
Data rate
Note PSoC Creator is responsible for providing requested clock frequency (internal or external
clock) based on current design clock configuration. When the requested clock frequency with
requested tolerance cannot be created, a warning about the clock accuracy range is generated
while building the project. This warning contains the actual clock frequency value created by
PSoC Creator. To remove this warning you must either change the system clock, component
settings or external clock to fit the clocking system requirements.
Byte mode
This option is only applicable for PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/
PSoC 4200M/PSoC 4200L devices. It allows doubling the TX and RX FIFO depth from 8 to 16
bytes. Increasing FIFO depth improves performance of I2C operation, as more bytes can be
transmitted or received without software interaction.
Slave address (7-bits)
This is the I2C address that will be recognized by the slave. It is only applicable for slave modes.
This address is the 7-bit right-justified slave address and does not include the R/W bit. A slave
address between 0x08 and 0x7F may be selected; the default is 0x08.
The value may be entered as decimal or hexadecimal; for hexadecimal numbers type 0x before
the address. The binary input format is supported as well.
Page 17 of 200
The following example shows the 7-bit slave address is 0x1B and the 8-bit address Mask is
0xDE.
7-bits Slave address
R/W
Address
Mask
Result
x = Do not care
Thus the matched 7-bit slave addresses are 0x1B and 0x0B.
The value may be entered as decimal or hexadecimal; for hexadecimal numbers type 0x before
the address. The binary input format is supported as well.
Accept matching address in RX FIFO
This parameter determines whether to accept a matched I 2C slave address in the RX FIFO or
not. This can be useful when more than one I2C address is implemented in a single SCB. In
order to access this address a callback function needs to be registered with the
SCB_SetI2cAddressCustomInterruptHandler() function. Inside this call back function the address
can be read out of the RX FIFO, and then appropriate action can be taken based on the address
in the FIFO. This may include a status update or changing read or write buffer. The callback
function must return the decision made to ACK or NACK the address. The NACK or ACK
command is executed by the I2C slave ISR. If the callback function is not registered the accepted
addresses are ACKed and the address is read from the RX FIFO and discarded.
For more information, refer to the Accept matching address RX FIFO section under the I2C
chapter in this document.
Note If this option is checked and the address is not read in a callback function the address will
appear in the write buffer. This may not be desirable behavior.
Accept general call address
This option enables the hardware to accept the I2C general call address (0x00). In order to
access this general call address a callback function needs to be registered with the
SCB_SetI2cAddressCustomInterruptHandler() function. Inside this callback function the general
Page 18 of 200
call address accept status can be checked, and then appropriate action can be taken based on
the address in the FIFO. This may include status update, changing read or write buffer. The
callback function must return the decision made to ACK or NACK the address. The NACK or
ACK command is executed by the I2C slave ISR. If the callback function is not registered the
general call address is ACKed.
For more information, refer to the Accept General Call section under the I2C chapter in this
document.
Note The general call address accept does not cause wakeup event to occur.
Enable wakeup from Deep Sleep Mode
Use this option to enable the component to wake the system from Deep Sleep when a slave
address match occurs. It is only available for Slave or Multi-Master-Slave mode.
For PSoC 4100/PSoC 4200 devices, the Slave address (7-bits) must be even (bit 0 equal zero)
when this option is enabled.
For all supported devices, the data rate must be less than or equal to 400 kbps for Multi-MasterSlave mode when this option is enabled.
Refer to the Low power modes section under the I2C chapter in this document; refer also to the
Power Management APIs section of the System Reference Guide for more information.
Page 19 of 200
GPIO_OVT pins are fully compliant with the I2C specification (except for hot swap
capability during I2C active communication), but the slew rate must be set appropriately:
Slew rate "Slow" for Standard mode (100 kbps) and Fast mode (400 kbps)
Common GPIO pins are not completely compliant with the I2C specification. Refer to the
Device Datasheet for the details.
Slew rate settings are applied to all pins of the associated port.
Page 20 of 200
pull-up
resistors
Rp
Rp
Device 1
Device 2
For most designs, the default values shown in the following table provide excellent performance
without any calculations. The default values were chosen to use standard resistor values
between the minimum and maximum limits.
Table 4. Recommended Default Pull-up Resistor Values
Standard Mode
(0 100 kbps)
Fast Mode
(0 400 kbps)
Units
4.7 k, 5%
1.74 k, 1%
620, 5%
These values work for designs with 1.8 V to 5.0V VDD, less than 200 pF bus capacitance (CB), up
to 25 A of total input leakage (IIL), up to 0.4 V output voltage level (VOL), and a max VIH of 0.7 *
VDD.
Standard Mode and Fast Mode can use either GPIO [1] or GPIO_OVT PSoC pins. Fast Mode
Plus requires use of GPIO_OVT pins to meet the VOL spec at 20 mA. Calculation of custom pullup resistor values is required if; your design does not meet the default assumptions, you use
series resistors (RS) to limit injected noise, or you want to maximize the resistor value for low
power consumption.
Calculation of the ideal pull-up resistor value involves finding a value between the limits set by
three equations detailed in the NXP I2C specification. These equations are:
Equation 1: RPMIN = (VDD(max) VOL(max)) / IOL(min)
Page 21 of 200
The supply voltage (VDD) limits the minimum pull-up resistor value due to bus devices maximum
low output voltage (VOL) specifications. Lower pull-up resistance increases current through the
pins and can therefore exceed the spec conditions of VOH. Equation 1 is derived using Ohms law
to determine the minimum resistance that will still meet the VOL specification at 3 mA for standard
and fast modes, and 20 mA for fast mode plus at the given VDD.
Equation 2 determines the maximum pull-up resistance due to bus capacitance. Total bus
capacitance is comprised of all pin, wire, and trace capacitance on the bus. The higher the bus
capacitance the lower the pull-up resistance required to meet the specified bus speeds rise time
due to RC delays. Choosing a pull-up resistance higher than allowed can result in failing timing
requirements resulting in communication errors. Most designs with five of fewer I2C devices and
up to 20 centimeters of bus trace length have less than 100 pF of bus capacitance.
A secondary effect that limits the maximum pull-up resistor value is total bus leakage calculated
in Equation 3. The primary source of leakage is I/O pins connected to the bus. If leakage is too
high, the pull-ups will have difficulty maintaining an acceptable VIH level causing communication
errors. Most designs with five or fewer I2C devices on the bus have less than 10 A of total
leakage current.
Internal Pull-Ups
PSoC also has an internal pull-up resistor for each pin that can be used instead of external pullup resistors connected to the I2C bus. These resistors are weak (5.6k ); therefore, their usage
is limited to Standard mode operation according to Table 4 on page 21. Refer to Device
Datasheet parameter RPULLUP for resistor value specification. It is recommended to use external
I2C pull-up resistors because their value can be changed if needed later in the design.
Page 22 of 200
The I2C pins SCL and SDA are buried inside the SCB component. The drive mode for these pins
is Open Drain, Drives Low for use with external pull-up resistors on the I2C bus. To enable use
of the PSoC internal pull-up resistor, the drive mode of the pin must be changed to Resistive Pull
Up. The SCB component GUI does not provide this option; therefore, the drive mode must be
changed by firmware. The pin names are generated from the component name in the schematic and
may require updating. The following code must be added before starting the component:
/* Change SCL and SDA pins drive mode to Resistive Pull Up */
SCB_scl_SetDriveMode(SCB_scl_DM_RES_UP);
SCB_sda_SetDriveMode(SCB_sda_DM_RES_UP);
I2C APIs
Application Programming Interface (API) functions allow you to configure the component using
software. The following table lists and describes the interface to each function. The subsequent
section discusses each function in more detail.
By default, PSoC Creator assigns the instance name SCB_1 to the first instance of a
component in a given design. You can rename the instance to any unique value that follows the
syntactic rules for identifiers. The instance name becomes the prefix of every global function
name, variable, and constant symbol. For readability, the instance name used in the following
table is SCB.
Function
Description
SCB_Start()
SCB_Init()
SCB_Enable()
SCB_Stop()
SCB_Sleep()
SCB_Wakeup()
SCB_I2CInit()
Configures the SCB component for operation in I2C mode. Only applicable
when component is in unconfigured mode.
SCB_I2CSlaveStatus()
SCB_I2CSlaveClearReadStatus()
Returns the slave read status flags and clears slave read status flags.
SCB_I2CSlaveClearWriteStatus()
Returns the slave write status and clears the slave write status flags.
SCB_I2CSlaveSetAddress()
SCB_I2CSlaveSetAddressMask()
Sets slave address mask, a value between 0 and 254 (0x00 to 0xFE).
SCB_I2CSlaveInitReadBuf()
SCB_I2CSlaveInitWriteBuf()
Page 23 of 200
Function
Description
SCB_I2CSlaveGetReadBufSize()
SCB_I2CSlaveGetWriteBufSize()
SCB_I2CSlaveClearReadBuf()
SCB_I2CSlaveClearWriteBuf()
SCB_I2CMasterStatus()
SCB_I2CMasterClearStatus()
SCB_I2CMasterWriteBuf()
SCB_I2CMasterReadBuf()
Reads data from the specified slave address and places the data in the
referenced buffer.
SCB_I2CMasterSendStart()
SCB_I2CMasterSendRestart()
SCB_I2CMasterSendStop()
SCB_I2CMasterWriteByte()
Writes a single byte. This is a manual command that should only be used with
the SCB_I2CMasterSendStart() or SCB_I2CMasterSendRestart() functions.
SCB_I2CMasterReadByte()
Reads a single byte. This is a manual command that should only be used
with the SCB_I2CMasterSendStart() or SCB_I2CMasterSendRestart()
functions.
SCB_I2CMasterGetReadBufSize() Returns the number of bytes that have been transferred with the
SCB_I2CMasterReadBuf() function.
SCB_I2CMasterGetWriteBufSize() Returns the number of bytes that have been transferred with the
SCB_I2CMasterWriteBuf() function.
SCB_I2CMasterClearReadBuf()
Resets the read buffer pointer back to the beginning of the buffer.
SCB_I2CMasterClearWriteBuf()
Resets the write buffer pointer back to the beginning of the buffer.
void SCB_Start(void)
Description:
Invokes SCB_Init() and SCB_Enable(). After this function call the component is enabled
and ready for operation. This is the preferred method to begin component operation.
When configuration is set to Unconfigured SCB, the component must first be initialized
to operate in one of the following configurations: I2C, SPI, UART or EZ I2C. Otherwise
this function does not enable the component.
Parameters:
None
Return Value:
None
Side Effects:
None
Page 24 of 200
void SCB_Init(void)
Description:
Initializes SCB component to operate in one of selected configurations: I2C, SPI, UART
or EZ I2C.
When the configuration is set to Unconfigured SCB, this function does not do any
initialization. Use mode-specific initialization APIs instead: SCB_I2CInit, SCB_SpiInit,
SCB_UartInit or SCB_EzI2CInit.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_Enable(void)
Description:
Enables SCB component operation: activates the hardware and internal interrupt.
For I2C and EZ I2C modes the interrupt is internal and mandatory for operation. For SPI
and UART modes the interrupt can be configured as none, internal or external.
The SCB configuration should be not changed when the component is enabled. Any
configuration changes should be made after disabling the component.
When configuration is set to Unconfigured SCB, the component must first be initialized
to operate in one of the following configurations: I2C, SPI, UART or EZ I2C, using the
mode-specific initialization API. Otherwise this function does not enable the component.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_Stop(void)
Description:
Disables the SCB component: disable the hardware and internal interrupt. It also
disables all TX interrupt sources so as not to cause an unexpected interrupt trigger
because after the component is enabled, the TX FIFO is empty.
Refer to the function SCB_Enable() for the interrupt configuration details.
This function disables the SCB component without checking to see if communication is
in progress. Before calling this function it may be necessary to check the status of
communication to make sure communication is complete. If this is not done then
communication could be stopped mid byte and corrupted data could result.
Parameters:
None
Return Value:
None
Side Effects:
None
Page 25 of 200
void SCB_Sleep(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_Wakeup(void)
Description:
Prepares the SCB component for Active mode operation after Deep Sleep.
The Enable wakeup from Deep Sleep Mode selection has influence on this function
implementation:
Checked: restores the component Active mode configuration.
Unchecked: enables the component if it was enabled before enter Deep Sleep.
This function should not be called after exiting Sleep.
Parameters:
None
Return Value:
None
Side Effects:
Calling the SCB_Wakeup() function without first calling the SCB_Sleep() function may
produce unexpected behavior.
Page 26 of 200
Parameters:
config: pointer to a structure that contains the following list of fields. These fields match the
selections available in the customizer. Refer to the customizer for further description of the
settings.
Field
uint32 mode
Description
Mode of operation for I2C. The following defines are available choices:
SCB_I2C_MODE_SLAVE
SCB_I2C_MODE_MASTER
SCB_I2C_MODE_MULTI_MASTER
SCB_I2C_MODE_MULTI_MASTER_SLAVE
uint32 oversampleLow
Oversampling factor for the low phase of the I2C clock. Ignored for Slave
mode operation. The oversampling factors need to be chosen in
conjunction with the clock rate in order to generate the desired rate of I2C
operation.
uint32 oversampleHigh
Oversampling factor for the high phase of the I2C clock. Ignored for Slave
mode operation.
uint32 enableMedianFilter
This field is left for compatibility and its value is ignored. Median filter is
enabled or disabled depends on the data rate and operation mode.
uint32 slaveAddr
uint32 slaveAddrMask
8-bit slave address mask. Bit 0 must have a value of 0. Ignored for nonslave modes.
uint32 acceptAddr
0 disable
1 enable
When enabled the matching address is received into the RX FIFO.
The callback function has to be registered to handle the address accepted
in the RX FIFO. Refer to section Accept matching address RX FIFO for
more information.
uint32 enableWake
0 disable
1 enable
Ignored for non-slave modes.
uint8 enableByteMode
Ignored for all devices other than PSoC 4100 BLE/PSoC 4200 BLE/
PSoC 4100M/PSoC 4200M/PSoC 4200L
0 disable
1 enable
When enabled the TX and RX FIFO depth is 16 bytes.
uint16 dataRate
Data rate in kbps used while the of I2C is in operation. Valid values are
between 1 and 1000.
Note This filed must be initialized for correct operation if Unconfigured SCB
was utilized with previous version of the component.
Page 27 of 200
uint8 acceptGeneralAddr
0 disable
1 enable
When enabled the I2C general call address (0x00) will be accepted by the
I2C hardware and trigger an interrupt
The callback function has to be registered to handle a general call address.
Refer to section Accept General Call for more information.
Return Value:
None
Side Effects:
None
Page 28 of 200
uint32 SCB_I2CSlaveStatus(void)
Description:
Parameters:
None
Return Value:
Description
Slave read transfer complete. Set when master indicates
it is done reading by sending a NAK [3].
The read error condition status bit must be checked to
ensure that the read transfer was completed successfully.
SCB_I2C_SSTAT_RD_BUSY
SCB_I2C_SSTAT_RD_OVFL
SCB_I2C_SSTAT_RD_ERR
SCB_I2C_SSTAT_WR_CMPLT
SCB_I2C_SSTAT_WR_BUSY
SCB_I2C_SSTAT_WR_OVFL
SCB_I2C_SSTAT_WR_ERR
Side Effects:
None
NAK is an abbreviation for negative acknowledgment or not acknowledged. I 2C documents commonly use NACK
while the rest of the networking world uses NAK. They mean the same thing.
Page 29 of 200
uint32 SCB_I2CSlaveClearReadStatus(void)
Description:
Clears the read status flags and returns their values. No other status flags are affected.
Parameters:
None
Return Value:
uint32: Current read status of slave. See the SCB_I2CSlaveStatus() function for constants.
Side Effects:
uint32 SCB_I2CSlaveClearWriteStatus(void)
Description:
Clears the write status flags and returns their values. No other status flags are affected.
Parameters:
None
Return Value:
uint32: Current write status of slave. See the SCB_I2CSlaveStatus() function for constants.
Side Effects:
Parameters:
uint32 address: I2C slave address. This address is the 7-bit right-justified slave address
and does not include the R/W bit.
The address value is not checked to see if it violates the I2C spec. The preferred addresses
are between 8 and 120 (0x08 to 0x78).
Return Value:
None
Side Effects:
None
Parameters:
Return Value:
None
Side Effects:
None
Page 30 of 200
Sets the buffer pointer and size of the read buffer. This function also resets the transfer
count returned with the SCB_I2CSlaveGetReadBufSize() function.
Parameters:
Return Value:
None
Side Effects:
If this function is called during a bus transaction, data from the previous buffer location
and the beginning of the current buffer may be transmitted.
Sets the buffer pointer and size of the write buffer. This function also resets the transfer
count returned with the SCB_I2CSlaveGetWriteBufSize() function.
Parameters:
Return Value:
None
Side Effects:
If this function is called during a bus transaction, data may be received in the previous
buffer and the current buffer location.
uint32 SCB_I2CSlaveGetReadBufSize(void)
Description:
Returns the number of bytes read by the I2C master since the
SCB_I2CSlaveInitReadBuf() or SCB_I2CSlaveClearReadBuf() function was called.
The maximum return value is the size of the read buffer.
Parameters:
None
Return Value:
uint32: Bytes read by master. If the transfer is not yet complete, it returns zero until
transfer completion.
Side Effects:
Page 31 of 200
uint32 SCB_I2CSlaveGetWriteBufSize(void)
Description:
Returns the number of bytes written by the I2C master since the
SCB_I2CSlaveInitWriteBuf() or SCB_I2CSlaveClearWriteBuf() function was called.
The maximum return value is the size of the write buffer.
Parameters:
None
Return Value:
uint32: Bytes written by master. If the transfer is not yet complete, it returns the byte
count transferred so far.
Side Effects:
void SCB_I2CSlaveClearReadBuf(void)
Description:
Resets the read pointer to the first byte in the read buffer. The next byte read by the
master will be the first byte in the read buffer.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_I2CSlaveClearWriteBuf(void)
Description:
Resets the write pointer to the first byte in the write buffer. The next byte written by the
master will be the first byte in the write buffer.
Parameters:
None
Return Value:
None
Side Effects:
None
Page 32 of 200
uint32 SCB_I2CMasterStatus(void)
Description:
Parameters:
None
Return Value:
uint32: Current status of I2C master. This status incorporates status constants. Each
constant is a bit field value. The value returned may have multiple bits set to indicate the
status of the read or write transfer.
Master Status constants
SCB_I2C_MSTAT_RD_CMPLT
Description
Read transfer complete.
The error condition status bits must be checked
to ensure that read transfer was completed
successfully.
SCB_I2C_MSTAT_WR_CMPLT
SCB_I2C_MSTAT_XFER_INP
Transfer in progress.
SCB_I2C_MSTAT_XFER_HALT
SCB_I2C_MSTAT_ERR_SHORT_XFER
SCB_I2C_MSTAT_ERR_ADDR_NAK
SCB_I2C_MSTAT_ERR_ARB_LOST
SCB_I2C_MSTAT_ERR_BUS_ERROR
SCB_I2C_MSTAT_ERR_ABORT_XFER
SCB_I2C_MSTAT_ERR_XFER
Side Effects:
None
Page 33 of 200
uint32 SCB_I2CMasterClearStatus(void)
Description:
Parameters:
None
Return Value:
Side Effects:
None
Page 34 of 200
Automatically writes an entire buffer of data to a slave device. Once the data transfer is
initiated by this function, further data transfer is handled by the included ISR.
Enables the I2C interrupt and clears SCB_ I2C_MSTAT_WR_CMPLT status.
Parameters:
Description
SCB_I2C_MODE_COMPLETE_XFER
SCB_I2C_MODE_REPEAT_START
SCB_I2C_MODE_NO_STOP
Return Value:
Description
SCB_I2C_MSTR_NO_ERROR
SCB_I2C_MSTR_BUS_BUSY
SCB_I2C_MSTR_NOT_READY
Side Effects:
None
Page 35 of 200
Automatically reads an entire buffer of data from a slave device. Once the data transfer is
initiated by this function, further data transfer is handled by the included ISR.
Enables the I2C interrupt and clears SCB_ I2C_MSTAT_RD_CMPLT status.
Parameters:
Return Value:
Description
SCB_I2C_MSTR_NO_ERROR
SCB_I2C_MSTR_BUS_BUSY
SCB_I2C_MSTR_NOT_READY
Side Effects:
None
uint32 SCB_I2CMasterGetReadBufSize(void)
Description:
Parameters:
None
Return Value:
uint32: Byte count of transfer. If the transfer is not yet complete, it returns the byte count
transferred so far.
Side Effects:
Page 36 of 200
uint32 SCB_I2CMasterGetWriteBufSize(void)
Description:
Parameters:
None
Return Value:
uint32: Byte count of transfer. If the transfer is not yet complete, it returns zero unit
transfer completion.
Side Effects:
void SCB_I2CMasterClearReadBuf(void)
Description:
Resets the read buffer pointer back to the first byte in the buffer.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_I2CMasterClearWriteBuf(void)
Description:
Resets the write buffer pointer back to the first byte in the buffer.
Parameters:
None
Return Value:
None
Side Effects:
None
Page 37 of 200
Generates Start condition and sends slave address with read/write bit. Disables the I2C
interrupt.
This function is blocking. It does not return until the Start condition and address byte are
sent, a ACK/NAK is received, or errors have occurred.
Parameters:
uint32 slaveAddress: Right justified 7-bit Slave address (valid range 8 to 120).
uint32 bitRnW: Direction of the following transfer. It is defined by read/write bit within
address byte.
Direction constants
Return Value:
Description
SCB_I2C_WRITE_XFER_MODE
SCB_I2C_READ_XFER_MODE
Description
SCB_I2C_MSTR_NO_ERROR
SCB_I2C_MSTR_BUS_BUSY
SCB_I2C_MSTR_NOT_READY
SCB_I2C_MSTR_ERR_LB_NAK
SCB_I2C_MSTR_ERR_ARB_LOST
SCB_I2C_MSTR_ERR_BUS_ERR
Side Effects:
Page 38 of 200
None
Generates ReStart condition and sends slave address with read/write bit.
If the last transaction was a read the NAK is sent before the ReStart to complete the
transaction.
This function is blocking and does not return until the ReStart condition and address are
sent, a ACK/NAK is received, or errors have occurred.
Parameters:
Return Value:
Side Effects:
A valid Start or ReStart condition must be generated before calling this function. This
function does nothing if Start or ReStart conditions failed before this function was called.
For read transaction, at least one byte has to be read before ReStart generation.
uint32 SCB_I2CMasterSendStop(void)
Description:
Generates Stop condition on the bus. The NAK is generated before Stop in case of a
read transaction.
At least one byte has to be read if a Start or ReStart condition with read direction was
generated before.
This function is blocking and does not return until a Stop condition is generated or error
occurred.
Parameters:
None
Return Value:
Side Effects:
A valid Start or ReStart condition must be generated before calling this function. This
function does nothing if Start or ReStart condition failed before this function was called.
For read transaction, at least one byte has to be read before Stop generation.
Page 39 of 200
Parameters:
Return Value:
Side Effects:
Description
SCB_I2C_MSTR_NO_ERROR
SCB_I2C_MSTR_NOT_READY
SCB_I2C_MSTR_ERR_LB_NAK
SCB_I2C_MSTR_ERR_ARB_LOST
SCB_I2C_MSTR_ERR_BUS_ERR
A valid Start or ReStart condition must be generated before calling this function. This
function does nothing if Start or ReStart conditions failed before this function was called.
Reads one byte from a slave and generates ACK or prepares to generate NAK. The
NAK will be generated before Stop or ReStart condition by SCB_I2CMasterSendStop()
or SCB_I2CMasterSendRestart() function appropriately.
This function is blocking. It does not return until a byte is received or an error occurs.
Parameters:
Description
Generates ACK.
The master notifies slave that transfer continues.
SCB_I2C_NAK_DATA
Return Value:
uint32: Byte read from the slave. In case of error the MSB of returned data is set to 1.
Side Effects:
A valid Start or ReStart condition must be generated before calling this function. This
function does nothing and returns invalid byte value if Start or ReStart conditions failed
before this function was called.
Page 40 of 200
Global Variables
Knowledge of these variables is not required for normal operations.
Variable
Description
SCB_initVar
SCB_initVar indicates whether the SCB component has been initialized. The variable is initialized
to 0 and set to 1 the first time SCB_Start() is called. This allows the component to restart without
reinitialization after the first call to the SCB_Start() routine.
If reinitialization of the component is required, then the SCB_Init() function can be called before
the SCB_Start() or SCB_Enable() function.
Master
MultiMaster
MultiMasterSlave
SCB_I2CInit()
SCB_I2CSlaveStatus()
SCB_I2CSlaveClearReadStatus()
SCB_I2CSlaveClearWriteStatus()
SCB_I2CSlaveSetAddress()
SCB_I2CSlaveSetAddressMask()
SCB_I2CSlaveInitReadBuf()
SCB_I2CSlaveInitWriteBuf()
SCB_I2CSlaveGetReadBufSize()
SCB_I2CSlaveGetWriteBufSize()
SCB_I2CSlaveClearReadBuf()
SCB_I2CSlaveClearWriteBuf()
SCB_I2CMasterStatus()
SCB_I2CMasterClearStatus()
SCB_I2CMasterWriteBuf()
SCB_I2CMasterReadBuf()
SCB_I2CMasterSendStart()
SCB_I2CMasterSendRestart()
SCB_I2CMasterSendStop()
SCB_I2CMasterWriteByte()
SCB_I2CMasterReadByte()
Function
Page 41 of 200
Slave
Master
MultiMaster
MultiMasterSlave
SCB_I2CMasterGetReadBufSize()
SCB_I2CMasterGetWriteBufSize()
SCB_I2CMasterClearReadBuf()
SCB_I2CMasterClearWriteBuf()
Function
Bootloader Support
The SCB component in I2C mode can be used as a communication component for the
Bootloader. You should use the following configurations to support communication protocol from
an external system to the Bootloader:
For more information about the Bootloader, refer to the Bootloader component datasheet.
The following API functions are provided for Bootloader use.
Function
Description
SCB_CyBtldrCommStart()
SCB_CyBtldrCommStop()
SCB_CyBtldrCommReset()
Sets read and write I2C buffers to the initial state and resets the slave status.
SCB_CyBtldrCommRead()
Allows the caller to read data from the bootloader host (the host writes the data).
SCB_CyBtldrCommWrite()
Allows the caller to write data to the bootloader host (the host writes the data).
void SCB_CyBtldrCommStart(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
Page 42 of 200
void SCB_CyBtldrCommStop(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_CyBtldrCommReset(void)
Description:
Sets read and write I2C buffers to the initial state and resets the slave status.
Parameters:
None
Return Value:
None
Side Effects:
None
Allows the caller to read data from the bootloader host (the host writes the data). The
function handles polling to allow a block of data to be completely received from the host
device.
Parameters:
uint8 pData[]: Pointer to the block of data to be read from bootloader host.
uint16 size: Number of bytes to be read from bootloader host.
uint16 *count: Pointer to variable to write the number of bytes actually read by the
bootloader host.
uint8 timeOut: Number of units in 10 ms to wait before returning because of a timeout.
Return Value:
Side Effects:
None
Page 43 of 200
Allows the caller to write data to the bootloader host (the host reads the data). The function
does not use timeout and returns after data has been copied into the slave read buffer. This
data available to be read by the bootloader host until following host data write.
Parameters:
const uint8 pData[]: Pointer to the block of data to send to the bootloader host.
uint16 size: Number of bytes to send to bootloader host.
uint16 *count: Pointer to variable to write the number of bytes actually written to the
bootloader host.
uint8 timeOut: The timeout is not used by this function. The function returns as soon as
data is copied into the slave read buffer.
Return Value:
Side Effects:
None
Using the functions above sets a pointer and byte count for the read and write buffers. The
bufSize for these functions may be less than or equal to the actual array size, but it should never
be larger than the available memory pointed to by the rdBuf or wrBuf pointers.
Page 44 of 200
uint8 rdBuf[10];
I2C_SlaveInitReadBuf(rdBuf, 10);
Index
0x1243
0x09
uint8 wrBuf[8];
I2C_SlaveInitWriteBuf(wrBuf, 8);
0x08
0x07
Index
0x06
I2C Read
Buffer
0x05
0x07
0x123A
0x06
0x1237
0x05
0x04
0x03
0x02
0x01
0x00
0x02
0x1230
0x01
0x00
0x0000
This resets the index back to zero. The next byte read or written by the I2C master is the first
byte in the array. Before these clear buffer commands are used, the data in the arrays should be
read or updated.
Multiple reads or writes by the I2C master continue to increment the array index until the clear
buffer commands are used or the array index attempts to grow beyond the array size. Figure 3
shows an example where an I2C master has executed two write transactions. The first write was
four bytes and the second write was six bytes. The sixth byte in the second transaction was
NAKed by the slave to signal that the end of the buffer had occurred. If the master tried to write a
seventh byte for the second transaction or started to write more bytes with a third transaction,
each byte would be NAKed and discarded until the buffer is reset.
Page 45 of 200
Using the SCB_I2CSlaveClearWriteBuf() function after the first transaction resets the index back
to zero and causes the second transaction to overwrite the data from the first transaction. Make
sure data is not lost by overflowing the buffer. The data in the buffer should be processed by the
slave before resetting the buffer index.
Figure 3. System Memory
System Memory
uint8 wrBuf[10];
0xFFFF
Index
Read or Write
Buffer
Visible by
I2C Master
Trans2 Byte6
Trans2 Byte5
Trans2 Byte4
Trans2 Byte3
Trans2 Byte2
Trans2 Byte1
Trans1 Byte4
Trans1 Byte3
Trans1 Byte2
Trans1 Byte1
Transaction 2
Transaction 1
0x1239
0x1230
0x0000
Both the read and write buffers have four status bits to signal transfer complete, transfer in
progress, and buffer overflow. When a transfer starts, the busy flag is set. When the transfer is
complete, the transfer complete flag is set and the busy flag is cleared. If a second transfer is
started, both the busy and transfer complete flags may be set at the same time. The following
table shows read and write status flags.
Slave Status Constants
Description
SCB_I2C_SSTAT_RD_CMPLT
SCB_I2C_SSTAT_RD_BUSY
SCB_I2C_SSTAT_RD_OVFL
SCB_I2C_SSTAT_RD_ERR
SCB_I2C_SSTAT_WR_CMPLT
SCB_I2C_SSTAT_WR_BUSY
SCB_I2C_SSTAT_WR_OVFL
SCB_I2C_SSTAT_WR_ERR
Page 46 of 200
The following code example initializes the write buffer then waits for a transfer to complete. Once
the transfer is complete, the data is then copied into a working array to handle the data. In many
applications, the data does not have to be copied to a second location, but instead can be
processed in the original buffer. You could create an almost identical read buffer example by
replacing the write functions and constants with read functions and constants. Processing the
data may mean new data is transferred into the slave buffer instead of out.
uint8 wrBuf[10u];
uint8 userArray[10u];
uint32 byteCnt;
uint32 status;
/* Initialize write buffer before call SCB_Start */
SCB_I2CSlaveInitWriteBuf((uint8 *) wrBuf, 10u);
/* Start I2C Slave operation */
SCB_Start();
/* The code below is not protected from the interruption. This might be required
to not cause buffer update by the following I2C write transaction while it is
handled.*/
/* Wait for I2C master to complete a write */
status = SCB_I2CSlaveStatus();
if(0u != (status & SCB_I2C_SSTAT_WR_CMPLT))
{
if(0u == (status & SCB_I2C_SSTAT_WR_ERR))
{
byteCnt = SCB_I2CSlaveGetWriteBufSize();
for(i=0; i < byteCnt; i++)
{
userArray[i] = wrBuf[i]; /* Copy data to local array */
}
}
/* Clean-up status and buffer pointer */
SCB_I2CSlaveClearWriteStatus();
SCB_I2CSlaveClearWriteBuf();
}
Page 47 of 200
Page 48 of 200
switch(activeAddress)
{
case (I2C_SLAVE_ADDRESS1):
/* Address 1: Setup buffers for read and write */
SCB_I2CSlaveInitReadBuf (addr1BufRead, ADDR1_BUFFER_SIZE);
SCB_I2CSlaveInitWriteBuf(addr1BufWrite, ADDR1_BUFFER_SIZE);
response = SCB_I2C_ACK_ADDR;
break;
case (I2C_SLAVE_ADDRESS2):
/* Address 2: Setup buffers for read and write */
SCB_I2CSlaveInitReadBuf (addr2BufRead, ADDR2_BUFFER_SIZE);
SCB_I2CSlaveInitWriteBuf(addr2BufWrite, ADDR2_BUFFER_SIZE);
response = SCB_I2C_ACK_ADDR;
break;
default:
/* NAK all other accepted addresses.
* The SCB_I2C_SSTAT_WR_CMPLT or SCB_I2C_SSTAT_RD_CMPLT flags are not
* affected when address is NACKed */
break;
}
return (response);
}
int main()
{
/* Register address callback function */
SCB_SetI2cAddressCustomInterruptHandler(&AddressAccepted);
/* Start I2C slave operation */
SCB_Start();
CyGlobalIntEnable;
for(;;)
{
if (0u != (SCB_I2CSlaveStatus() & SCB_I2C_SSTAT_WR_CMPLT))
{
if (I2C_SLAVE_ADDRESS1 == activeAddress)
{
/* Handle slave address 1: master writes */
}
else
{
/* Handle slave address 2: master writes */
}
/* Clean-up status and buffer pointer */
SCB_I2CSlaveClearWriteBuf();
Page 49 of 200
SCB_I2CSlaveClearWriteStatus();
}
if (0u != (SCB_I2CSlaveStatus() & SCB_I2C_SSTAT_RD_CMPLT))
{
if (I2C_SLAVE_ADDRESS1 == activeAddress)
{
/* Handle slave address 1: master reads */
}
else
{
/* Handle slave address 2: master reads */
}
/* Clean-up status and buffer pointer */
SCB_I2CSlaveClearReadBuf();
SCB_I2CSlaveClearReadStatus();
}
}
}
Note All slave functions return the values related to the most recent slave address which was
accessed by the master.
Note Any slave matched address wakes device from deep sleep independently whether it will be
ACKed or NACKed.
Accept General Call
The general call address is used for addressing every device connected to the I2C-bus at the
same time. In the default I2C configuration, the I2C slave ignores the general call address and will
generate a NAK response. Enabling the Accept general call address option in the I2C Basic
Tab forces the component to accept the general call address and will call the user generated
custom callback function after an address (the specific slave address or general call address) is
received. The interrupt source SCB_INTR.SLAVE_I2C_GENERAL notifies that general call
address is received.
The following code provides an example of a custom function which handles the general call
address and a single slave address.
/* Slave read and write buffers */
#define SLAVE_BUFFER_SIZE
(10u)
uint8 slaveBufWrite[SLAVE_BUFFER_SIZE];
uint8 slaveBufRead[SLAVE_BUFFER_SIZE];
/* Gen call write buffer */
#define GEN_CALL_BUFFER_SIZE
(2u)
uint8 genCallBufWrite[GEN_CALL_BUFFER_SIZE];
/* Store the address which was more recently accessed */
uint8 activeAddress;
#define I2C_SLAVE_ADDRESS
(SCB_I2C_SLAVE_ADDRESS)
#define I2C_GENERAL_CALL_ADDRESS
(0x00u)
Page 50 of 200
uint32 AddressAccepted(void)
{
uint32 response;
/* ACK slave address or general call address access */
response = SCB_I2C_ACK_ADDR;
/* Prepare for general call address */
if (0u != (SCB_GetSlaveInterruptSourceMasked() & SCB_INTR_SLAVE_I2C_GENERAL))
{
/* Setup only write buffer as R/W bit is always 0 */
SCB_I2CSlaveInitWriteBuf(genCallBufWrite, GEN_CALL_BUFFER_SIZE);
/* Set active address to be general call */
activeAddress = I2C_GENERAL_CALL_ADDRESS;
}
/* Prepare for slave address access */
else
{
/* Restore slave write buffer */
SCB_I2CSlaveInitWriteBuf(slaveBufWrite, SLAVE_BUFFER_SIZE);
/* Set active address to be slave address */
activeAddress = I2C_SLAVE_ADDRESS;
}
return (response);
}
int main()
{
/* Register address callback function */
SCB_SetI2cAddressCustomInterruptHandler(&AddressAccepted);
/* Start I2C slave operation */
SCB_Start();
CyGlobalIntEnable;
for(;;)
{
if (0u != (SCB_I2CSlaveStatus() & SCB_I2C_SSTAT_WR_CMPLT))
{
if (I2C_SLAVE_ADDRESS == activeAddress)
{
/* Handle slave address: master writes */
}
else
{
/* Handle general call address: master writes */
}
/* Clean-up status and buffer pointer */
SCB_I2CSlaveClearWriteBuf();
Page 51 of 200
SCB_I2CSlaveClearWriteStatus();
}
}
}
Note All slave functions return the values related to the most recent slave address which was
accessed by the master.
Note The general call address wakes up the device from deep sleep.
Master/Multi-Master Operation
Master and Multi-Master operation are basically the same, with two exceptions. When operating
in Multi-Master mode, the bus should always be checked to see if it is busy. Another master may
already be communicating with another slave. In this case, the program must wait until the
current operation is complete before issuing a start transaction. The program looks at the return
value, which sets a busy status if another master has control of the bus.
The second difference is that, in Multi-Master mode, two masters can start at the exact same
time. If this happens, one of the two masters loses arbitration. You must check for this condition
after each byte is transferred. The component automatically checks for this condition and
responds with an error if arbitration is lost.
There are two options when operating the I2C master: manual and automatic. In automatic mode,
a buffer is created to hold the entire transfer. In the case of a write operation, the buffer is
prefilled with the data to be sent. If data is to be read from the slave, a buffer at least the size of
the packet needs to be allocated. To write an array of bytes to a slave in automatic mode, use
the following function.
uint32 SCB_I2CMasterWriteBuf(uint32 slaveAddress, uint8 * wrData, uint32 cnt,
uint32 mode)
The slaveAddress variable is a right-justified 7-bit slave address of 0 to 127. The component API
automatically appends the write flag to the LSb of the address byte. The array of data to transfer
is pointed to with the second parameter, wrData. The cnt parameter is the number of bytes to
transfer. The last parameter, mode, determines how the transfer starts and stops. A transaction
may begin with a restart instead of a start, or halt before the stop sequence. These options allow
back-to-back transfers where the last transfer does not send a stop and the next transfer issues
a restart instead of a start.
A read operation is almost identical to the write operation. The same parameters with the same
constants are used.
uint32 SCB_I2CMasterReadBuf(uint32 slaveAddress, uint8 * rdData, uint32 cnt,
uint32 mode);
Both of these functions return status. See the status table for the SCB_I2CMasterStatus()
function return value. Since the read and write transfers complete in the background during the
I2C interrupt code, the SCB_I2CMasterStatus() function can be used to determine when the
transfer is complete. A code snippet that shows a typical write to a slave follows.
Page 52 of 200
The I2C master can also be operated manually. In this mode, each part of the write transaction is
performed with individual commands.
status = SCB_I2CMasterSendStart(8u, SCB_I2C_WRITE_XFER_MODE);
if(SCB_I2C_MSTR_NO_ERROR == status)
/* Check if transfer completed without
errors */
{
/* Send array of 5 bytes */
for(i=0; i<5u; i++)
{
status = SCB_I2CMasterWriteByte(userArray[i]);
if(SCB_I2C_MSTR_NO_ERROR != status)
{
break;
}
}
}
SCB_I2CMasterSendStop();
/* Send Stop */
A manual read transaction is similar to the write transaction except the last byte should be
NAKed. The example below shows a typical manual read transaction.
status = SCB_I2CMasterSendStart(8u, SCB_I2C_READ_XFER_MODE);
if(SCB_I2C_MSTR_NO_ERROR == status)
/* Check if transfer completed without
errors */
{
/* Read array of 5 bytes */
for(i=0; i<5u; i++)
{
if(i < 4u)
{
userArray[i] = SCB_I2CMasterReadByte(SCB_I2C_ACK_DATA);
}
else
{
userArray[i] = SCB_I2CMasterReadByte(SCB_I2C_NAK_DATA);
}
}
}
SCB_I2CMasterSendStop();
/* Send Stop */
Page 53 of 200
Page 54 of 200
else
{
/* Slave is busy. Do not enter Deep Sleep.
*/
/* Exit critical section to continue slave operation */
CyExitCriticalSection(intState);
}
For devices other than PSoC 4100 /PSoC 4200, the component clock must be disabled before
calling SCB_Sleep(), and then enabled after calling SCB_Wakeup(); otherwise, the SCL will lock
up after wakeup from Deep Sleep. Disabling and re-enabling the component clock is managed
by the SCB_Sleep() and SCB_Wakeup() APIs when the Clock from terminal option is disabled.
Otherwise, when the Clock from terminal option is enabled, the code provided above requires
modification to enable and disable the clock source connected to the SCB component. Review
the following modified code and highlighted in blue (ScbClock the instance name of clock
component connected to the SCB):
if(0u == status)
{
SCB_Sleep();
/* Configure the slave to be wakeup source */
ScbClock_Stop(); /* Disable the SCB clock */
CySysPmDeepSleep();
/* Exit critical section to continue slave operation */
CyExitCriticalSection(intState);
SCB_Wakeup();
/* Configure the slave to active mode operation */
ScbClock _Start(); /* Enable the SCB clock */
}
For devices other than PSoC 4100 /PSoC 4200 configured in Multi-Master-Slave mode only, in
order for the component to be a wake-up source from deep sleep, the configuration of the
component must be changed before deep sleep and after the part wakes from deep sleep. This
configuration change occurs automatically in the SCB_Sleep() function, and any function that
starts an I2C master transaction. During this configuration change the component is disabled.
After the configuration has been changed, it is re-enabled. During the time it is disabled, any
incoming addresses to the slave will be NAKed; the external master will have to retry to access
the slave.
Figure 4. Master transaction wakes up device on slave address match
SCB_Sleep()
call
Transfer to other slave
Or bus IDLE
Address
match
S
Address
R/W
SCB_Wakeup()
call
Clock streching
Data
Active
Deep Sleep
Mode transition
Active
Page 55 of 200
Page 56 of 200
desired (Data rate * Oversampling). The oversampling is controlled by the user. This
method is left to provide backward compatibility with previous versions of component.
3. Connect a user configurable clock to the SCB component. This option is enabled by
checking the Clock from terminal control. The user still uses the GUI to configure the
oversampling factor low and high. This method provides full control of the data rate
configuration.
Independent of chosen method the component displays actual data rate for Master. This data
rate might differ from the observed data rate on the bus due to the tR and tF time.
I2C spec parameters calculation
The ranges provided in Table 2 on page 16 assume worst case conditions on the bus; often a
bus will never experience worst case conditions. The following section describes how to
calculate various I2C parameters based on the connected clock frequency and oversampling
factors. This information can be used to determine if the chosen connected clock frequency and
oversampling factor meet I2C specifications on your I2C bus.
To find the frequency of the connected clock open the PSoC Creator Design-Wide Resources
(DWR) file, and open the Clock Tab. If you used an internal clock look for a clock name that
contains the component instance name with the suffix _SCBCLK. If you used the clock from
terminal option, look for the name of your clock. The Nominal frequency has to be taken but it
might differ from the Desired frequency due to design clock configuration.
Also the clock accuracy should be taken to account. The master device generates fSCL with the
accuracy of the provided clock source. Therefore when maximum data rate (for selected data
rate mode) is used the slave has to tolerate this inaccuracy otherwise the fSCL has to be reduced
or more accurate clock source provided.
The slave device is less sensitive to clock accuracy than the master as only when clock
frequency is close to low or high limit (for the selected data rate mode) is provided the clock
source accuracy has to be taken into account. The clock should not run too slow due negative
deviation as well as too fast due to positive deviation. The slave has wide range of allowed
clocks therefore selecting clock frequency in range (low limit + negative deviation) to (high limit
positive deviation) eliminates effect of the clock source accuracy.
For master modes Table 2 on page 16 contains the ranges of clock frequencies for the selected
data rate. Keeping the clock frequency within these ranges ensures that tVD;DAT and tVD;ACK
parameters from I2C spec are met.
For Data rates of 0-400 kbps:
tVD;DAT = (3/ fSCBCLK) + tR_0%_70% + 90 nsec
For Data rates of 401-1000 kbps:
tVD;DAT = (4/ fSCBCLK) + tR_0%_70%
Note tR_0%_70% is the rising time from 0% to 70% to be measured for specific I2C bus.
Note The same equation applies for tVD;ACK
Page 57 of 200
Page 58 of 200
EZI2C [4]
The I2C bus is an industry standard, two-wire hardware interface developed by Philips. The
master initiates all communication on the I2C bus and supplies the clock for all slave devices.
The EZI2C Slave implements an I2C register-based slave device. It is compatible [1] with I2C
Standard-mode, Fast-mode, and Fast-mode Plus devices as defined in the NXP I2C-bus
specification.
The EZI2C Slave is a unique implementation of an I2C slave in that all communication between
the master and slave is handled in the ISR (Interrupt Service Routine) and requires no
interaction with the main program flow. The interface appears as shared memory between the
master and slave. Once the EZI2C_Start() function is called, there is little need to interact with
the API.
Input/Output Connections
This section describes the various input and output connections for the SCB component. An
asterisk (*) in the list of terminals indicates that the terminal may be hidden on the symbol under
the conditions listed in the description of that terminal.
clock Input*
Clock that operates this block. The presence of this terminal varies depending on the Clock
from terminal parameter.
The interface-specific pins are buried inside the component because these pins use dedicated
connections and are not routable as general purpose signals. See the I/O System section in the
device Technical Reference Manual (TRM) for more information.
This is a firmware implementation of the EZI2C protocol on top of I2C (non-EZ mode). All communication
between the master and slave is handled in the ISR (Interrupt Service Routine). The data buffer has to be
allocated in the RAM. The SCB component does not support EZI2C (EZ-mode), which uses a 32-bytes hardware
buffer.
Page 59 of 200
Page 60 of 200
Parameter
fSCB
Standard-mode
Fast-mode
Fast-mode Plus
(0-100 kbps)
(0-400 kbps)
(0-1000 kbps)
Min
Max
Min
Max
Min
Max
Units
1.55
12.8
7.82
15.38
15.84
48.0
MHz
Note When the clock frequency is less than the lower limit of 1.55 MHz, an error is generated
while building the project.
Note PSoC Creator is responsible for providing requested clock frequency (internal or external
clock) based on current design clock configuration. When the requested clock frequency with
requested tolerance cannot be created, a warning about the clock accuracy range is generated
while building the project. This warning contains the actual clock frequency value created by
PSoC Creator. To remove this warning you must either change the system clock, component
settings or external clock to fit the clocking system requirements.
Clock stretching
This parameter applies clock stretching on the SCL line if the EZ I2C slave is not ready to
respond. Enabling this option ensures consistent slave operation for any EZ I 2C slave interrupt
latency because the I2C transaction is paused by clock stretching. Without the clock stretching
option enabled, the design needs to service the EZ I2C slave interrupt fast enough to provide
correct slave operation.
Byte mode
This option is only applicable for PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/
PSoC 4200L devices. It allows doubling the TX and RX FIFO depth from 8 to 16 bytes.
Increasing the FIFO depth improves performance of EZ I2C operation when clock stretching is
enabled, as more bytes can be transmitted or received without software interaction. This option
does not improve EZ I2C operation when clock stretching is disabled; therefore, it is not available
for this mode.
Page 61 of 200
Number of addresses
This option determines whether 1 (default) or 2 independent I2C slave addresses are recognized.
If two addresses are recognized, then address detection will be performed in software. When the
Clock Stretching option is disabled, the number of address choices is restricted to 1.
Primary slave address (7-bits)
This is an I2C address that will be recognized by the slave as the primary address. This address
is the 7-bit right-justified slave address and does not include the R/W bit. A slave address
between 0x08 and 0x7F may be selected; the default is 0x08.
The value may be entered as decimal or hexadecimal; for hexadecimal numbers type 0x before
the address.
Secondary slave address (7-bits)
This is an I2C address that will be recognized by the slave as the secondary address. This
address is the 7-bit right-justified slave address and does not include the R/W bit. A slave
address between 0x08 and 0x7F may be selected; the default is 0x09. Refer to Preferable
Secondary Address Choice.
The value may be entered as decimal or hexadecimal; for hexadecimal numbers type 0x before
the address.
Sub-address size
This option determines what range of data can be accessed. You can select a sub-address of 8
bits (default) or 16 bits. If you use a sub-address size of 8 bits, the master can only access data
offsets between 0 and 255. You may also select a sub-address size of 16 bits. That will allow the
I2C master to access data arrays of up to 65,535 bytes.
Enable wakeup from Deep Sleep Mode
Use this option to enable the component to wake the system from Deep Sleep when a slave
address match occurs.
Enabling this option adds the following restrictions (only for PSoC 4100/PSoC 4200 devices):
Refer to the Low power modes section in the EZI2C chapter of this document and Power
Management APIs section of the System Reference Guide for more information.
Page 62 of 200
GPIO_OVT pins are fully compliant with the I2C specification but the slew rate must be set
appropriately:
Slew rate "Slow" for Standard mode (100 kbps) and Fast mode (400 kbps)
Common GPIO pins are not completely compliant with the I2C specification. Refer to the
Device Datasheet for the details.
Slew rate settings are applied to all pins of the associated port.
Page 63 of 200
EZI2C APIs
Application Programming Interface (API) functions allow you to configure the component using
software. The following table lists and describes the interface to each function. The subsequent
section discusses each function in more detail.
By default, PSoC Creator assigns the instance name SCB_1 to the first instance of a
component in a given design. You can rename the instance to any unique value that follows the
syntactic rules for identifiers. The instance name becomes the prefix of every global function
name, variable, and constant symbol. For readability, the instance name used in the following
table is SCB.
Function
Description
SCB_Start()
SCB_Init()
SCB_Enable()
SCB_Stop()
SCB_Sleep()
SCB_Wakeup()
SCB_EzI2CInit()
SCB_EzI2CGetActivity()
SCB_EzI2CSetAddress1()
SCB_EzI2CGetAddress1()
Page 64 of 200
Function
Description
SCB_EzI2CSetBuffer1()
SCB_EzI2CSetReadBoundaryBuffer1()
Sets the read only boundary of the data buffer to be exposed by I2C
master by the primary address request.
SCB_EzI2CSetAddress2()
SCB_EzI2CGetAddress2()
SCB_EzI2CSetBuffer2()
SCB_EzI2CSetReadBoundaryBuffer2()
Sets the read boundary of the data buffer to be exposed by I2C master
by the secondary address request.
void SCB_Start(void)
Description:
Invokes SCB_Init() and SCB_Enable(). After this function call the component is enabled
and ready for operation. This is the preferred method to begin component operation.
When configuration is set to Unconfigured SCB, the component must first be initialized
to operate in one of the following configurations: I2C, SPI, UART or EZ I2C. Otherwise
this function does not enable component.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_Init(void)
Description:
Initializes the SCB component to operate in one of the selected configurations: I2C, SPI,
UART or EZ I2C.
When configuration set to Unconfigured SCB, this function does not do any
initialization. Use mode-specific initialization APIs instead: SCB_I2CInit, SCB_SpiInit,
SCB_UartInit or SCB_EzI2CInit.
Parameters:
None
Return Value:
None
Side Effects:
None
Page 65 of 200
void SCB_Enable(void)
Description:
Enables SCB component operation: activates the hardware and internal interrupt.
For I2C and EZ I2C modes the interrupt is internal and mandatory for operation. For SPI
and UART modes the interrupt can be configured as none, internal or external.
The SCB configuration should be not changed when the component is enabled. Any
configuration changes should be made after disabling the component.
When configuration is set to Unconfigured SCB, the component must first be initialized
to operate in one of the following configurations: I2C, SPI, UART or EZ I2C, Using the
mode-specific initialization API. Otherwise this function does not enable the component.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_Stop(void)
Description:
Disables the SCB component: disable the hardware and internal interrupt. It also
disables all TX interrupt sources so as not to cause an unexpected interrupt trigger
because after the component is enabled, the TX FIFO is empty.
Refer to the function SCB_Enable() for the interrupt configuration details.
This function disables the SCB component without checking to see if communication is
in progress. Before calling this function it may be necessary to check the status of
communication to make sure communication is complete. If this is not done then
communication could be stopped mid byte and corrupted data could result.
Parameters:
None
Return Value:
None
Side Effects:
None
Page 66 of 200
void SCB_Sleep(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_Wakeup(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
Calling the SCB_Wakeup() function without first calling the SCB_Sleep() function may
produce unexpected behavior.
Page 67 of 200
Parameters:
config: pointer to a structure that contains the list of fields. These fields match the
selections available in the customizer. Refer to the customizer for further description of the
settings.
Field
uint32 enableClockStretch
Description
0 disable
1 enable
When enabled the SCL is stretched as required for proper
operation.
uint32 enableMedianFilter
uint32 numberOfAddresses
uint32 primarySlaveAddr
uint32 secondarySlaveAddr
uint32 subAddrSize
Size of sub-address:
SCB_EZI2C_SUB_ADDR8_BITS
SCB_EZI2C_SUB_ADDR16_BITS
uint32 enableWake
0 disable
1 enable
When enabled the matching address generates a wakeup
request.
uint8 enableByteMode
Return Value:
None
Side Effects:
None
Page 68 of 200
uint32 SCB_EzI2CGetActivity(void)
Description:
Parameters:
None
Return Value:
Description
Read transfer complete. The transfer used the primary
slave address.
The error condition status bit must be checked to
ensure that read transfer was completed successfully.
SCB_EZI2C_STATUS_WRITE1
SCB_EZI2C_STATUS_READ2
SCB_EZI2C_STATUS_WRITE2
SCB_EZI2C_STATUS_BUSY
SCB_EZI2C_STATUS_ERR
Side Effects:
None
Page 69 of 200
Parameters:
Return Value:
None
Side Effects:
None
uint32 SCB_EzI2CGetAddress1(void)
Description:
Parameters:
None
Return Value:
Side Effects:
None
Sets up the data buffer to be exposed to the I2C master on a primary slave address
request.
Parameters:
Return Value:
None
Side Effects:
Calling this function in the middle of a transaction intended for the primary slave
address leads to unexpected behavior.
Page 70 of 200
Sets the read only boundary in the data buffer to be exposed to the I2C master on a
primary slave address request.
Parameters:
uint32 rwBoundary: number of data bytes starting from the beginning of the buffer with
read and write access. Data bytes located at offset rwBoundary or greater are read
only.
This value must be less than or equal to the buffer size.
Return Value:
None
Side Effects:
Calling this function in the middle of a transaction intended for the primary slave
address leads to unexpected behavior.
Parameters:
Return Value:
None
Side Effects:
None
uint32 SCB_EzI2CGetAddress2(void)
Description:
Parameters:
None
Return Value:
Side Effects:
None
Page 71 of 200
Sets up the data buffer to be exposed to the I2C master on a secondary slave address
request.
Parameters:
Return Value:
None
Side Effects:
Calling this function in the middle of a transaction intended for the secondary slave
address leads to unexpected behavior.
Sets the read only boundary in the data buffer to be exposed to the I2C master on a
secondary address request.
Parameters:
uint32 rwBoundary: number of data bytes starting from the beginning of the buffer with
read and write access. Data bytes located at offset rwBoundary or greater are read
only.
This value must be less than or equal to the buffer size.
Return Value:
None
Side Effects:
Calling this function in the middle of a transaction intended to the secondary slave
address leads to unexpected behavior.
Global Variables
Knowledge of these variables is not required for normal operations.
Variable
SCB_initVar
Description
SCB_initVar indicates whether the SCB component has been initialized. The variable is initialized
to 0 and set to 1 the first time SCB_Start() is called. This allows the component to restart without
reinitialization after the first call to the SCB_Start() routine.
If reinitialization of the component is required, then the SCB_Init() function can be called before
the SCB_Start() or SCB_Enable() function.
Page 72 of 200
Bootloader Support
The SCB component in EZ I2C mode cannot be used as a communication component for the
Bootloader.
Memory Interface
To an I2C master the interface looks very similar to a common I2C EEPROM. The EZ I2C buffer
can be configured as a variable, array, or structure but it is preferable to use an array. The buffer
acts as a shared memory interface between your program and an I 2C master through the I2C
bus. The component permits read and write I2C master access to the specified buffer memory
and prevents any access outside the buffer or write access into a read only region.
For example, the buffer for the primary slave address is configured using the code below. The
buffer elements from 4 to 9 are read only.
#define BUFFER_SIZE
#define BUFFER_RW_BOUNDARY
(0x0Au)
(0x04u)
uint8 ezi2cBuffer[BUFFER_SIZE];
SCB_EzI2CSetBuffer1(BUFFER_SIZE, BUFFER_RW_BOUNDARY, ezi2cBuffer);
Page 73 of 200
Access type
Exposed Buffer
ezi2cBuffer[9]
ezi2cBuffer[8]
Read Only
ezi2cBuffer[7]
0x0016
ezi2cBuffer[6]
ezi2cBuffer[5]
ezi2cBuffer[4]
ezi2cBuffer[3]
0x000D
Read/Write
ezi2cBuffer[2]
ezi2cBuffer[1]
ezi2cBuffer[0]
0x0000
To configure the whole buffer for read and write access, the buffer size and read/write boundary
need to use the same value. For example:
SCB_EzI2CSetBuffer1(BUFFER_SIZE, BUFFER_SIZE, ezi2cBuffer);
Handling endianness
The EZ I2C buffer can be set up as a variable. A variable with a size of more than one byte will
require knowledge of endianness (little-endian or big-endian). The endianness will determine the
byte order on the I2C bus. It is the I2C masters responsibility to handle byte ordering properly.
uint16 ezi2cBuffer = 0xAABB;
#define BUFFER_SIZE (2u)
SCB_EzI2CSetBuffer1(BUFFER_SIZE, BUFFER_SIZE, (uint8 *) &ezi2cBuffer);
All PSoC 4 devices are little-endian devices, so the master will read these two bytes in order as:
0xBB 0xAA.
Handling structures
The EZ I2C buffer can be set up as structure. The compiler lays out structures in memory and
may add extra bytes. This is called byte padding. The compiler will add these bytes to align the
fields of the structure to match the requirements of the Cortex-M0. This processor does not
support unaligned access to multi-byte fields. When using a structure, the application must take
Page 74 of 200
this alignment into account. If fields need to be packed, then a byte array should be used instead
of a structure.
(0x0Au)
(0u)
Page 75 of 200
LSB
BASE ADDRESS
LSB MSB
MSB
LSB
For write operations, a base address is always provided and is one or two bytes depending on
the configuration. This base address is retained and will be used for later read operations.
Following the base address is a sequence of bytes that are written into the buffer starting from
the base address location. The buffer index is incremented for each written byte, but this does
not affect the base address, which is retained. The length of a write operation is limited by the
maximum buffer read/write region size. The EZ I2C slave behaves differently on the I2C bus
when a master attempts to write outside the read/write region or past the end of the buffer
depending on the setting for Clock Stretching:
Enabled: the byte is NAKed by the slave and the master has to stop the current
transaction. The NAKed byte is discarded by the slave.
Disabled: all written bytes are ACKed by the slave, but these bytes are discarded.
Slave Address
Data[n+x]
Data[n+1]
Stop
ACK
ACK
ACK
ACK
Write
ACK
A A A A A A A R
B B B B B B B B
D D D D D D D D
D D D D D D D D
D D D D D D D D
A
A
A
A
A P
6 5 4 3 2 1 0 W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
Start
Data[n]
A read operation always starts from the base address set by the most recent write operation.
The buffer index is incremented for each read byte. Two sequential read operations start from
the same base address no matter how many bytes were read. The length of a read operation is
not limited by the maximum size of the data buffer. The EZ I2C slave returns 0xFF bytes if the
read operation passes the end of the buffer.
Page 76 of 200
Figure 8. I2C Master reads X bytes from the EZ I2C Slave buffer
Slave Address
Data[n+x]
Data[n+2]
Data[n+1]
Stop
NACK
ACK
ACK
ACK
Read
ACK
A A A A A A A R
D D D D D D D D
D D D D D D D D
D D D D D D D D
D D D D D D D D
A
A
A
A
A P
6 5 4 3 2 1 0 W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
Start
Data[n]
Typically, a read operation requires the base address to be updated before starting the read. In
this case, the write and read operations need to be combined together. The I 2C master may use
ReStart or Stop/Start conditions to combine the operations. The write operation only sets the
base address and the following read operation will start reading from the new base address. In
cases where the base address remains the same, there is no need for a write operation to be
performed.
Figure 9. I2C Master sets the base address and reads X bytes from the EZ I2C Slave buffer
Base
Address (n)
Slave Address
Stop
NACK
ACK
ACK
Read
ACK
ReStart
ACK
A A A A A A A R
B B B B B B B B
S A A A A A A A R
D D D D D D D D
D D D D D D D D
A
A
A
A
A P
6 5 4 3 2 1 0 W
7 6 5 4 3 2 1 0
r 6 5 4 3 2 1 0 W
7 6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
Write
Start
Data[n+x]
Data[n]
Slave Address
Detailed descriptions of the I2C bus and its implementation are available in the complete I2C
specification on the NXP website, and by referring to the device datasheet.
Data Coherency
Although a data buffer may include a data structure larger than a single byte, a Master read or
write operation consists of multiple single-byte operations. This can cause a data coherency
problem, because there is no mechanism to guarantee that a multi-byte read or write will be
synchronized on both sides of the interface (Master and Slave). For example, consider a buffer
that contains a single two-byte integer. While the master is reading the two-byte integer one byte
at a time, the slave may have updated the entire integer between the time the master read the
first byte of the integer (LSB) and was about to read the second byte (MSB). The data read by
the master may be invalid, since the LSB was read from the original data and the MSB was read
from the updated value.
You must provide a mechanism on the master, slave, or both that guarantees that updates from
the master or slave do not occur while the other side is reading or writing the data. The
SCB_EzI2CGetActivity() function can be used to develop an application-specific mechanism.
Note The buffer setup APIs are not interrupt protected and must be called when the component
is disabled or the slave is not busy.
Page 77 of 200
Clock Stretching
Clock stretching pauses a transaction by holding the SCL line low. The transaction cannot
continue until the SCL line is released allowing the signal to go high again. The support of clock
stretching is an optional feature of the I2C spec. For that reason, the EZ I2C slave provides an
option to enable or disable this feature.
Clock Stretching Enable
Enabling the clock stretching option makes is possible for the slave to insert a pause into the
transaction at the byte level. This allows for consistent EZ I2C slave operation for any slave
interrupt latency. The drawback is that the master has to support clock stretching as well.
Clock Stretching Disable
Disabling clock stretching configures the EZ I2C slave to operate with an optimized interrupt
service routine. This allows the EZ I2C slave to operate without clock stretching. Despite the
optimization, the slave interrupt still must be serviced fast enough. The maximum time that the
slave interrupt service can be delayed is defined as the maximum EZ I2C slave interrupt latency.
A design that does not satisfy the required maximum EZ I2C slave interrupt latency will cause
erroneous slave behavior. It is recommended to enable clock stretching if the design cannot
satisfy the required maximum EZ I2C slave interrupt latency. When selecting the clock stretching
disable option, refer also to the following:
Page 78 of 200
A A A A A A A
R A
6 5 4 3 2 1 0
EZI2C interrupt
request
CPU operation
Task
ISR
Task
tTX UPDATE
Master drives the bus
Slave drives the bus
EZI2C interrupt
hander
The time between starting the slave interrupt handler to the moment when the TX FIFO has been
updated with the first byte is referred as tTX UPDATE[5] [6] (Figure 10). The TX FIFO update consists
of clearing the TX FIFO and writing a byte from the slave buffer into the TX FIFO. The TX FIFO
update must be completed before the master starts reading the first data byte. Otherwise, a
number of issues can occur, including: reading old the TX FIFO content, clock stretching when
the TX FIFO is cleared [7], or reading a partial byte due to the TX FIFO clear in the middle of the
byte transfer.
The constraint applied to the TX FIFO update during the master read transaction causes the
maximum slave interrupt latency to be defined as maximum delay, which can be inserted from
the Start condition detection by the slave hardware, to the start of the execution of the slave
interrupt handler (Figure 11 on page 80).
This time depends on design settings such as CPU clock, compiler, optimization, etc.
This time does not include interrupt latency of the Cortext-M0 processor.
Page 79 of 200
Therefore, the maximum interrupt latency must be less than the master address byte transmit
time (tADDRESS) plus slave ACK bit transmit time (tACK). But taking to account TX FIFO update
constraint, the maximum interrupt latency must be less than:
tMAX LATENCY = (tADDRESS + tACK) tTX UPDATE = (8bits / fSCL + 1bit / fSCL)
tTX UPDATE = 9 / fSCL tTX UPDATE
For example I2C data rate of 100 kbps, the maximum interrupt latency must be less than:
tMAX LATENCY = 9 / fSCL tTX UPDATE = 90 uS tTX UPDATE
The number of CPU cycles to put the first byte into TX FIFO is calculated in the EZ I2C interrupt.
This number is equal to 71 cycles (mode Release, Compiler GCC, optimization Size). Taking into
account that the maximum interrupt latency of the Cortext-M0 processor is 16 cycles; the number
of cycles is increased to 87.
With the assumption that clock configuration of the design is internal IMO and HFCLK = SYSCLK
= 24 MHz, the tMAX LATENCY is calculated for the I2C data rate of 100 kbps. The accuracy of the
internal IMO is +/-2%; therefore, the number of CPU cycles is increased by 2% and equal to
~89 cycles. The tTX UPDATE = 89 / SYSCLK = 3.71uS. Referring to the above equation, the
maximum interrupt latency is equal to:
tMAX LATENCY = 9 / fSCL tTX UPDATE = 90 uS tTX UPDATE = 90 uS 3.71 uS = 86.29 uS
Figure 11. EZ I2C slave maximum interrupt latency
Start / ReStart
condition is detected
A A A A A A A
D D D D D D D
R A
6 5 4 3 2 1 0
7 6 5 4 3 2 1
tACK
tADDRESS
EZI2C interrupt
request
CPU operation
Task
tMAX LATENCY
ISR
Task
tTX UPDATE
EZI2C interrupt
hander
Design recommendations:
1. Use the highest possible SYSCLK frequency, as it runs the CPU to reduce execution time
of the EZ I2C slave interrupt.
Page 80 of 200
Page 81 of 200
Stop condition
is detected
Add byte
into TX FIFO
A A A A A A A
D D D D D D D D
A A A A A A A
D D D D D D D D
W A
A Sr
R A
A
6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
Case 1:
EZI2C interrupt
request
CPU operation
Task
ISR
Task
ISR
tTX UPDATE
ISR
Task
ISR
tTX UPDATE
ISR
Task
ISR
Task
Task
Task
Case 2:
EZI2C interrupt
request
CPU operation
Task
ISR
Task
ISR
tTX UPDATE
ISR
Task
ISR
tTX UPDATE
Task
tRX DELAY
Sr
SDA
SCL
tLOW
Page 82 of 200
Start/ReStart
condition is detected
A A A A A A A
D D D D D D D D
R A
A
6 5 4 3 2 1 0
7 6 5 4 3 2 1 0
EZI2C interrupt
request
CPU operation
Task
ISR
Task
ISR
ISR
Task
Task
CPU operation
Task
ISR
Task
tTX UPDATE
2
Address match
status
1
1
Page 83 of 200
Primary address = 0x24 and secondary address = 0x34, only one bit differs. Only the two
addresses are treated as matching by the hardware.
Primary address = 0x24 and secondary address = 0x30, two bits differ. Four addresses
are treated as matching by the hardware: 0x24, 0x34, 0x20 and 0x30. Firmware is
required to ACK only the primary and secondary addresses 0x24 and 0x30 and NAK all
others 0x20 and 0x34.
Page 84 of 200
{
/* Slave is not busy: enter Deep Sleep */
SCB_Sleep();
/* Configure the slave to be wakeup source */
CySysPmDeepSleep();
/* Exit critical section to continue slave operation */
CyExitCriticalSection(intState);
SCB_Wakeup();
/* Configure the slave to active mode operation */
}
else
{
/* Slave is busy. Do not enter Deep Sleep.
*/
/* Exit critical section to continue slave operation */
CyExitCriticalSection(intState);
}
For devices other than PSoC 4100 /PSoC 4200, the component clock must be disabled before
calling SCB_Sleep(), and then enabled after calling SCB_Wakeup(); otherwise, the SCL will lock
up after wakeup from Deep Sleep. Disabling and re-enabling the component clock is managed
by the SCB_Sleep() and SCB_Wakeup() APIs when the Clock from terminal option is disabled.
Otherwise, when the Clock from terminal option is enabled, the code provided above requires
modification to enable and disable the clock source connected to the SCB component. Review
the following modified code and highlighted in blue (ScbClock the instance name of clock
component connected to the SCB):
if (0u == status)
{
/* Slave is not busy: enter to Deep Sleep */
SCB_Sleep();
/* Configure the slave to be wakeup source */
ScbClock_Stop(); /* Disable the SCB clock */
CySysPmDeepSleep();
/* Exit critical section to continue slave operation */
CyExitCriticalSection(intState);
ScbClock _Start(); /* Enable SCB clock */
}
Figure 14. Master transfer wakes up device on slave address match (Clock stretching
enable)
SCB_Sleep()
call
Transfer to other slave
Or bus IDLE
Address
match
S
Address
R/W
SCB_Wakeup()
call
Clock streching
Data
Active
Deep Sleep
Mode transition
Active
Page 85 of 200
Note The values for the primary and secondary addresses affect the range of matched
addresses. The preferable choice for the secondary address is when it differs from the primary
only by one bit. If it differs by more than one bit, then some transactions that are not intended for
this device will still wake the device from deep sleep. The address is going to be NAKed in this
case.
Clock stretching disable: the slave NAKs the matched address and any subsequent
transactions until the device wakes up.
Before entering Deep Sleep, the ongoing transaction intended for the slave must be completed.
The waiting loop is implemented inside the SCB_Sleep() function. This function is blocking and
waits until the slave is free to configure it to be a wakeup source. For proper SCB_Sleep()
function operation the slave busy status has to be managed properly by the EZI2C slave(refer to
the Slave busy management section for more information). After reconfiguration, the sampling of
the address match event is started and the device has time to enter Deep Sleep mode. To
operate correctly in active mode, the slave configuration must be restored back by
SCB_Wakeup(). The agreement between slave and master must be concluded so as not to
access the slave after wakeup until SCB_Wakeup() is executed. The following code is
suggested:
SCB_Sleep(); /* Wait for the slave to be free and configures it to be wakeup
source */
CySysPmDeepSleep();
SCB_Wakeup(); /* Configure the slave to active mode operation */
Note The interrupts are required for the slave operations and global interrupts must be enabled
before calling SCB_Sleep().
Figure 15. Master transfer wakes up device on slave address match (Clock stretching
disable)
SCB_Sleep()
call
Transfer to other slave
Or bus IDLE
Active
Page 86 of 200
Address
match
S
Address
Deep Sleep
R\W
SCB_Wakeup()
call
Bus IDLE
Mode transition
Address
R\W
Data
Active
SPI
This component provides an industry-standard, 4-wire SPI interface. Three different SPI
protocols or modes are supported:
In addition to the standard 8-bit word length, the component supports a configurable 4 to 16-bit
data width for communicating at nonstandard SPI data widths.
Input/Output Connections
This section describes the various input and output connections for the SCB component. An
asterisk (*) in the list of terminals indicates that the terminal may be hidden on the symbol under
the conditions listed in the description of that terminal.
clock Input*
Clock that operates this block. The presence of this terminal varies depending on the Clock
from terminal parameter.
interrupt Output*
This signal can only be connected to an interrupt component or left unconnected. The presence
of this terminal varies depending on the Interrupt parameter.
rx_tr_out Output*
This signal can only be connected to a DMA channel trigger input. This signal is used to trigger a
DMA transaction. The output of this terminal is controlled by the RX FIFO level. The presence of
this terminal varies depending RX Output parameter.
Page 87 of 200
tx_tr_out Output*
This signal can only be connected to a DMA channel trigger input. This signal is used to trigger a
DMA transaction. The output of this terminal is controlled by the TX FIFO level. The presence of
this terminal varies depending TX Output parameter.
The interface-specific pins are buried inside component because these pins use dedicated
connections and are not routable as general purpose signals. See the I/O System section in the
device Technical Reference Manual (TRM) for more information.
Note The input buffer of buried output pins is disabled so as not to cause current linkage in low
power mode. Reading the status of these pins always returns zero. To get the current status, the
input buffer must be enabled before status read.
Page 88 of 200
Page 89 of 200
Sub mode
This option determines what SPI sub-modes are supported:
SCLK mode
This parameter defines the serial clock phase and clock polarity mode for communication.
Refer to the section Motorola sub mode operation in the SPI chapter of this document for more
information.
Data rate
This parameter is used to set the SPI data rate value up to 8000 kbps; the actual rate may differ
based on available clock frequency and component settings. The standard data rates are 500,
1000 (default), 2000, 4000 to 8000 in multiples of 2000 kbps. This parameter has no effect if the
Clock from terminal parameter is enabled.
Actual data rate
The actual data rate displays the data rate at which the component will operate with current
settings. The factors that affect the actual data rate calculation are: the accuracy of the
component clock (internal or external) and oversampling factor (only for the Master mode). When
a change is made to any of the component parameters that affect actual data rate, it becomes
unknown. To calculate the new actual data rate press the Apply button.
Page 90 of 200
Note For Slave mode the actual data rate always provides maximum value for the selected clock
frequency. As external Master parameters are unknown, the assumption was made that MISO is
sampled in the leading edge of SCLK.
Refer to the Slave data rate section for actual data rate calculation which takes to account
external environment timing conditions.
Oversampling
This parameter defines the oversampling factor of the SPI clock; the number of component
clocks within one SPI clock period. Oversampling factor is used to calculate the internal
component clock frequency required to achieve this amount of oversampling as follows:
SCBCLK = Data rate * Oversampling factor.
For Slave mode, only the component clock source frequency is important. The
oversampling value is used to create a clock fast enough to operate at the selected data
rate. Refer to the Maximum data rate calculation section for more information. The
created clock is equal to the (data rate * Oversampling).
For Master mode, the oversampling value is used for serial clock signal (SCLK)
generation. The oversampling is equal to number of component clocks within one SPI
clock period. When the oversampling is even the first and second phase of the clock
period are the same. Otherwise the first phase of the clock signal period is one
component clock cycle longer than the second phase. The level of the first phase of the
clock period depends on CPOL settings: 0 low level and 1 high level.
An oversampling factor maximum value is 16 and minimum depends on component settings. For
Master the minimum oversampling factor value is 6. For Slave the minimum oversampling value
6 (Median filter is disabled) or 8 (Median filter is enabled).
Clock from terminal
This parameter allows choosing between an internally configured clock (by the component) or an
externally configured clock (by the user) for the component operation. Refer to the
Oversampling section to understand relationship between component clock frequency and the
component parameters.
When this option is enabled, the component does not control the data rate, but displays the
actual data rate based on the user-connected clock source frequency and the component
oversampling factor (only for the Master mode). When this option is not enabled, the clock
configuration and Oversampling factor (only for the Master mode) is provided by the component.
The clock source frequency is calculated by the component based on the Data rate parameter.
Note PSoC Creator is responsible for providing requested clock frequency (internal or external
clock) based on current design clock configuration. When the requested clock frequency with
requested tolerance cannot be created, a warning about the clock accuracy range is generated
while building the project. This warning contains the actual clock frequency value created by
Page 91 of 200
PSoC Creator. To remove this warning you must either change the system clock, component
settings or external clock to fit the clocking system requirements.
Median filter
This parameter applies 3 taps digital median filter on the input line. The master has one input
line: MISO, and the slave has three input lines: SCLK, MOSI, and SS. This filter reduces the
susceptibility to errors. However, minimum oversampling factor value is increased. The default
value is a Disabled.
SCLK free running
This option is only applicable for PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/
PSoC 4200L devices in Master mode. It allows master to generate SCLK continually. It is useful
when master SCLK is connected to the slave device which uses it for functional operation rather
than just SPI functionality.
The default value is a Disabled.
Enable late MISO sample
This option allows the master to sample the MISO signal by half of SCLK period later (on the
alternate serial clock edge). Late sampling addresses the round-trip delay associated with
transmitting SCLK from the master to the slave and transmitting MISO from the slave to the
master. The default value is a Disabled.
Enable wakeup from Deep Sleep Mode
Use this option to enable the component to wake the system from Deep Sleep when slave select
occurs.
To enable this option all of the following restrictions must be met:
Refer to the Low power modes section under the SPI chapter in this document and Power
Management APIs section of the System Reference Guide for more information.
TX data bits
This option defines the bit width in a transmitted data frame. The default number of bits is a
single byte (8 bits). Any integer from 4 to 16 is a valid setting.
Page 92 of 200
RX data bits
This option defines the bit width in a received data frame. The default number of bits is a single
byte (8 bits). Any integer from 4 to 16 is a valid setting.
Note The number of TX data bits and RX data bits should be set the same for Motorola and
Texas Instruments sub-modes; they can be set different for National Semiconductor submode.
Bit order
The Bits order parameter defines the direction in which the serial data is transmitted. When set
to MSB first, the most-significant bit is transmitted first. When set to LSB first, the leastsignificant bit is transmitted first.
Remove SCLK
This option allows removal of the SCLK pin from the SPI interface. If selected, this pin is no
longer available in the Design-Wide Resources System Editor (in the <project>.cydwr file) on the
Pins Tab. The SCLK pin cannot be removed in Slave mode.
Remove MOSI
This option allows removal of the MOSI pin from the SPI interface. If selected, this pin is no
longer available in the Design-Wide Resources System Editor (in the <project>.cydwr file) on the
Pins Tab.
Remove MISO
This option allows removal of the MISO pin from the SPI interface. If selected, this pin is no
longer available in the Design-Wide Resources System Editor (in the <project>.cydwr file) on the
Pins Tab.
Number of SS
This parameter determines the number of SPI slave select lines. Only one slave select line is
available in Slave mode and it is not optional. The values between 0 and 4 are valid choices in
Master mode. The default number of lines is 1.
Transfer separation
This parameter determines if individual data transfers are separated by slave select de-selection
(only applicable for Master mode):
Continuous The slave select line is held in active state until the end of transfer
(default).
The master assigns the slave select output after data has been written into the TX FIFO
and keeps it active as long as there are data elements to transmit. The slave select output
Page 93 of 200
becomes inactive when all data elements have been transmitted from the TX FIFO and
shifter register.
Note This can happen even in the middle of the transfer if the TX FIFO is not loaded fast
enough by the CPU or DMA. To overcome this behavior, the slave select can be
controlled by firmware. For more information about slave select control, refer to the Slave
select lines section.
Separated Every data frame 4-16 bits is separated by slave select line de-selection by
one SCLK period.
SS0-SS3 polarity
This option is only applicable for PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/
PSoC 4200L devices. It determines the active polarity of the slave select signal as Active Low
(default) or Active High. For other devices, only Active Low is available.
Each slave select line active polarity can be configured independently.
For Texas Instruments precede/coincide sub-modes the active polarity logic is inverted:
Active Low Slave select line is inactive low and generated pulse is active high.
Active High Slave select line is inactive high and generated pulse is active low.
Page 94 of 200
For 4100/PSoC 4200 devices, the RX and TX FIFO depth is equal to 8 bytes/words.
For PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/PSoC 4200L devices,
the RX and TX FIFO depth is equal to 8 bytes/words or 16 bytes; refer to Byte mode for
more information.
TX buffer size
The TX buffer size parameter defines the size (in bytes/words) of memory allocated for a
circular transmit data buffer. The TX buffer size minimum value is equal to the TX FIFO depth.
The TX FIFO is implemented in hardware. Values greater than the TX FIFO depth up to (232 1)
imply using the TX FIFO, circular software buffer controlled by the supplied APIs, and the
internal interrupt handler. The software buffer size is limited only by the available memory. The
interrupt mode is automatically set to the internal and the TX FIFO not full interrupt source is
reserved if a software buffer is used.
For 4100/PSoC 4200 devices, the RX and TX FIFO depth is equal to 8 bytes/words.
For PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/PSoC 4200L devices,
the RX and TX FIFO depth is equal to 8 bytes/words or 16 bytes; refer to Byte mode for
more information.
Byte mode
This option is only applicable to PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/
PSoC 4200L devices. It allows doubling the TX and RX FIFO depth from 8 to 16 bytes, by
reducing the FIFO width from 16bits to 8 bits. This implies that the number of TX and RX data
bits must be less than or equal to 8 bits. Increasing FIFO depth improves performance of SPI
operation as more bytes can be transmitted or received without software interaction.
Interrupt
This option determines what interrupt modes are supported None, Internal or External.
Page 95 of 200
Internal This option leaves the interrupt component inside the SCB component. The
predefined internal interrupt handler is hooked up to the interrupt. The Interrupt sources
option sets one or more interrupt sources, which trigger the interrupt. To add your own
code to the interrupt service routine you need to register a function using the
SCB_SetCustomInterruptHandler() function.
External This option removes the internal interrupt and provides an output terminal.
Only an interrupt component can be connected to this terminal if an interrupt handler is
desired. The Interrupt sources option sets one or more interrupt sources, which trigger
the interrupt output.
Note For buffer sizes greater than the hardware FIFO depth, the component automatically
enables the internal interrupt sources required for proper internal software buffer operations. In
addition, the global interrupt enable must be explicitly enabled for proper buffer handling.
DMA
DMA is only available in PSoC 4100M/PSoC 4200M/PSoC 4200L devices. The RX Output and
TX Output options determine if DMA output trigger terminals are available on the component
symbol.
RX Output
This option determines if the rx_tr_out terminal is available on the component symbol. This
signal can only be connected to a DMA channel trigger input. The output of this terminal is
controlled by the RX FIFO level. This option is active only when RX buffer size equal to FIFO
depth.
TX Output
This option determines if the tx_tr_out terminal is available on the component symbol. This signal
can only be connected to a DMA channel trigger input. The output of this terminal is controlled by
the TX FIFO level. This option is active only when TX buffer size equal to FIFO depth.
Interrupt sources
The interrupt sources are either level or pulse. Level interrupt sources in the following list are
indicated with an asterisk (*). Refer to sections TX FIFO interrupt sources and RX FIFO interrupt
sources for more information about level interrupt sources operation. The SPI supports interrupts
on the following events:
SPI done Master transfer done event: all data elements from the TX FIFO are sent. This
interrupt source triggers later than TX FIFO empty by the amount of time it takes to
transmit a single data element. The TX FIFO empty triggers when the last data element
from the TX FIFO goes to the shifter register. However, SPI done triggers after this data
element has been transmitted. This means SPI done will be asserted one SCLK clock
cycle earlier than the reception of the data element has been completed. It is
Page 96 of 200
TX FIFO not full * TX FIFO is not full. At least one data element can be written into the
TX FIFO.
SPI bus error SPI slave deselected at an unexpected time during the SPI transfer.
RX FIFO not empty * RX FIFO is not empty. At least one data element is available in
the RX FIFO to be read.
Notes
When RX buffer size is greater than the RX FIFO depth, the RX FIFO not empty interrupt
source is reserved by the component and used for the internal interrupt.
When TX buffer size is greater than the TX FIFO depth, the TX FIFO not full interrupt source is
reserved by the component and used for the internal interrupt.
FIFO level
The RX and TX FIFO level settings control behavior of the appropriate level interrupt sources as
well as RX and TX DMA triggers outputs.
RX FIFO
The interrupt or DMA trigger output signal remains active until the number of data elements in
the RX FIFO is greater than the value of RX FIFO level.
Page 97 of 200
TX FIFO
The interrupt or DMA trigger output signal remains active until the number of data elements in
the TX FIFO is less than the value of TX FIFO level.
SPI APIs
APIs allow you to configure the component using software. The following table lists and
describes the interface to each function. The subsequent sections discuss each function in more
detail.
By default, PSoC Creator assigns the instance name SCB_1 to the first instance of a
component in a given design. You can rename the instance to any unique value that follows the
syntactic rules for identifiers. The instance name becomes the prefix of every global function
name, variable, and constant symbol. For readability, the instance name used in the following
table is SCB.
Function
Description
SCB_Start()
SCB_Init()
SCB_Enable()
SCB_Stop()
SCB_Sleep()
SCB_Wakeup()
SCB_SpiInit()
SCB_SpiIsBusBusy()
SCB_SpiSetActiveSlaveSelect()
Selects the active slave select line. Only applicable in Master mode.
Places a data entry into the transmit buffer to be sent at the next available bus
time.
SCB_SpiUartPutArray()
SCB_SpiUartGetTxBufferSize()
SCB_SpiUartClearTxBuffer()
SCB_SpiUartReadRxData()
SCB_SpiUartGetRxBufferSize()
SCB_SpiUartClearRxBuffer()
Page 98 of 200
void SCB_Start(void)
Description:
Invokes SCB_Init() and SCB_Enable(). After this function call the component is enabled
and ready for operation. This is the preferred method to begin component operation.
When configuration is set to Unconfigured SCB, the component must first be initialized to
operate in one of the following configurations: I2C, SPI, UART or EZ I2C. Otherwise this
function does not enable component.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_Init(void)
Description:
Initializes the SCB component to operate in one of the selected configurations: I2C, SPI,
UART or EZ I2C.
When configuration is set to Unconfigured SCB, this function does not do any initialization.
Use mode-specific initialization APIs instead: SCB_I2CInit, SCB_SpiInit, SCB_UartInit or
SCB_EzI2CInit.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_Enable(void)
Description:
Enables SCB component operation: activates the hardware and internal interrupt.
For I2C and EZ I2C modes the interrupt is internal and mandatory for operation. For SPI and
UART modes the interrupt can be configured as none, internal or external.
The SCB configuration should be not changed when the component is enabled. Any
configuration changes should be made after disabling the component.
When configuration is set to Unconfigured SCB, the component must first be initialized to
operate in one of the following configurations: I2C, SPI, UART or EZ I2C. Otherwise this
function does not enable component.
Parameters:
None
Return Value:
None
Side Effects:
None
Page 99 of 200
void SCB_Stop(void)
Description:
Disables the SCB component: disable the hardware and internal interrupt. It also disables
all TX interrupt sources so as not to cause an unexpected interrupt trigger because after the
component is enabled, the TX FIFO is empty.
Refer to the function SCB_Enable() for the interrupt configuration details.
This function disables the SCB component without checking to see if communication is in
progress. Before calling this function it may be necessary to check the status of
communication to make sure communication is complete. If this is not done then
communication could be stopped mid byte and corrupted data could result.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_Sleep(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_Wakeup(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
Calling the SCB_Wakeup() function without first calling the SCB_Sleep() function may
produce unexpected behavior.
Parameters:
config: pointer to a structure that contains the following list of fields. These fields match
the selections available in the customizer. Refer to the customizer for further description
of the settings.
Field
Description
uint32 mode
uint32 submode
uint32 sclkMode
uint32 oversample
Oversampling factor for the SPI clock. Ignored for Slave mode
operation.
uint32 enableMedianFilter
0 disable
1 enable
uint32 enableLateSampling
0 disable
1 enable
Ignored for slave mode.
uint32 enableWake
0 disable
1 enable
Ignored for master mode.
uint32 rxDataBits
uint32 txDataBits
uint32 bitOrder
uint32 transferSeperation
uint32 rxBufferSize
uint8* rxBuffer
uint32 txBufferSize
uint8* txBuffer
uint32 enableInterrupt
0 disable
1 enable
The interrupt has to be enabled if software buffer is used.
uint32 rxInterruptMask
uint32 rxTriggerLevel
uint32 txInterruptMask
uint32 txTriggerLevel
uint8 enableByteMode
Ignored for all devices other than For PSoC 4100 BLE/
PSoC 4200 BLE/ PSoC 4100M/PSoC 4200M/PSoC 4200L.
0 disable
1 enable
When enabled the TX and RX FIFO depth is 16 bytes. This implies
that number of TX and RX data bits must be less than or equal to 8.
uint8 enableFreeRunSclk
Ignored for all devices other than For PSoC 4100 BLE/
PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/PSoC 4200L.
Enables continuous SCLK generation by the SPI master.
0 disable
1 enable
uint8 polaritySs
Ignored for all devices other than For PSoC 4100 BLE/
PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/PSoC 4200L.
Active polarity of slave select lines 0-3. This is bitmask where bit
SCB_SPI_SLAVE_SELECT0 corresponds to slave select 0 polarity,
bit SCB_SPI_SLAVE_SELECT1 slave select 1 polarity and so on.
Polarity constants are:
SCB_SPI_SS_ACTIVE_LOW
SCB_SPI_SS_ACTIVE_HIGH
Return Value:
None
Side Effects:
None
uint32 SCB_SpiIsBusBusy(void)
Description:
Returns the current status on the bus. The bus status is determined using the slave
select signal.
Motorola and National Semiconductor sub-modes: The bus is busy after the slave
select line is activated and lasts until the slave select line is deactivated.
Texas Instrument sub-modes: The bus is busy at the moment of the initial pulse on
the slave select line and lasts until the transfer is complete.
If SPI Master is configured to use "separated transfers" (see Continuous versus
Separated Transfer Separation), the bus is busy during each element transfer and is
free between each element transfer. The Master does not activate SS line immediately
after data has been written into the TX FIFO.
Parameters:
None
Return Value:
uint32: Current status on the bus. If the returned value is nonzero, the bus is busy. If
zero is returned, the bus is free. The bus status is determined using the slave select
signal.
Side Effects:
None
Selects one of the four slave select lines to be active during the transfer. After
initialization the active slave select line is 0.
The component should be in one of the following states to change the active slave select
signal source correctly:
The component is disabled
The component has completed transfer
This function does not check that these conditions are met.
This function is only applicable to SPI Master mode of operation.
Parameters:
uint32 slaveSelect: slave select line that will be active after the transfer.
Active Slave Select constants
Description
SCB_SPI_SLAVE_SELECT0
Slave select 0
SCB_SPI_SLAVE_SELECT1
Slave select 1
SCB_SPI_SLAVE_SELECT2
Slave select 2
SCB_SPI_SLAVE_SELECT3
Slave select 3
Return Value:
None
Side Effects:
None
Parameters:
Description
Slave select 0.
For SPI slave mode the slave select 0 is only
valid argument due to slave select placement
constraint.
SCB_SPI_SLAVE_SELECT1
Slave select 1
SCB_SPI_SLAVE_SELECT2
Slave select 2
SCB_SPI_SLAVE_SELECT3
Slave select 3
Description
SCB_SPI_SS_ACTIVE_LOW
SCB_SPI_SS_ACTIVE_HIGH
Return Value:
None
Side Effects:
None
Places a data entry into the transmit buffer to be sent at the next available bus time.
This function is blocking and waits until there is space available to put the requested
data in the transmit buffer.
Parameters:
Return Value:
None
Side Effects:
None
Parameters:
Return Value:
None
Side Effects:
None
uint32 SCB_SpiUartGetTxBufferSize(void)
Description:
Parameters:
None
Return Value:
Side Effects:
None
void SCB_SpiUartClearTxBuffer(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
uint32 SCB_SpiUartReadRxData(void)
Description:
Parameters:
None
Return Value:
uint32: Next data element from the receive buffer. The amount of data bits to be
received depends on RX data bits selection (the data bit counting starts from LSB of
return value).
Side Effects:
None
uint32 SCB_SpiUartGetRxBufferSize(void)
Description:
Parameters:
None
Return Value:
Side Effects:
None
void SCB_SpiUartClearRxBuffer(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
Global Variables
Knowledge of these variables is not required for normal operations.
Variable
SCB_initVar
Description
SCB_initVar indicates whether the SCB component has been initialized. The variable is
initialized to 0 and set to 1 the first time SCB_Start() is called. This allows the
component to restart without reinitialization after the first call to the SCB_Start() routine.
If reinitialization of the component is required, then the SCB_Init() function can be called
before the SCB_Start() or SCB_Enable() function.
Variable
SCB_rxBufferOverflow
Description
SCB_rxBufferOverflow sets when internal software receive buffer overflow was
occurred.
Bootloader Support
The SCB component in SPI mode can be used as a communication component for the
Bootloader. You should use the following configuration to support the SPI communication
protocol from an external system to the Bootloader:
For more information about the Bootloader, refer to the Bootloader component datasheet.
Description
SCB_CyBtldrCommStart()
SCB_CyBtldrCommStop()
SCB_CyBtldrCommReset()
SCB_CyBtldrCommRead()
Allows the caller to read data from the bootloader host (the host writes the data).
SCB_CyBtldrCommWrite()
Allows the caller to write data to the bootloader host (the host reads the data).
void SCB_CyBtldrCommStart(void)
Description:
Starts the SPI component and enables its interrupt (if TX or RX buffer size is greater
than FIFO depth).
Every incoming SPI transfer is treated as a command for the bootloader.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_CyBtldrCommStop(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_CyBtldrCommReset(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
Allows the caller to read data from the bootloader host (the host writes the data). The
function handles polling to allow a block of data to be completely received from the host
device.
Parameters:
uint8 pData[]: Pointer to the block of data to be read from bootloader host.
uint16 size: Number of bytes to be read from bootloader host.
uint16 *count: Pointer to variable to write the number of bytes actually read by
bootloader host.
uint8 timeOut: Number of units in 10 ms to wait before returning because of a timeout.
Return Value:
Side Effects:
None
Allows the caller to write data to the bootloader host (the host reads the data). The
function handles polling to allow a block of data to be completely sent to the host
device.
Parameters:
const uint8 pData[]: Pointer to the block of data to send to the bootloader host.
uint16 size: Number of bytes to send to bootloader host.
uint16 *count: Pointer to variable to write the number of bytes actually written to
bootloader host.
uint8 timeOut: Number of units in 10 ms to wait before returning because of a timeout.
Return Value:
Side Effects:
None
SCB_CyBtldrCommRead details
The SPI interface does not provide start and stop conditions to define the start and end of a
transfer like I2C. Therefore, the following approach is used to define when command packet from
the host is received:
1) To determine when the start of a packet has occurred, the RX buffer is checked at a one
millisecond interval until the buffer size is non-zero or timeout is expired. As soon as at
least one data element has been received the communication component knows a packet
transfer has started and immediately begins looking for the end of the packet.
2) The transfer is completed if no new data elements are received within the byte-to-byte
timeout interval. This time interval is defined as the time consumed to transfer two data
elements with selected data rate. It is calculated by the component based on current data
rate selection. If needed, the byte-to-byte interval can be changed by using global defines.
Open project Build Settings -> Compiler -> Command line and provide global define of the
interval in microseconds. For example, to change the interval to 40 microseconds:
-D DUT_UART_BYTE_TO_BYTE=40
Figure 17 illustrates driving and capturing of MOSI/MISO data as a function of CPOL and CPHA.
Figure 17. SPI Motorola frame format
CPOL = 0
CPHA = 0
SCLK
MISO /
MOSI
MSB
LSB
CPOL = 0
CPHA = 1
SCLK
MISO /
MOSI
MSB
LSB
CPOL = 1
CPHA = 0
SCLK
MISO /
MOSI
MSB
LSB
CPOL = 1
CPHA = 1
SCLK
MISO /
MOSI
MSB
LSB
Figure 18 illustrates a single 8-bit data transfer and two successive 8-bit data transfers in mode 0
(CPOL is '0', CPHA is '0').
Figure 18. SPI Motorola Data Transfer Example
CPOL = 0, CPHA = 0 single data transfer
SCLK
SELECT
MOSI
MISO
MSB
LSB
MSB
LSB
SCLK
SELECT
MOSI
MISO
MSB
MSB
LSB MSB
LSB
LSB MSB
LSB
Figure 19 illustrates a single 8-bit data transfer and two successive 8-bit data transfers. The SS
pulse precedes the first data bit.
Note The SELECT pulse of the second data transfer coincides with the last data bit of the first
data transfer.
Figure 19. TI (Precede) Data Transfer Example
CPOL=0, CPHA=1 single data transfer
SCLK
SELECT
MOSI
MSB
LSB
MISO
MSB
LSB
SCLK
SELECT
MOSI
MSB
LSB MSB
LSB
MISO
MSB
LSB MSB
LSB
Figure 20 illustrates a single 8-bit data transfer and two successive 8-bit data transfers. The SS
pulse coincides with the first data bit.
Figure 20. TI (Coincide) Data Transfer Example
CPOL=0, CPHA=1 single data transfer
SCLK
SELECT
MOSI
MSB
LSB
MISO
MSB
LSB
SCLK
SELECT
MOSI
MSB
LSB MSB
LSB
MISO
MSB
LSB MSB
LSB
Figure 21 illustrates a single data transfer and two successive data transfers. In both cases the
transmission data transfer size is 8 bits and the reception transfer size is 4 bits.
Figure 21. National Semiconductor's Microwire Data Transfer Example
CPOL=0, CPHA=0 single data transfer
SCLK
SELECT
MOSI
MSB
LSB
MSB
MISO
LSB
idle 0 cycle
CPOL=0, CPHA=0 two successive data transfers
SCLK
SELECT
MOSI
MISO
MSB
MSB
LSB
MSB
idle 0 cycle
LSB
No idle cycle
SCLK
MISO
Normal sample
MSB
MISO
Late sample
LSB
MSB
LSB
Set the active slave select line to one that is not routed out to the pin. This option is
recommended when less than four slave select lines are used by the master. Example:
SPI master consumes 3 slave select lines SS0, SS1 and SS2. Call
SCB_SpiSetActiveSlaveSelect(SCB_SPIM_ACTIVE_SS3) to deactivate hardware
controlled slave select lines SS0-SS2.
Change the source of the control of the active slave select line in HSIOM (High Speed I/O
Matrix) from the SCB SPI interface to GPIO (CPU firmware control). Refer to the HighSpeed I/O Matrix description in the Technical Reference Manual (TRM) for more
information. This option is recommended when the master uses four slave select lines or
when multiplexing between hardware controlled and firmware controlled slave select lines
is required.
CPHA = 0
SCLK
SELECT
1 SCLK period
SCLK period
CPHA = 1
SCLK
SELECT
SCLK period
1 SCLK period
Note PSoC 4100/PSoC 4200 devices support only SCLK gated and active low SELECT polarity.
Figure 24. SELECT and SCLK Timing Correlation (PSoC 4100 BLE/PSoC 4200 BLE/
PSoC 4100M/PSoC 4200M/PSoC 4200L)
CPHA = 0
SCLK
SELECT
SCLK period
SCLK period
CPHA = 1
SCLK
SELECT
SCLK period
SCLK period
Note PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/PSoC 4200L devices
support SCLK gated and free running, as well as active low and high SELECT polarity. For all
configurations, the same correlation is preserved.
SELECT polarity
The SELECT line polarity for PSoC 4100/PSoC 4200 devices is active low. PSoC 4100
BLE/PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/PSoC 4200L devices provide the capability to
select the active polarity of the line as active low or active high.
Active Low
SELECT
Active High
Active Low
SELECT
Active High
extra element that remains empty while in operation. Keeping this element empty simplifies
circular buffer operation. The interrupt option is automatically set to Internal, and the RX or TX
interrupt source is reserved to provide software buffer operation.
The internal interrupt is connected to the interrupt output. This interrupt runs a predefined
interrupt service routine. Its main purpose is to provide interaction between software buffers and
hardware RX or TX FIFO. The software buffer overflow can happen only for the RX direction.
The data elements read from the RX FIFO that do not fit into the software buffer are discarded.
This event is reported via global variable SCB_rxBufferOverflow. For the TX direction, the
provided APIs do not allow the software buffer overflow.
Interrupts
When RX buffer size or TX buffer size is greater than the FIFO depth, the RX FIFO not empty
or TX FIFO not full interrupt sources are reserved by the component for the internal software
buffers operations. Do not clear or disable them because it causes incorrect software buffer
operation. However, it is the users responsibility to clear interrupt events from other enabled
interrupt sources because they are not cleared automatically. Create a custom function that
clears these interrupt sources and register it using SCB_SetCustomInterruptHandler(). Each time
an internal interrupt handler executes, the custom function is called before handling software
buffer operation.
In case RX buffer size or TX buffer size is equal to the FIFO depth instead of software buffer
only the hardware TX or RX FIFO is used. In the Internal interrupt mode the interrupts are not
cleared automatically. It is user responsibility to do this. The External or None interrupt selection
is preferred in this case.
Low power modes
The component in SPI mode is able to be a wakeup source from Sleep and Deep Sleep low
power modes.
Sleep mode is identical to Active from a peripheral point of view. No configuration changes are
required in the component or code before entering/exiting this mode. Any communication
intended for the slave causes an interrupt to occur and leads to wakeup. Any master activity that
causes an interrupt to occur leads to wakeup.
The master mode is not able to be a wakeup source from Deep Sleep. This capability is only
available in slave mode. Deep Sleep mode requires that the slave be properly configured to be a
wakeup source. The Enable wakeup from Deep Sleep Mode option must be checked in the SPI
configuration dialog. The SCB_Sleep() and SCB_Wakeup() functions must be called before/after
entering/exiting Deep Sleep.
The content of TX and RX FIFOs is cleared when device enters the Deep Sleep mode.
Therefore received data should be stored in the SRAM buffer and transmit data should be
transferred before enter Deep Sleep mode to avoid data lost. This is applies for Master and
Slave modes.
In Master mode, the ongoing transfer is stopped asynchronously when the SCB_Sleep() API is
called because this function disables the component. The following code sample is suggested to
ensure that transfer is completed before entering Deep Sleep mode. It occurs when all data
elements have been transferred from the software buffer (if utilized), TX FIFO, and shifter
register. Also, the slave select line must be deactivated. This method works reliably for any
choice of slave select Transfer separation configuration.
/* Wait until SPI Master completes transfer data */
while (0u != (SCB_SpiUartGetTxBufferSize() + SCB_GET_TX_FIFO_SR_VALID))
{
}
/* Wait until SPI Master deactivates slave select to ensure that the last
* data element has been completely tranferred.
*/
while (0u != SCB_SpiIsBusBusy())
{
}
/* SPI Master is ready to enter Deep Sleep mode. */
SCB_Sleep();
CySysPmDeepSleep();
In Slave mode, the data transmission is stopped asynchronously while the device enters Deep
Sleep mode. The moment that the stop occurs depends on the Enable wakeup from Deep Sleep
Mode option. When the option is disabled, the SCB_Sleep() API disables the component and the
slave stops driving the MISO line at that moment. Otherwise, when the Enable wakeup from
Deep Sleep Mode is enabled, the slave stops driving the MISO line at the moment when the
device enters Deep Sleep mode. The previous code sample can be used for the slave as well to
ensure that the transfer is completed before entering Deep Sleep mode.
The slave wakes up the device from Deep Sleep on detecting slave select activation. Waking up
takes time and the ongoing SPI transfer is negatively acknowledged "0xFF" bytes are sent out
on the MISO line. The master must poll the component again after the device wake-up time is
passed and data is loaded in the RX buffer.
Note The SCB_SpiUartGetTxBufferSize() or SCB_SpiUartGetRxBufferSize() function could
return different values for software and hardware buffers after Deep Sleep because SRAM
content is stored. However, TX and RX FIFO content is not stored while in Deep Sleep.
Slave data rate calculations
The SPI GUI calculates the actual data rate for master or slave devices. This value is based on
the parameters of the component and does not take to account such factors as: parameters of
external master or slave device as well as PCB delays. The master and slave parameters for
PSoC4 can be found in the DC and AC Electrical Characteristics of this document or the Device
datasheet.
The main factor limiting the maximum data rate between master and slave is the round trip path
delay. This delay includes the PCB delay from the falling edge of SCLK at the pin of the master
to the SCLK pin of the slave, the internal slave delay from the falling edge of SCLK to MISO
transition, the PCB delay from the slave MISO pin to the master MISO pin, and the master setup
time. The following equation takes to account delays listed above:
tROUND_TRIP_DELAY = tSCLK_PD_PCB + tDSO_SLAVE + tMISO_PD_PCB + tDSI_MASTER
tSCLK_PD_PCB is the PCB path delay of SCLK from the pin of the master device to the pin of
the slave device.
tDSO_SLAVE is the time it takes the slave to change MISO after SCLK clock driving edge is
captured. This parameter commonly listed in the slave device datasheet.
tMISO_PD_PCB is the PCB path delay of MISO from the pin of the slave device to the pin of
the master device.
tDSI_MASTER is the setup time of MISO signal to be sampled correctly by the master (the
MISO must be valid before SCLK clock capturing edge). This parameter commonly listed
in the master device datasheet.
When tROUND_TRIP_DELAY was calculated, the maximum communication data rate between master
and slave can be defined as following:
fSCLK (max) = 1 / (2* tROUND_TRIP_DELAY)
The assumption is made that master samples the MISO signal a half SCLK period after the
driving edge.
When master is capable of sampling the MISO signal a full of SCLK period after the driving edge
(late MISO sampling) the communication data rate is doubled and calculated as following:
fSCLK (max) = 1 / tROUND_TRIP_DELAY
Refer to the section MISO late sampling for more information about MISO sampling by the
master device.
As an example the fSCLK (max) is calculated for SCB SPI Master and Slave implemented on
PSoC 4100/PSoC 4200 devices. The design clock settings are following: IMO = HFCLK =
SYSCLK = 48 MHz. The clock source frequency connected to the SCB SPI Slave and Master
components is equal to 48MHz as well.
tDSO_SLAVE = TDSO = 42 + 3*tSCB = 42 + 3 * (1 / 48 MHz) = 105 ns
tDSI_MASTER = TDSI = 20 ns (Full clock, late MISO Sampling used)
For simplicity of the calculations assume that tSCLK_PD_PCB = 0 ns and tMISO_PD_PCB = 0 ns.
tROUND_TRIP_DELAY = tSCLK_PD_PCB + tDSO_SLAVE + tMISO_PD_PCB + tDSI_MASTER = 0 + 105 + 20 + 0 =
125 ns
fSCLK (max) = 1 / tROUND_TRIP_DELAY = 1 / 125 ns = 8 MHz
The SPI master is capable to generate maximum FSPI = 8 MHz and accordingly to calculation
above the MISO line will be sampled properly for this data rate.
For real applications the PCB delays would need to be added, and tDSO_SLAVE and tDSI_MASTER
adjusted to match the real master or slave device.
DMA Support
DMA is only available in PSoC 4100M/PSoC 4200M/PSoC 4200L devices.
The SPI mode provides interface to DMA controller. The signals for transmit and receive
direction can be used to trigger a DMA transfer. To enable this signal, the RX output or TX
output option must be enabled on the component Advanced parameter tab. The RX and TX
trigger output signals are hard-wired to the DMA controller; their connection to another source
will result in a build error. These signals are level sensitive and require the RX or TX FIFO level
to be set. The signal behavior for the triggers is as follows:
RX trigger output the signal remains active until the number of data elements in the RX
FIFO is greater than the value of RX FIFO level.
TX trigger output the signal remains active until the number of data elements in the TX
FIFO is less than the value of TX FIFO level.
The following table specifies what DMA component configuration should be used when it is
connected to the SCB (SPI mode) component.
DMA Source / Destination
name
SCB_RX_FIFO_RD_PTR
Direction
Source
Source /
Destination transfer
width
Word /
DMA
request
signal
Destination
Data bits /
Byte or Halfword
Description
rx_tr_out
Level
sensitive
Receive FIFO
tx_tr_out
Level
sensitive
Transmit FIFO
Byte or Halfword
SCB_TX_FIFO_WR_PTR
DMA
trigger type
Note If the number of data bits selected is less or equal to 8 bits the transfer data element width
is byte, if the number of data bits is between 9 and 16 bits the width is halfword.
Note The SCB (SPI mode) clears request signal within 4 SYSCLK cycles therefore level
sensitive configuration of DMA has to be wait 4 SYSCLK.
UART
Input/Output Connections
This section describes the various input and output connections for the SCB component. An
asterisk (*) in the list of terminals indicates that the terminals may be hidden on the symbol under
the conditions listed in the description of that terminals.
clock Input*
Clock that operates this block. The presence of this terminal varies depending on the Clock
from terminal parameter.
interrupt Output*
This signal can only be connected to an interrupt component or left unconnected. The presence
of this terminal varies depending on the Interrupt parameter.
rx_tr_out Output*
This signal can only be connected to a DMA channel component. This signal is used to trigger a
DMA transaction. The output of this terminal is controlled by the RX FIFO level. The presence of
this terminal varies depending RX Output parameter.
tx_tr_out Output*
This signal can only be connected to a DMA channel component. This signal is used to trigger a
DMA transaction. The output of this terminal is controlled by the TX FIFO level.. The presence of
this terminal varies depending TX Output parameter.
The interface-specific pins are buried inside component because these pins use dedicated
connections and are not routable as general purpose signals. See the I/O System section in the
device Technical Reference Manual (TRM) for more information.
Note The input buffer of buried output pins is disabled so as not to cause current linkage in low
power mode. Reading the status of these pins always returns zero. To get the current status, the
input buffer must be enabled before a status read.
Mode
This option determines the operating mode of the UART: Standard, SmartCard or IrDA. The
default mode is Standard.
Direction
This parameter defines the functional components you want to include in the UART. This can be
setup to be a bidirectional TX + RX (default), Receiver (RX only) or Transmitter (TX only).
Baud rate
This parameter defines the baud-rate configuration of the hardware for baud rate generation up
to 921600. The actual baud rate may differ based on available clock frequency and component
settings. This parameter has no effect if the Clock from terminal parameter is enabled. The
default is 115200.
Note The integer clock divider is used to provide the desired internal clock frequency to obtain
the specified baud rate (Clock from terminal option is disabled). To use a different clock source
configuration (for example: fractional clock divider), the clock must be provided externally to the
component by enabling the Clock from terminal option.
Actual baud rate
The actual data rate displays the data rate at which the component will operate with current
settings. The factors that affect the actual data rate calculation are: the accuracy of the
component clock (internal or external) and oversampling factor. When a change is made to any
of the component parameters that affect actual data rate, it becomes unknown. To calculate the
new actual data rate press the Apply button
Data bits
This parameter defines the number of data bits transmitted between start and stop of a single
UART transaction. Options are 5, 6, 7, 8 (default), or 9.
Eight data bits is the default configuration, sending a byte per transfer.
The 9-bit mode does not transmit 9 data bits; the ninth bit takes the place of the parity bit
as an indicator of address or data.
Parity
This parameter defines the functionality of the parity bit location in the transfer. This can be set to
None (default), Odd or Even.
Stop bits
This parameter defines the number of stop bits implemented in the transmitter. This parameter
can be set to 1 (default), 1.5 or 2 data bits.
Oversampling
This parameter defines the oversampling factor of the UART interface; the number of the
component clocks within one UART bit time. Oversampling factor is used to calculate the internal
component clock frequency required to achieve this amount of oversampling for the selected
Data rate. An oversampling factor between 8 and 16 is the range of valid values. The default is
12.
For IrDA mode the oversampling values are predefined and Median filter is always enabled.
Clock from terminal
This parameter allows choosing between an internally configured clock (by the component) or an
externally configured clock (by the user) for component operation. Refer to the Oversampling
section to understand relationship between component clock frequency and the component
parameters.
When this option is enabled the component does not control the data rate, but displays the
actual data rate based on the user-connected clock source frequency and the component
oversampling factor. When this option is not enabled the clock configuration is provided by the
component. The clock source frequency is calculated or selected by the component based on
the Data rate parameter and Oversampling factor.
Note PSoC Creator is responsible for providing requested clock frequency (internal or external
clock) based on current design clock configuration. When the requested clock frequency with
requested tolerance cannot be created, a warning about the clock accuracy range is generated
while building the project. This warning contains the actual clock frequency value created by
PSoC Creator. To remove this warning you must either change the system clock, component
settings or external clock to fit the clocking system requirements.
Median filter
This parameter applies 3 taps digital median filter on input path of RX line. This filter reduces the
susceptibility to errors. The default value is a Disabled.
Retry on NACK
This option is applicable only for SmartCard mode. It enables retry on NACK feature. The Data
frame is retransmitted when a negative acknowledgement is received.
Inverting RX
This option is applicable only for IrDA mode. It enables the inversion of the incoming RX line
signal.
RX buffer size
The RX buffer size parameter defines the size (in bytes/words) of memory allocated for a
receive data buffer. The RX buffer size minimum value is equal to the RX FIFO depth. The RX
FIFO is implemented in hardware. Values greater than the RX FIFO depth up to (232 2) imply
usage of the RX FIFO, a circular software buffer controlled by the supplied APIs, and internal
ISR. The software buffer size is limited only by the available memory. The interrupt mode is
automatically set to internal and the RX FIFO not empty interrupt source is reserved if a software
buffer is used.
For 4100/PSoC 4200 devices, the RX and TX FIFO depth is equal to 8 bytes/words.
For PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/PSoC 4200L devices,
the RX and TX FIFO depth is equal to 8 bytes/words or 16 bytes; refer to Byte mode for
more information.
TX buffer size
The TX buffer size parameter defines the size (in bytes/words) of memory allocated for a
transmit data buffer. The TX buffer size minimum value is equal to the TX FIFO depth. The TX
FIFO is implemented in hardware. Values greater than the TX FIFO depth up to (232 1) imply
usage of the TX FIFO, a circular software buffer controlled by the supplied APIs, and internal
ISR. The software buffer size is limited only by the available memory. The interrupt mode is
automatically set to the internal and the TX FIFO not full interrupt source is reserved if a software
buffer is used.
For 4100/PSoC 4200 devices, the RX and TX FIFO depth is equal to 8 bytes/words.
For PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/PSoC 4200L devices,
the RX and TX FIFO depth is equal to 8 bytes/words or 16 bytes; refer to Byte mode for
more information.
Byte mode
This option is only applicable for PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/
PSoC 4200L devices. It allows doubling the TX and RX FIFO depth from 8 to 16 bytes. This
implies that the number of data bits must be less than or equal to 8 bits. Increasing the FIFO
depth improves performance of UART operation as more bytes can be transmitted or received
without software interaction.
Interrupt
This option determines what interrupt modes are supported None, Internal or External.
option sets one or more interrupt sources, which trigger the interrupt. To add your own
code to the interrupt service routine you need to register a function using the
SCB_SetCustomInterruptHandler() function.
External This option removes the internal interrupt and provides an output terminal.
Only an interrupt component can be connected to the terminal if an interrupt handler is
desired. The Interrupt sources option sets one or more interrupt sources, which trigger
the interrupt output.
Note For buffer sizes greater than the hardware FIFO depth, the component automatically
enables the internal interrupt sources required for proper internal software buffer operations. In
addition, the global interrupt enable must be explicitly enabled for proper buffer handling.
DMA
DMA is only available in PSoC 4100M/PSoC 4200M/PSoC 4200L devices. The provided options
determine if DMA output trigger terminals are available on the component symbol.
RX Output
This option determines if the rx_tr_out terminal is available on the component symbol. This
signal can only be connected to a DMA channel trigger input. The output of this terminal is
controlled by the RX FIFO level. This option is active only when RX buffer size equal to FIFO
depth.
TX Output
This option determines if the tx_tr_out terminal is available on the component symbol. This signal
can only be connected to a DMA channel trigger input. The output of this terminal is controlled by
the TX FIFO level. This option is active only when TX buffer size equal to FIFO depth.
Interrupt sources
The interrupt sources are either level or pulse. Level interrupt sources in the following list are
indicated with an asterisk (*). Refer to sections TX FIFO interrupt sources and RX FIFO interrupt
sources for more information about level interrupt sources operation. The UART supports
interrupts on the following events:
UART done UART transmitter done event: all data elements from the TX FIFO are sent.
This interrupt source triggers later than TX FIFO empty by time it takes to transmit a
single data element. The TX FIFO empty triggers when the last data element from the TX
FIFO goes to the shifter register. However UART done triggers after this data element has
been transmitted.
TX FIFO not full * TX FIFO is not full. At least one data element can be written into the
TX FIFO.
RX FIFO not empty * RX FIFO is not empty. At least one data element is available in
the RX FIFO to be read.
Start bit error after the detection of the beginning of a start bit period (RX line
changes from '1' to '0'), the middle of the start bit period is sampled erroneously
(RX line is '1').
Note A start bit error is detected BEFORE a data frame is received.
Stop bit error: the RX line is sampled as '0', but a '1' was expected.
Note A stop bit error may result in failure to receive successive data frame(s). A
stop bit error is detected AFTER a data frame is received.
Note For stop bit duration equal to 1bit, the frame error is not tracked.
Notes
When RX buffer size is greater than the RX FIFO depth, the RX FIFO not empty interrupt
source is reserved by the component and used for the internal interrupt.
When TX buffer size is greater than the TX FIFO depth, the TX FIFO not full interrupt source is
reserved by the component and used for the internal interrupt.
FIFO level
The RX and TX FIFO level settings control behavior of the appropriate level interrupt sources as
well as RX and TX DMA triggers outputs.
RX FIFO
The interrupt or DMA trigger output signal remains active until the number of data elements in
the RX FIFO is greater than the value of RX FIFO level.
TX FIFO
The interrupt or DMA trigger output signal remains active until the number of data elements in
the TX FIFO is less than the value of TX FIFO level.
Multiprocessor mode
This parameter enables the multiprocessor mode where the 9th bit (in the place of the parity bit)
indicates an address. The default value is a Disabled. The number of Data bits must be set to 9
bits to get possibility to enable this option.
Address (hex)
Slave device address. Used to match when multiprocessor mode is enabled. The default value is
0x02.
Mask (hex)
Slave device address mask. These bits are used when matching to the slave address. The
default value is 0xFF.
On parity error Defines behavior when a parity check fails. When parity check is
passed, received data is sent to the RX FIFO. Otherwise, received data is dropped and
lost. Only applicable in Standard and SmartCard modes.
On frame error Defines behavior when a frame error is detected. When no frame error
is captured, received data is sent to the RX FIFO. Otherwise, received data is dropped
and lost.
RTS
This parameter is only applicable for PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/
PSoC 4200M/PSoC 4200L devices. It enables the Ready to Send (RTS) output signal. The RTS
signal is the part of flow control functionality used by the receiver. As long as the receiver is
ready to accept more data it will keep the RTS signal active. The RTS FIFO level parameter
determines if RTS remains active. The default value is a Disabled.
RTS Polarity
This parameter defines active polarity of the RTS output signal as Active Low (default) or Active
High.
RTS FIFO level
This parameter is only available for PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/
PSoC 4200M/PSoC 4200L devices. It determines whether the RTS signal remains active. While
the RX FIFO has fewer entries than the RTS FIFO level, the RTS signal remains active;
otherwise, the RTS signal becomes inactive. The RTS remains inactive unit data from RX FIFO
will be read to match RTS FIFO level. The default value is 4.
CTS
This parameter is only applicable for PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/
PSoC 4200M/PSoC 4200L devices. It enables the Clear to Send (CTS) input signal to be routedout to the pin. The CTS signal is the part of flow control functionality utilized by the transmitter.
The transmitter checks whether CTS signal is active before sending data from the TX FIFO. The
transmission of data is suspended if CTS signal is inactive and will be resumed when CTS signal
becomes active again. The default value is a Disabled.
CTS Polarity
This parameter defines active polarity of CTS input signal as Active Low (default) or Active High.
UART APIs
APIs allow you to configure the component using software. The following table lists and
describes the interface to each function. The subsequent sections discusses each function in
more detail.
By default, PSoC Creator assigns the instance name SCB_1 to the first instance of a
component in a given design. You can rename the instance to any unique value that follows the
syntactic rules for identifiers. The instance name becomes the prefix of every global function
name, variable, and constant symbol. For readability, the instance name used in the following
table is SCB.
Function
Description
SCB_Start()
SCB_Init()
SCB_Enable()
SCB_Stop()
SCB_Sleep()
SCB_Wakeup()
SCB_UartInit()
Configures the SCB for UART operation. Only used when using the SCB in
unconfigured mode.
SCB_UartPutChar()
Places a byte of data in the transmit buffer to be sent at the next available bus
time.
SCB_UartPutString()
Places a NULL terminated string in the transmit buffer to be sent at the next
available bus time.
SCB_UartPutCRLF()
Places byte of data followed by a carriage return (0x0D) and line feed (0x0A)
to the transmit buffer
SCB_UartGetChar()
SCB_UartGetByte()
SCB_UartSetRxAddress()
Sets the hardware detectable receiver address for the UART in Multiprocessor
mode.
SCB_UartSetRxAddressMask()
Sets the hardware address mask for the UART in Multiprocessor mode.
SCB_UartSetRtsPolarity()
SCB_UartSetRtsFifoLevel()
SCB_UartEnableCts()
SCB_UartDisableCts()
SCB_UartSetCtsPolarity()
SCB_SpiUartWriteTxData()
Places a data entry into the transmit buffer to be sent at the next available bus
time.
SCB_SpiUartPutArray()
SCB_SpiUartGetTxBufferSize()
SCB_SpiUartClearTxBuffer()
SCB_SpiUartReadRxData()
SCB_SpiUartGetRxBufferSize()
Function
Description
SCB_SpiUartClearRxBuffer()
void SCB_Start(void)
Description:
Invokes SCB_Init() and SCB_Enable(). After this function call the component is enabled
and ready for operation. This is the preferred method to begin component operation.
When configuration is set to Unconfigured SCB, the component must first be initialized
to operate in one of the following configurations: I2C, SPI, UART or EZ I2C. Otherwise
this function does not enable component.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_Init(void)
Description:
Initializes the SCB component to operate in one of the selected configurations: I2C, SPI,
UART or EZ I2C.
When configuration is set to Unconfigured SCB, this function does not do any
initialization. Use mode-specific initialization functions instead: SCB_I2CInit,
SCB_SpiInit, SCB_UartInit or SCB_EzI2CInit.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_Enable(void)
Description:
Enables SCB component operation: activates the hardware and internal interrupt.
For I2C and EZ I2C modes the interrupt is internal and mandatory for operation. For SPI
and UART modes the interrupt can be configured as none, internal or external. The
SCB configuration should be not changed when the component is enabled. Any
configuration changes should be made after disabling the component.
When configuration is set to Unconfigured SCB, the component must first be initialized
to operate in one of the following configurations: I2C, SPI, UART or EZ I2C using the
mode-specific functions: SCB_I2CInit, SCB_SpiInit, SCB_UartInit or SCB_EzI2CInit.
Otherwise this function does not enable component.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_Stop(void)
Description:
Disables the SCB component: disable the hardware and internal interrupt. It also
disables all TX interrupt sources so as not to cause an unexpected interrupt trigger
because after the component is enabled, the TX FIFO is empty.
Refer to the function SCB_Enable() for the interrupt configuration details.
This function disables the SCB component without checking to see if communication is
in progress. Before calling this function it may be necessary to check the status of
communication to make sure communication is complete. If this is not done then
communication could be stopped mid byte and corrupted data could result.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_Sleep(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_Wakeup(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
Calling the SCB_Wakeup() function without first calling the SCB_Sleep() function may
produce unexpected behavior.
Parameters:
config: pointer to a structure that contains the following ordered list of fields. These
fields match the selections available in the customizer. Refer to the customizer for
further description of the settings.
Field
uint32 mode
Description
Mode of operation for the UART. The following defines are available
choices:
SCB_UART_MODE_STD
SCB_UART_MODE_SMARTCARD
SCB_UART_MODE_IRDA
uint32 direction
uint32 dataBits
uint32 parity
uint32 stopBits
uint32 oversample
uint32 enableIrdaLowPower
uint32 enableMedianFilter
0 disable
1 enable
uint32 enableRetryNack
0 disable
1 enable
Ignored for modes other than SmartCard.
uint32 enableInvertedRx
0 disable
1 enable
Ignored for modes other than IrDA.
uint32 dropOnParityErr
uint32 dropOnFrameErr
uint32 enableWake
0 disable
1 enable
Ignored for modes other than standard UART. The RX functionality
has to be enabled.
uint32 rxBufferSize
uint8* rxBuffer
uint32 txBufferSize
uint8* txBuffer
uint32 enableMultiproc
uint32 multiprocAcceptAddr
uint32 multiprocAddr
uint32 multiprocAddrMask
uint32 enableInterrupt
0 disable
1 enable
The interrupt has to be enabled if software buffer will be used.
uint32 rxInterruptMask
uint32 rxTriggerLevel
uint32 txInterruptMask
uint32 txTriggerLevel
uint8 enableByteMode
uint8 enableCts
Ignored for all devices other than PSoC 4100 BLE/PSoC 4200
BLE/PSoC 4100M/PSoC 4200M. Enables usage of CTS input signal
by the UART transmitter.
0 disable
1 enable
uint8 ctsPolarity
Ignored for all devices other than PSoC 4100 BLE/PSoC 4200
BLE/PSoC 4100M/PSoC 4200M. Sets active polarity of CTS input
signal.
SCB_UART_CTS_ACTIVE_LOW
SCB_UART_CTS_ACTIVE_HIGH
uint8 rtsRxFifoLevel
Ignored for all devices other than PSoC 4100 BLE/PSoC 4200
BLE/PSoC 4100M/PSoC 4200M. RX FIFO level for RTS signal
activation. While the RX FIFO has fewer entries than the RTS FIFO
level value the RTS signal remains active, otherwise the RTS signal
becomes inactive. By setting this field to 0, RTS signal activation is
disabled.
uint8 rtsPolarity
Ignored for all devices other than PSoC 4100 BLE/PSoC 4200
BLE/PSoC 4100M/PSoC 4200M. Sets active polarity of RTS output
signal.
SCB_UART_RTS_ ACTIVE_LOW
SCB_UART_RTS_ACTIVE_HIGH
Return Value:
None
Side Effects:
None
Places a byte of data in the transmit buffer to be sent at the next available bus time.
This function is blocking and waits until there is a space available to put requested data
in the transmit buffer.
For UART Multi Processor mode this function can send 9-bits data as well. Use
SCB_UART_MP_MARK to add a mark to create an address byte.
Note This function is implemented as macro which calls SCB_SpiUartWriteTxData().
Parameters:
Return Value:
None
Side Effects:
None
Places a NULL terminated string in the transmit buffer to be sent at the next available
bus time.
This function is blocking and waits until there is a space available to put requested data
in transmit buffer.
Parameters:
const char8 string[]: pointer to the null terminated string array to be placed in the
transmit buffer.
Return Value:
None
Side Effects:
None
Places byte of data followed by a carriage return (0x0D) and line feed (0x0A) in the
transmit buffer
This function is blocking and waits until there is a space available to put all requested
data in transmit buffer.
Parameters:
Return Value:
None
Side Effects:
None
uint32 SCB_UartGetChar(void)
Description:
Retrieves next data element from receive buffer. This function is designed for ASCII
characters and returns a char where 1 to 255 are valid characters and 0 indicates an
error occurred or no data is present.
RX software buffer is disabled: Returns data element retrieved from RX FIFO.
RX software buffer is enabled: Returns data element from the software receive buffer.
Parameters:
None
Return Value:
uint32: Next data element from the receive buffer. ASCII character values from 1 to 255
are valid. A returned zero signifies an error condition or no data available.
Side Effects:
The errors bits may not correspond with reading characters due to RX FIFO and
software buffer usage.
RX software buffer is enabled: The internal software buffer overflow is not treated as an
error condition. Check SCB_rxBufferOverflow to capture that error condition.
uint32 SCB_UartGetByte(void)
Description:
Retrieves next data element from the receive buffer, returns received byte and error
condition.
RX software buffer disabled: Returns data element retrieved from RX FIFO. Undefined
data will be returned if the RX FIFO is empty
RX software buffer enabled: Returns data element from the software receive buffer
Parameters:
None
Return Value:
uint32: Bits 7-0 contain the next data element from the receive buffer and other bits
contain the error condition. The error condition constants are provided below:
RX error conditions
Side Effects:
Description
SCB_UART_RX_OVERFLOW
SCB_UART_RX_UNDERFLOW
SCB_UART_RX_FRAME_ERROR
SCB_UART_RX_PARITY_ERROR
The errors bits may not correspond with reading characters due to RX FIFO and
software buffer usage.
RX software buffer is disabled: Internal software buffer overflow is not returned as
status by this function. Check SCB_rxBufferOverflow to capture that error condition.
Sets the hardware detectable receiver address for the UART in Multiprocessor mode.
Parameters:
Return Value:
None
Side Effects:
None
Sets the hardware address mask for the UART in Multiprocessor mode.
Parameters:
Return Value:
None
Side Effects:
None
Parameters:
Description
SCB_UART_RTS_ACTIVE_LOW
SCB_UART_RTS_ACTIVE_HIGH
Return Value:
None
Side Effects:
None
Sets level in the RX FIFO for RTS signal activation. While the RX FIFO has fewer
entries than the RTS FIFO level the RTS signal remains active, otherwise the RTS
signal becomes inactive.
Only available for PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/ PSoC
4200L devices.
Parameters:
Return Value:
None
Side Effects:
None
void SCB_UartEnableCts(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_UartDisableCts(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
Parameters:
Description
CTS signal is active low
None
Side Effects:
None
Places a data entry into the transmit buffer to be sent at the next available bus time.
The data transmit direction is LSB.
This function is blocking and waits until there is space available to put the requested
data in the transmit buffer.
For UART Multi Processor mode this function can send 9-bits data. Use
SCB_UART_MP_MARK to add a mark to create an address byte.
Parameters:
Return Value:
None
Side Effects:
None
Parameters:
const uint16/uint8 wrBuf[]: pointer to an array with data to be placed in transmit buffer.
The amount of data bits to be transmitted as one array entry depends on Data bits
selection (the data bit counting starts from LSB for each array entry).
uint32 count: number of data elements to be placed in the transmit buffer.
Return Value:
None
Side Effects:
None
uint32 SCB_SpiUartGetTxBufferSize(void)
Description:
Parameters:
None
Return Value:
Side Effects:
None
void SCB_SpiUartClearTxBuffer(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
uint32 SCB_SpiUartReadRxData(void)
Description:
Parameters:
None
Return Value:
Side Effects:
None
uint32 SCB_SpiUartGetRxBufferSize(void)
Description:
Parameters:
None
Return Value:
Side Effects:
None
void SCB_SpiUartClearRxBuffer(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
Global Variables
Knowledge of these variables is not required for normal operations.
Variable
SCB_initVar
Description
SCB_initVar indicates whether the SCB component has been initialized. The variable
is initialized to 0 and set to 1 the first time SCB_Start() is called. This allows the
component to restart without reinitialization after the first call to the SCB_Start()
routine.
If re-initialization of the component is required, then the SCB_Init() function can be
called before the SCB_Start() or SCB_Enable() function.
Variable
SCB_rxBufferOverflow
Description
SCB_rxBufferOverflow sets when internal software receive buffer overflow was
occurred.
Bootloader Support
The SCB component in UART mode can be used as a communication component for the
Bootloader. The following configuration should be used to support UART communication
protocol from an external system to the Bootloader:
Mode: Standard
Direction: TX+RX
Data bits: 8 bits
Baud rate: Must match Host (boot device)
Parity: Must match Host (boot device).
Stop Bits: Must match Host (boot device).
RX buffer size: Must match or be greater than the maximum size of the packet received
from Host. The recommended RX buffer size value to select for bootloading when using
the Bootloader Host Tool (shipped with PSoC Creator) is 64.
TX buffer size: Must match or be greater than the maximum size of the packet transmitted
to Host. The recommended TX buffer size to select for bootloading when using the
Bootloader Host Tool (shipped with PSoC Creator) is 64.
For more information about the Bootloader, refer to the Bootloader component datasheet.
The following API functions are provided for Bootloader use.
Function
Description
SCB_CyBtldrCommStart()
SCB_CyBtldrCommStop()
SCB_CyBtldrCommReset()
SCB_CyBtldrCommRead()
Allows the caller to read data from the bootloader host (the host writes the data).
SCB_CyBtldrCommWrite()
Allows the caller to write data to the bootloader host (the host reads the data).
void SCB_CyBtldrCommStart(void)
Description:
Starts the UART component and enables its interrupt (if TX or RX buffer size is greater
than FIFO depth).
Every incoming UART transfer is treated as a command for the bootloader.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_CyBtldrCommStop(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_CyBtldrCommReset(void)
Description:
Parameters:
None
Return Value:
None
Side Effects:
None
Allows the caller to read data from the bootloader host (the host writes the data). The
function handles polling to allow a block of data to be completely received from the host
device.
Parameters:
uint8 pData[]: Pointer to the block of data to be read from bootloader host.
uint16 size: Number of bytes to be read from bootloader host.
uint16 *count: Pointer to variable to write the number of bytes actually read by
bootloader host.
uint8 timeOut: Number of units in 10 ms to wait before returning because of a timeout.
Return Value:
Side Effects:
None
Allows the caller to write data to the bootloader host (the host reads the data). The
function does not use timeout and returns after data has been copied into the transmit
buffer. The data transmission starts immediately after the first data element is written
into the buffer and lasts until all data elements from the buffer are sent.
Parameters:
const uint8 pData[]: Pointer to the block of data to send to the bootloader host.
uint16 size: Number of bytes to send to bootloader host.
uint16 *count: Pointer to variable to write the number of bytes actually written to
bootloader host.
uint8 timeOut: The timeout is not used by this function. The function returns as soon as
data is copied into the transmit buffer.
Return Value:
Side Effects:
None
SCB_CyBtldrCommRead details
The UART interface does not provide start and stop conditions to define the start and end of a
transfer like I2C. Therefore, the following approach is used to define when a command packet
from the host is received:
1) To determine when the start of a packet has occurred, the RX buffer is checked at a one
millisecond interval until the buffer size is non-zero or timeout is expired. As soon as at
least one data element has been received the communication component knows a packet
transfer has started and immediately begins looking for the end of the packet.
2) The transfer is completed if no new data elements are received within byte-to-byte
interval. This time interval is defined as the time consumed to transfer two data elements
with selected data rate. It is calculated by the component based on current data rate
selection. If needed, the byte-to-byte interval can be changed using global defines. Open
project Build Settings -> Compiler -> Command line and provide the global define of the
interval in microseconds. For example, to change interval to 40 microseconds:
-D DUT_UART_BYTE_TO_BYTE=40
TX Transmitter
RX Receiver
RX
RX
TX
TX
UART2
START
DATA
DATA
DATA
DATA
DATA
DATA
DATA
PAR
STOP
START
DATA
DATA
DATA
Flow control
Flow control is a method used to provide reliable communication between the receiver and
transmitter without data loss. This method implies that a receiver tells a transmitter to stop
(suspend) or start (resume) transmitting. Hardware flow control is supported by the UART in
Standard mode by PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/ PSoC 4200L
devices. The two extra lines for hardware flow control are needed in addition to data lines. They
are called RTS and CTS. These lines are cross-coupled between the two devices, so the RTS
line on one device is connected to the CTS line on the other device and vice versa. The
Configure dialog provides independent control of RTS and CTS signals.
Figure 28. UART hardware flow control typical connection
UART1
RX
RX
TX
TX
CTS
CTS
RTS
RTS
UART2
As long as the receiver is ready to accept more data it will keep the RTS signal active. The RTS
FIFO level parameter determines how the RTS remains active as follows: while the RX FIFO has
fewer entries than the RX FIFO level the RTS signal remains active, otherwise the RTS signal
becomes inactive. The RTS remains inactive unit data from RX FIFO is read to match RTS
activation condition.
Figure 29. UART RTS signal activation
Recevier
Recevier
Recevier
RX
RX FIFO
RX
Used
RX
RX FIFO
RX FIFO
Used
RTS Level
RTS Level
<
RTS Level
<
ACTIVE
<
ACTIVE
RTS
Used
RTS
INACTIVE
RTS
The transmitter checks whether the CTS signal is active before sending data from the TX FIFO
on the bus. The transmission of data is suspended if the CTS signal is inactive and will be
resumed when CTS signal becomes active again.
Typically, the RTS and CTS signals are active low. However, there is a possibility to change the
active polarity of these signals.
RX
TX
Master TX
Master RX
RX
TX
TX
UART MP
Slave 1
RX
TX
UART MP
Slave 2
RX
UART MP
Slave 3
To enable Multiprocessor mode, configure the UART with the following options: Mode: Standard,
Data bits: 9 bits, Parity: None.
Figure 31. UART data frame in Multiprocessor mode
DATA Field
IDLE
START
DATA
DATA
DATA
DATA
DATA
DATA
DATA
DATA
MP
STOP
Because the data link layer of a multi-drop network is a user-defined protocol, it offers a flexible
way of composing the data field.
All the bits in an address frame can be used to represent a device address. Alternatively, some
bit can be used to represent the address, while the remaining bits can represent a command to
the slave device, and some bits can represent the length of data in following data frames.
The SCB can be used as a master or slave device in multiprocessor mode.
When UART works as slave device, the received address is matched with Address and Mask.
The matched address is written in the RX FIFO when Accept matching address in RX FIFO is
checked. In the case of a match, subsequent received data are sent to the RX FIFO. In the case
of no match, subsequent received data is dropped, until next address received for compare.
UART 9th data bit usage
The 9th bit is sent in the parity bit position and most typically used to define whether the data sent
was an address or standard data. A mark (1) in the parity bit indicates an address was sent and
a space (0) in the parity bit indicates data was sent. The data flow is "Start Bit, Data Bits, Parity,
Stop Bits," similar to the other parity modes but this bit has to be controlled by user firmware
before the transfer rather than being calculated based on the data bit values.
tx_data = 0x31;
tx_data |= UART_UART_MP_MARK; /* Set 9th bit to indicate address */
UART_SpiUartWriteTxData(tx_data);
Refer to the ISO/IEC 7816-3:2006 Identification cards Integrated circuit cards Part 3: Cards with contacts
Electrical interface and transmission protocols (1997) on the ISO web site at www.iso.org
START
DATA
DATA
DATA
DATA
DATA
DATA
DATA
PAR
STOP
START
DATA
DATA
DATA
DATA
DATA
Two successive data transfers (7data bits, 1 parity bit, 2 stop bits) with NACK
TX / RX
IDLE
START
DATA
DATA
DATA
DATA
DATA
DATA
DATA
PAR
STOP
NACK
STOP
START
A SmartCard transfer has the transmitter drive the Start Bit and Data Bits and a Parity Bit.
After these bits, it enters its stop period by releasing the bus. Releasing results in the line being
1 (the value of a Stop Bit). After half bit transfer period into the stop period, the receiver may
drive a NACK on the line (a value of 0) for one to two bit transfer period. This NACK is observed
by the transmitter, which reacts by extending its stop period by one bit transfer period. For this
protocol to work, the stop period should be larger than one bit transfer period.
Note Data transfer with a NACK takes one bit transfer period longer than a data transfer without
a NACK.
Example implementation of SmartCard reader
You have to consider how to implement a complete SmartCard system with other available
system resources for RST signal, CLK signal, card detect signal, card power supply control
signals.
Figure 33 is example of implementing SmartCard reader function with TCPWM and pins
components.
The UART component is connected to I/O card contact, a pull-up resistor must be connected to
this line. SC_RST, SC_CLK are standard card contacts. SC_DET is for card insertion detection.
SC_PWR is for control of card power on or off. Refer to the ISO7816 specification for more
details.
IrDA mode operation
IrDA is defined with peer to peer topology. SCB only provides support [9] for IrDA from the basic
physical layer with rates from 1200 bps to 115200 bps. The physical layer is responsible for the
definition of hardware transceivers for the data transmission. The higher level protocol
implementation is left for firmware to handle from the user level.
The minimum demand for transmission rates for IrDA is only 9600 bps. All transmissions must
be started at this rate to enable compatibility. Higher rates are a matter of negotiation of the ports
after establishing the links.
The IrDA protocol adds a modulation scheme to the UART signaling. At the transmitter, bits are
modulated. At the receiver, bits are demodulated. The modulation scheme uses a Return-toZero-Inverted (RZI) format. A bit value of 0 is signaled by a short 1 pulse on the line and a bit
value of 1 is signaled by holding the line to 0. IrDA is using 3/16 RZI modulation.
Refer to the IrPHY (IrDA Physical Layer Link Specification) (Rev. 1.4 from May 2001) on the IrDA web site at
www.irda.org
The Figure 34 shows UART frame and IR frame, comprised a Start Bit, 8 Data Bits, no Parity Bit
and ending with a Stop Bit.
Figure 34. UART Frame and IR Frame example
Oversampling Selection
IrDA is using 3/16 RZI modulation, so the sampling clock frequency should be set 16x of
selected Baud rate, by configuring Oversampling. Oversampling should always be 16 for
IrDA.
Normal versus Low power transmitting
There are two modes of IrDA operation:
Normal transmission pulse width is roughly 3/16 of the bit period (for all baud rates)
Low power transmission pulse width is potentially smaller (down to 1.62 s typical and
1.41s minimal) than 3/16 of the bit period (for rates less 115200 bps). Supported only for
RX only direction.
Inverting RX
This option is used to support two possible demodulation schemes described below.
According to the IrPHY specification, the IR frame modulation (encoding) scheme is shown in
Figure 35.
Figure 35. IR frame modulation scheme
CLK
The IR frame demodulation (decoding) scheme is shown in Figure 36. RXIR line voltage level is
default low, active high.
Figure 36. IR frame demodulation scheme 1 (active high)
CLK
In an application, the RXIR frame output from IrDA transceiver is often pull-up, default high,
active low. Figure 37 shows another demodulation scheme.
Figure 37. IR frame demodulation scheme 2 (active low)
CLK
FIFO depth
The hardware provides two FIFOs. One is used for receive direction, RX FIFO, and the other for
transmit direction, TX FIFO. The FIFO depth is 8 data elements. The width of each data element
is 16 bits. The data frame width is configurable from 4-16 bits. One FIFO element is consumed
regardless of the data frame width.
PSoC 4100 BLE/PSoC 4200 BLE/PSoC 4100M/PSoC 4200M/ PSoC 4200L devices provide the
ability to double the FIFO depth to 16 data elements when the data frame width is 4-8 bits.
Software Buffer
Selecting RX or TX Buffer Size values greater than the FIFO depth enables usage of the RX or
TX FIFO and a circular software buffer. The array of requested size is allocated internally by the
component for the TX software buffer. The allocated array for the RX software buffer has one
extra element that remains empty while in operation. Keeping this element empty simplifies
circular buffer operation. The interrupt option is automatically updated to Internal, and the RX or
TX interrupt source are reserved to provide software buffer operation. The internal interrupt
handler is hooked up to the interrupt. Its main purpose is to provide interaction between software
buffers and the hardware RX or TX FIFO.
The software buffer overflow can happen only for the RX direction when the UART flow control
signal RTS is disabled. The data elements read from the RX FIFO that do not fit into the software
buffer are discarded. This event is reported via global variable SCB_rxBufferOverflow.
The software buffer overflow is not expected when the RTS signal is enabled. When the RX
software buffer becomes full, the RX Not empty interrupt source is disabled and data elements
stop reading from the RX FIFO. However, the transfer continues until the number of data
elements in the RX FIFO is not equal to the RTS trigger level. Then, the RTS signal is activated
to notify the transmitter to pause the transfer. As soon as the data element has been read from
the RX software buffer, the RX Not empty interrupt source is enabled and transfer continues.
For the TX direction, the provided APIs do not allow software buffer overflow.
Interrupts
When RX buffer size or TX buffer size is greater than the FIFO depth, the RX FIFO not empty
or TX FIFO not full interrupt sources are reserved by the component for internal software buffer
operations. Do not clear or disable them because it can cause incorrect software buffer
operation. However, it is the users responsibility to clear interrupts from other enabled interrupt
because they are not cleared automatically. Create a custom function that clears these interrupt
sources and register it using SCB_SetCustomInterruptHandler(). Each time internal interrupt
handler executes the custom function is called before handling software buffer operation. In case
RX buffer size or TX buffer size is equal to the FIFO depth only the hardware TX or RX FIFO is
used. In the Internal interrupt mode the interrupts are not cleared automatically. It is the users
responsibility to do this. The External interrupt mode is preferred in this case.
Low power modes
The component in UART mode is able to be a wakeup source from Sleep and Deep Sleep low
power modes.
Sleep mode is identical to Active from a peripheral point of view. No configuration changes are
required in the component or code before entering/exiting this mode. Any UART activity in TX or
RX direction that involves an interrupt to occur leads to wakeup.
Deep Sleep mode requires that the UART be properly configured to be a wakeup source. The
Enable wakeup from Deep Sleep Mode option must be checked in the UART configuration
dialog (the RX direction must be enabled to allow wakeup). The SCB_Sleep() and
SCB_Wakeup() functions must be called before/after entering/exiting Deep Sleep.
The device wakes up by the RX GPIO falling edge event that is generated by the incoming start
bit. There are two constraints for wakeup:
The 1st data bit of wakeup transfer has to be 1. The UART skips the start bit and
synchronizes on the 1st data bit. If synchronization does not occur, the received data will
be corrupted.
The wakeup time of the device must be less than one bit duration; otherwise, the received
data will be incorrect.
Note RX GPIO interrupt restricts usage of all GPIO interrupts from the port where the UART rx
pin is placed.
The content of TX and RX FIFOs is cleared when the device enters the Deep Sleep mode.
Therefore, received data should be stored in the SRAM buffer and transmit data should be
transferred before entering Deep Sleep mode to avoid data loss.
The transmission is stopped asynchronously while the device enters Deep Sleep mode. The
moment that the stop occurs depends on the Enable wakeup from Deep Sleep Mode option.
When the option is disabled the SCB_Sleep() API disables the component and transfer is
stopped at that moment. Otherwise, when the Enable wakeup from Deep Sleep Mode is
enabled, the transfer is stopped at the moment when the device enters Deep Sleep mode.
The following code is suggested to ensure that transmission is completed before entering Deep
Sleep mode. It occurs when all data elements have been transferred from the software buffer (if
utilized), TX FIFO, and shifter register.
/* Wait until UART transmitter completes transfer data. */
while (0u != (SCB_SpiUartGetTxBufferSize() + SCB_GET_TX_FIFO_SR_VALID))
{
}
/* UART transmitter is ready to enter Deep Sleep mode. */
SCB_Sleep();
CySysPmDeepSleep();
Function Name
GCC
_write()
MDK
fputc()
RVDS
fputc()
IAR
__write()
The application should revise these functions to call the communication component API to send
data via the selected interface (in this case, the UART interface).
Note The following code example uses an instance name of "SCB" for the SCB UART
component:
#include <project.h>
#include <stdio.h>
#if defined (__GNUC__)
/* Add an explicit reference to the floating point printf library to allow
the usage of floating point conversion specifier. */
/* Enable interrupts */
SCB_Start();
Note The printf() function prepares the text stream in the buffer and transmits it when new-line
character \n is reached.
DMA Support
DMA is only available in PSoC 4100M/PSoC 4200M/ PSoC 4200L devices.
The UART mode may interface with the DMA controller. Signals for transmit and receive
direction can be used to trigger a DMA transfer. To enable this signal, the RX output or TX
output option must be enabled in the component Advanced parameter tab. The RX and TX
trigger output signals are hard-wired to the DMA controller; their connection to another source
will result in a build error. These signals are level sensitive therefore require the RX or TX FIFO
level to be set. The FIFO level signal behavior is as follows:
RX trigger output the signal remains active until the number of data elements in the RX
FIFO is greater than the value of RX FIFO level.
TX trigger output the signal remains active until the number of data elements in the TX
FIFO is less than the value of TX FIFO level.
The following table specifies what DMA component configuration should be used when it is
connected to the SCB (UART mode) component.
DMA Source / Destination
name
SCB_RX_FIFO_RD_PTR
Direction
Source
Source /
Destination transfer
width
Word /
DMA
request
signal
Destination
Data bits /
Byte or Halfword
Description
rx_tr_out
Level
sensitive
Receive FIFO
tx_tr_out
Level
sensitive
Transmit FIFO
Byte or Halfword
SCB_TX_FIFO_WR_PTR
DMA
trigger type
Note If the number of data bits are less than or equal to 8 bits the transfer data element width is
byte, if the number of data bits are between 9 and 16 bits the width is halfword.
Note The SCB (UART mode) clears request signal within 4 SYSCLK cycles therefore level
sensitive configuration of DMA has to be wait 4 SYSCLK.
Define a macro to signal the presence of a callback (in cyapicallbacks.h). This will
uncomment the function call from the components source code.
Write the function declaration (in cyapicallbacks.h). This will make this function visible by
all the project files.
Write the function implementation (in any user file).
Associated Macro
Description
SCB_EZI2C_STRETCH_ISR_ SCB_EZI2C_STRETCH_ISR_
EntryCallback
ENTRY_CALLBACK
SCB_EZI2C_STRETCH_ISR_ SCB_EZI2C_STRETCH_ISR_
ExitCallback
EXIT_CALLBACK
SCB_EZI2C_NO_STRETCH_
ISR_EntryCallback
SCB_EZI2C_NO_STRETCH_
ISR_ExitCallback
SCB_I2C_ISR_EntryCallback
SCB_I2C_ISR_ENTRY_CALL
BACK
SCB_I2C_ISR_ExitCallback
SCB_SPI_UART_ISR_EntryC
allback
SCB_SPI_UART_ISR_ENTR
Y_CALLBACK
SCB_SPI_UART_ISR_ExitCal
lback
SCB_SPI_UART_ISR_EXIT_
CALLBACK
10
The callback function name is formed by component function name optionally appended by short explanation
and Callback suffix.
Associated Macro
Description
SCB_UART_WAKEUP_ISR_
EntryCallback
SCB_UART_WAKEUP_ISR_
ENTRY_CALLBACK
SCB_UART_WAKEUP_ISR_
ExitCallback
SCB_UART_WAKEUP_ISR_
EXIT_CALLBACK
Interrupt APIs
These functions are common for most SCB modes.
By default, PSoC Creator assigns the instance name SCB_1 to the first instance of a
component in a given design. You can rename it to any unique value that follows the syntactic
rules for identifiers. The instance name becomes the prefix of every global function name,
variable, and constant symbol. For readability, the instance name used in the following table is
SCB.
Function
Description
SCB_EnableInt()
SCB_DisableInt()
SCB_GetInterruptCause()
SCB_SetCustomInterruptHandler()
SCB_GetTxInterruptSource()
SCB_SetTxInterruptMode()
SCB_GetTxInterruptMode()
SCB_GetTxInterruptSourceMasked()
SCB_ClearTxInterruptSource()
SCB_SetTxInterrupt()
SCB_SetTxFifoLevel()
SCB_GetRxInterruptSource()
SCB_SetRxInterruptMode()
SCB_GetRxInterruptMode()
SCB_GetRxInterruptSourceMasked()
Function
Description
logical AND of corresponding bits from RX interrupt request and mask
registers.
SCB_ClearRxInterruptSource()
SCB_SetRxInterrupt()
SCB_SetRxFifoLevel()
SCB_GetMasterInterruptSource()
SCB_SetMasterInterruptMode()
SCB_GetMasterInterruptMode()
SCB_GetMasterInterruptSourceMasked()
SCB_ClearMasterInterruptSource()
SCB_SetMasterInterrupt()
SCB_ClearSlaveInterruptSource()
SCB_SetSlaveInterruptMode()
SCB_GetSlaveInterruptMode()
SCB_GetSlaveInterruptSourceMasked()
SCB_ClearSlaveInterruptSource()
SCB_SetSlaveInterrupt()
void SCB_EnableInt(void)
Description:
When using an Internal interrupt, this enables the interrupt in the NVIC. When using an
external interrupt the API for the interrupt component must be used to enable the
interrupt.
Parameters:
None
Return Value:
None
Side Effects:
None
void SCB_DisableInt(void)
Description:
When using an Internal interrupt, this disables the interrupt in the NVIC. When using an
external interrupt the API for the interrupt component must be used to disable the
interrupt.
Parameters:
None
Return Value:
None
Side Effects:
None
uint32 SCB_GetInterruptCause(void)
Description:
Returns a mask of bits showing the source of the current triggered interrupt. This is
useful for modes of operation where an interrupt can be generated by conditions in
multiple interrupt source registers.
Parameters:
None
Return Value:
uint32: Mask with the OR of the following conditions that have been triggered:
Interrupt causes constants
Side Effects:
Description
SCB_INTR_CAUSE_MASTER
SCB_INTR_CAUSE_SLAVE
SCB_INTR_CAUSE_TX
Interrupt from TX
SCB_INTR_CAUSE_RX
Interrupt from RX
None
Registers a function to be called by the internal interrupt handler. First the function that
is registered is called, and then the internal interrupt handler performs any operations
such as software buffer management functions. It is users responsibility to not break
the software buffer operations. Only one custom handler is supported; which is the
function provided by the most recent call. At initialization time no custom handler is
registered.
Parameters:
func: Pointer to the function to register. The value NULL indicates to remove the
current custom interrupt handler.
Return Value:
None
Side Effects:
None
Registers a function to be called by the I2C slave interrupt handler during the I2C
interrupt address processing. This function should be used when multiple I 2C addresses
need to be decoded or general call address supported. The registered function must
return decision whether to ACK or NACK accepted address. Only one I2C address
handler is supported, which is the function provided by the most recent call. At
initialization time no I2C address handler is registered.
Parameters:
func: Pointer to the function to register. The value NULL indicates to remove the current
custom interrupt handler.
The registered function must return decision whether to ACK or NACK accepted
address: 0 ACK, other values NACK. The registered callback function does not
perform the ACK/NACK, this operation is performed in the I2C ISR.
Return Value:
None
Side Effects:
None
uint32 SCB_GetTxInterruptSource(void)
Description:
Parameters:
None
Return Value:
Description
SCB_INTR_TX_FIFO_LEVEL
SCB_INTR_TX_NOT_FULL
SCB_INTR_TX_EMPTY
SCB_INTR_TX_OVERFLOW
SCB_INTR_TX_UNDERFLOW
SCB_INTR_TX_UART_NACK
SCB_INTR_TX_UART_DONE
Side Effects:
None
Writes TX interrupt mask register. This register configures which bits from TX interrupt
request register will trigger an interrupt event.
Parameters:
Return Value:
None
Side Effects:
None
uint32 SCB_GetTxInterruptMode(void)
Description:
Returns TX interrupt mask register This register specifies which bits from TX interrupt
request register will trigger an interrupt event.
Parameters:
None
Return Value:
Side Effects:
None
uint32 SCB_GetTxInterruptSourceMasked(void)
Description:
Returns TX interrupt masked request register. This register contains logical AND of
corresponding bits from TX interrupt request and mask registers.
This function is intended to be used in the interrupt service routine to identify which of
enabled TX interrupt sources cause interrupt event.
Parameters:
None
Return Value:
Side Effects:
None
Parameters:
Return Value:
None
Side Effects:
The side effects are listed in the table below for each affected interrupt source. Refer to
section TX FIFO interrupt sources for detailed description.
TX interrupt sources
Description
SCB_INTR_TX_FIFO_LEVEL
SCB_INTR_TX_NOT_FULL
SCB_INTR_TX_EMPTY
SCB_INTR_TX_UNDERFLOW
Parameters:
Return Value:
None
Side Effects:
None
Parameters:
Return Value:
None
Side Effects:
None
uint32 SCB_GetRxInterruptSource(void)
Description:
Parameters:
None
Return Value:
Side Effects:
Description
SCB_INTR_RX_FIFO_LEVEL
SCB_INTR_RX_NOT_EMPTY
SCB_INTR_RX_FULL
SCB_INTR_RX_OVERFLOW
SCB_INTR_RX_UNDERFLOW
SCB_INTR_RX_FRAME_ERROR
SCB_INTR_RX_PARITY_ERROR
None
Writes RX interrupt mask register. This register configures which bits from RX interrupt
request register will trigger an interrupt event.
Parameters:
Return Value:
None
Side Effects:
None
uint32 SCB_GetRxInterruptMode(void)
Description:
Returns RX interrupt mask register This register specifies which bits from RX interrupt
request register will trigger an interrupt event.
Parameters:
None
Return Value:
Side Effects:
None
uint32 SCB_GetRxInterruptSourceMasked(void)
Description:
Returns RX interrupt masked request register. This register contains logical AND of
corresponding bits from RX interrupt request and mask registers.
This function is intended to be used in the interrupt service routine to identify which of
enabled RX interrupt sources cause interrupt event.
Parameters:
None
Return Value:
Side Effects:
None
Parameters:
Return Value:
None
Side Effects:
The side effects are listed in the table below for each affected interrupt source. Refer to
section RX FIFO interrupt sources for detailed description.
RX interrupt sources
Description
SCB_INTR_RX_FIFO_LEVEL
SCB_INTR_RX_NOT_EMPTY
SCB_INTR_RX_FULL
Parameters:
Return Value:
None
Side Effects:
None
Parameters:
Return Value:
None
Side Effects:
None
uint32 SCB_GetMasterInterruptSource(void)
Description:
Returns Master interrupt request register. This register contains current status of Master
interrupt sources.
Parameters:
None
Return Value:
Description
SPI master transfer is complete.
Refer to Interrupt sources section for
detailed description.
Side Effects:
SCB_INTR_MASTER_I2C_ARB_LOST
SCB_INTR_MASTER_I2C_NACK
SCB_INTR_MASTER_I2C_ACK
SCB_INTR_MASTER_I2C_STOP
SCB_INTR_MASTER_I2C_BUS_ERROR
None
Writes Master interrupt mask register. This register configures which bits from Master
interrupt request register will trigger an interrupt event.
Parameters:
Return Value:
None
Side Effects:
None
uint32 SCB_GetMasterInterruptMode(void)
Description:
Returns Master interrupt mask register This register specifies which bits from Master
interrupt request register will trigger an interrupt event.
Parameters:
None
Return Value:
Side Effects:
None
uint32 SCB_GetMasterInterruptSourceMasked(void)
Description:
Returns Master interrupt masked request register. This register contains logical AND of
corresponding bits from Master interrupt request and mask registers.
This function is intended to be used in the interrupt service routine to identify which of
enabled Master interrupt sources cause interrupt event.
Parameters:
None
Return Value:
Side Effects:
None
Parameters:
Return Value:
None
Side Effects:
None
Parameters:
uint32 interruptMask: Master interrupt sources to set in the Master interrupt request
register (refer to SCB_GetMasterInterruptSource() function for return values).
Return Value:
None
Side Effects:
None
uint32 SCB_GetSlaveInterruptSource(void)
Description:
Returns Slave interrupt request register. This register contains current status of Slave
interrupt sources.
Parameters:
None
Return Value:
Description
SCB_INTR_SLAVE_I2C_ARB_LOST
SCB_INTR_SLAVE_I2C_NACK
SCB_INTR_SLAVE_I2C_ACK
SCB_INTR_SLAVE_I2C_WRITE_STOP
SCB_INTR_SLAVE_I2C_STOP
SCB_INTR_SLAVE_I2C_START
Side Effects:
SCB_INTR_SLAVE_I2C_GENERAL
SCB_INTR_SLAVE_I2C_BUS_ERROR
SCB_INTR_SLAVE_SPI_BUS_ERROR
None
Writes Slave interrupt mask register. This register configures which bits from Slave
interrupt request register will trigger an interrupt event.
Parameters:
Return Value:
None
Side Effects:
None
uint32 SCB_GetSlaveInterruptMode(void)
Description:
Returns Slave interrupt mask register This register specifies which bits from Slave
interrupt request register will trigger an interrupt event.
Parameters:
None
Return Value:
Side Effects:
None
uint32 SCB_GetSlaveInterruptSourceMasked(void)
Description:
Returns Slave interrupt masked request register. This register contains logical AND of
corresponding bits from Slave interrupt request and mask registers.
This function is intended to be used in the interrupt service routine to identify which of
enabled Slave interrupt sources cause interrupt event.
Parameters:
None
Return Value:
Side Effects:
None
Parameters:
Return Value:
None
Side Effects:
None
Parameters:
uint32 interruptMask: Slave interrupt sources to set in the Slave interrupt request
register (refer to SCB_GetSlaveInterruptSource() function for return values).
Return Value:
None
Side Effects:
None
I2C
EZI2C
SPI
UART
SCB_EnableInt()
SCB_DisableInt()
SCB_GetInterruptCause()
SCB_SetCustomInterruptHandler() [11]
+/-
+/-
SCB_SetI2cAddressCustomInterruptHandler()
SCB_GetTxInterruptSource()
SCB_SetTxInterruptMode()
SCB_GetTxInterruptMode()
SCB_GetTxInterruptSourceMasked()
SCB_ClearTxInterruptSource()
SCB_SetTxInterrupt()
SCB_SetTxFifoLevel()
SCB_GetRxInterruptSource()
SCB_SetRxInterruptMode()
SCB_GetRxInterruptMode()
SCB_GetRxInterruptSourceMasked()
SCB_ClearRxInterruptSource()
SCB_SetRxInterrupt()
SCB_SetRxFifoLevel()
SCB_GetMasterInterruptSource()
SCB_SetMasterInterruptMode()
SCB_GetMasterInterruptMode()
SCB_GetMasterInterruptSourceMasked()
SCB_ClearMasterInterruptSource()
SCB_SetMasterInterrupt()
SCB_GetSlaveInterruptSource()
SCB_SetSlaveInterruptMode()
SCB_GetSlaveInterruptMode()
11
- Only available when SPI and UART provide internal interrupt handler.
Function
I2C
EZI2C
SPI
UART
SCB_GetSlaveInterruptSourceMasked()
SCB_ClearSlaveInterruptSource()
SCB_SetSlaveInterrupt()
Clock Selection
The SCB is clocked by a single dedicated clock connection. Depending on the mode of
operation the frequency of this clock may be calculated by the component based on the
customizer configuration or may be provided externally.
Since the Unconfigured mode customizer is not aware of the end mode of operation the clock
must be provided externally in this case.
MISRA Compliance
This section describes the MISRA-C:2004 compliance and deviations for the component. There
are two types of deviations defined:
project deviations deviations that are applicable for all PSoC Creator components
specific deviations deviations that are applicable only for this component
Rule Class
[12]
Rule Description
This rule states that
code shall conform to
C ISO/IEC
9899:1990 standard.
Description of Deviation(s)
Nesting of control structures (statements) exceeds 15 program does not conform strictly to ISO:C90.
In practice, most compilers will support a much more liberal
nesting limit and therefore this limit may only be relevant
when strict conformance is required. By comparison,
ISO:C99 specifies a limit of 127 "nesting levels of blocks.
The supported compilers (GCC 4.1.1, RVDS and MDK)
support larger number nesting of control structures.
12
Required / Advisory
MISRA-C:
2004 Rule
Rule Class
[12]
Rule Description
Description of Deviation(s)
17.4
19.7
A function should be Deviated since function-like macros are used to allow more
used in preference to efficient code.
a function-like macro.
This component has the following embedded components: Pins and Interrupt. Refer to the
corresponding component datasheets for information on their MISRA compliance and specific
deviations.
void main()
{
/* Register custom function */
SCB_SetCustomInterruptHandler(&CustomInterruptHandler);
/* Initialize SCB component in UART mode.
* The SCB_INTR_RX_PARITY_ERROR is already enabled in GUI:
* UART Advanced Tab.
*/
SCB_Start();
CyGlobalIntEnable; /* Enable global interrupts. */
for (;;)
{
/* Place your application code here. */
}
}
/* User interrupt handler to insert into SCB interrupt handler.
* Note: SCB interrupt set to Internal in GUI.
*/
void CustomInterruptHandler(void)
{
if (0u != (SCB_GetRxInterruptSourceMasked() & SCB_INTR_RX_PARITY_ERROR))
{
/* Interrupt sources does not clear automatically if it is managed by
* user. The interrupt sources clearing becomes user responsibility.
*/
SCB_ClearRxInterruptSource(SCB_INTR_RX_PARITY_ERROR);
/*
* Add user interrupt code to manage SCB_INTR_RX_PARITY_ERROR.
*/
}
}
TX FIFO empty
TX FIFO not full
TX FIFO level
These interrupt sources trigger the current status of the TX FIFO, and keep it until a clear
operation. Clearing these interrupt sources does not make any sense if the current status of the
TX FIFO still triggers them, because they are restored back.
The restore operation takes one clock cycle; therefore, the interrupt source is cleared during this
time. The restore time causes false clearing of interrupt sources, which might have an undesired
impact on the design.
These interrupt sources trigger the current status of the RX FIFO, and keep it until a clear
operation. Clearing these interrupt sources does not make any sense if the current status of the
RX FIFO still triggers them, because they are restored back. The restore operation takes one
clock cycle; therefore, the interrupt source is cleared during this time.
The restore time causes false clearing of RX interrupt sources, which might have an undesired
impact on the design.
The suggested flow to start RX FIFO interrupt sources processing is as follows:
1. Clear the old triggered interrupt source. To clear interrupt source, write 1 to the
corresponding bit position.
2. Then enable the interrupt source.
In most cases the clear operation is not required. While getting data from the RX FIFO, it is
better to monitor the number of entries in it rather than try to clear the RX FIFO interrupt source
after each byte read from the RX FIFO.
Note The RX FIFO level interrupt source behavior depends on level value.
Note The described behavior applies only to PSoC 4100/PSoC 4200 devices. After the SCB
component is disabled, the triggered RX FIFO interrupt sources are not cleared automatically.
The explicit clear operation must be executed.
Placement
The SCB is placed as Fixed Function block and all placement information is provided to the API
through the cyfitter.h file. The SCB pins placement information is available in the Pins tab of the
PSoC Creator Design-Wide Resources (DWR) file. See the Device datasheet section Pinout for
pins functions and placement information.
Generally, debug pins have an alternate function to be SCB pins. To use these pins for SCB
functionality, debug capability needs to be disabled in the System tab of the PSoC Creator DWR
file. Set Debug Select option to GPIO to allow the tool to use the alternate function.
Note The debugger will not be functional after choosing this option.
This is specifically important for PSoC 4000 devices, which have a limited number of pins. The
debug pins for this device are P3[0] (SWD_IO) and P3[1] (SWD_CLK). The alternate function of
these pins is I2C functionality SCB[0] (SDA) and SCB[0] (SCL). For other devices, refer to the
appropriate device datasheet to determine alternate functions of debug pins.
Registers
See the chip Technical Reference Manual (TRM) for more information about registers.
Resources
The SCB is implemented as a fixed-function block.
Resource Type
Configuration
Interrupts
Clocks
SCB
(Fixed blocks)
Unconfigured SCB
I2C
EZ I2C
SPI
Master / Slave
UART
PSoC 4 (GCC)
PSoC 4000
PSoC 4100 /
PSoC 4200
Flash
RAM
Flash
RAM
Flash
RAM
Unconfigured SCB
7460
158
11134
175
12074
175
I2C
Slave
1616
43
1668
43
1564
43
Master
2560
46
2792
46
2564
46
Multi-Master
2560
46
2792
46
2564
46
13
Hardware buffers The TX and RX buffer size is equal to FIFO depth which is implemented in the hardware; no
memory is allocated for the TX or RX buffer. The RX and TX FIFO depth is equal to 8 bytes/words or 16 bytes;
refer to Byte mode for more information.
14
Software buffers The TX and RX buffer size is greater than FIFO depth; the TX and RX FIFOs are still used but
the memory is allocated for TX and RX buffer. Internal interrupt handler is automatically enabled to transfer data
between the hardware FIFOs and RX and TX memory buffers.
Configuration
PSoC 4 (GCC)
PSoC 4000
EZI2C
SPI
Flash
RAM
Flash
RAM
Flash
RAM
Multi-Master-Slave
3872
79
4092
79
3816
79
1692
174
1744
174
1640
174
Clock stretching
enabled
One address
1316
26
1352
26
1264
26
Two addresses
1688
50
1760
50
1632
50
Clock stretching
disabled [15]
One address
1256
23
1032
24
1208
23
Slave
N/A
N/A
586
626
N/A
N/A
1014
23 + BUFRAM
1054
23 + BUFRAM
N/A
N/A
1194
23 + BUFRAM
1194
23 + BUFRAM
N/A
N/A
766
814
N/A
N/A
1190
23 + BUFRAM
1238
23 + BUFRAM
N/A
N/A
732
948
N/A
N/A
1220
23 + BUFRAM
1468
23 + BUFRAM
N/A
N/A
1130
23 + BUFRAM
1138
23 + BUFRAM
UART
PSoC 4100 /
PSoC 4200
Standard [17]
Hardware buffers
Software buffers
[16]
[13]
[14]
Bootloader communication
[16]
RX buffer size and TX buffer size is equal to appropriate settings on the Advanced Tab for
SPI or UART mode.
BytesNumberRX is number of bytes to store the RX data element. The BytesNumberRX = 1
when RX data bits <= 8 bits and BytesNumberRX = 2 when RX data bits > 8 bits.
BytesNumberTX is number of bytes to store the TX data element. The BytesNumberTX = 1
when TX data bits <= 8 bits and BytesNumberTX = 2 when RX data bits > 8 bits.
Note For UART mode the TX and RX data bits options are combined into the single
option Data bits which value must be used for BUFRAM calculations instead of
BytesNumberRX and BytesNumberTX.
15
The Enable wakeup from Deep Sleep Mode is enabled for all devices other than PSoC 4100/PSoC 4200.
16
17
The hardware flow control feature is enabled for devices other than PSoC 4100/PSoC 4200.
Description
Min
Typ
Max
Units
II2C1
10.5
II2C2
135
II2C4
2.5
Min
Typ
Max
Units
400
Kbps
Description
Min
Typ
Max
Units
II2C1
10.5
II2C2
135
II2C3
310
II2C4
1.4
Min
Typ
Max
Units
Mbps
Conditions
I2C AC Specifications
Parameter
FI2C1
Description
Bit rate
Conditions
Conditions
I2C AC Specifications
Parameter
FI2C1
Description
Bit rate
Conditions
UART DC Specifications
Parameter
Description
Min
Typ
Max
Units
IUART1
IUART2
312
Min
Typ
Max
Units
Mbps
Min
Typ
Max
Units
Conditions
UART AC Specifications
Parameter
FUART
Description
Bit rate
Conditions
SPI DC Specifications
Parameter
Description
ISPI1
360
ISPI2
560
ISPI3
600
Min
Typ
Max
Units
MHz
Min
Typ
Max
Units
Conditions
SPI AC Specifications
Parameter
FSPI
Description
SPI operating frequency (master; 6X
oversampling)
Conditions
Description
TDMO
15
ns
TDSI
20
ns
THMO
ns
Conditions
Description
Min
Typ
Max
Units
TDMI
40
ns
TDSO
42 + 3 Tscb
ns
THSO
ns
TSSELSCK
100
ns
Conditions
Description
Min
Typ
Max
Units
II2C1
50
II2C2
155
II2C3
390
II2C4
1.4
Min
Typ
Max
Units
Mbps
Conditions
I2C AC Specifications
Parameter
FI2C1
Description
Bit rate
Conditions
UART DC Specifications
Parameter
Description
Min
Typ
Max
Units
IUART1
55
IUART2
312
Min
Typ
Max
Units
Conditions
UART AC Specifications
Parameter
FUART
Description
Bit rate
Conditions
Mbps
SPI DC Specifications
Parameter
Description
Min
Typ
Max
Units
Conditions
ISPI1
360
ISPI2
560
ISPI3
600
Min
Typ
Max
Units
MHz
Min
Typ
Max
Units
SPI AC Specifications
Parameter
FSPI
Description
SPI operating frequency (master; 6X
oversampling)
Conditions
Description
TDMO
18
ns
TDSI
20
ns
THMO
ns
Conditions
Description
Min
Typ
Max
Units
TDMI
40
ns
TDSO
42 + 3 Tscb
ns
THSO
ns
TSSELSCK
100
ns
Conditions
Description
Min
Typ
Max
Units
II2C1
50
II2C2
135
II2C3
310
II2C4
1.4
Min
Typ
Max
Units
Mbps
Conditions
I2C AC Specifications
Parameter
FI2C1
Description
Bit rate
Conditions
UART DC Specifications
Parameter
Description
Min
Typ
Max
Units
IUART1
55
IUART2
312
Min
Typ
Max
Units
Mbps
Min
Typ
Max
Units
Conditions
UART AC Specifications
Parameter
FUART
Description
Bit rate
Conditions
SPI DC Specifications
Parameter
Description
ISPI1
360
ISPI2
560
ISPI3
600
Conditions
SPI AC Specifications
Parameter
FSPI
Description
Min
Typ
Max
Units
MHz
Min
Typ
Max
Units
Conditions
Description
TDMO
15
ns
TDSI
20
ns
THMO
ns
Conditions
Description
Min
Typ
Max
Units
TDMI
40
ns
TDSO
42 + 3 Tscb
ns
TDSO_ext
48
ns
ns
100
ns
Conditions
Clock mode
THSO
TSSELSCK
Component Errata
This section lists known problems with the component.
Cypress
ID
215863
Component
Version
2.0, 3.0
Problem
When operating in UART mode, the Configure dialog
does not disable the RX FIFO not empty interrupt
source when the RX buffer size is equal to 16 data
elements and the Byte mode parameter is enabled.
Workaround
Disable the RX FIFO not
empty interrupt source on
the UART Configure
dialogs Advanced tab.
Component Changes
This section lists the major changes in the component from the previous version.
Version
Description of Changes
3.10
3.0.b
Datasheet update.
3.0.a
3.0
Version
Description of Changes
2.0.a
Datasheet updates.
2.0
Version
Description of Changes
Removed Median filter option from the I2C and EZ The analog filters applied to I2C lines for most
I2C modes. The median filter option is set depends data rate modes. There is no reason to apply both
on the selected data rate.
filters: analog and median (digital). For I2C master
modes with data rate greater than 400 kbps (Fast
Plus) only median (digital) filter is applied.
If Unconfigured SCB was utilized with previous
version of the component and configured to I2C
mode the dataRate field of configuration structure
has to be initialized for correct filter selection.
The SCB_Sleep() and SCB_Wakeup() functions
were modified for I2C and EZI2C slave (clock
stretching enabled) modes for PSoC 4000. For
more information refer to Low power modes
section of the appropriate mode.
Fixed the I2C master operation in the Multi-Master- The master was not able to able to start
Slave mode when Enable wakeup from Deep
communication.
Sleep Mode option is enabled for PSoC 4000.
Added APIs to set level in the RX and TX FIFO to
generate appropriate level interrupt:
void SCB_SetRxFifoLevel(uint32 level)
void SCB_SetTxFifoLevel(uint32 level)
Removed SPI Master slave select routing
constrains.
SCB_SpiIsBusBusy()
Version
Description of Changes
Add protection from the component interruption to
the following APIs:
SCB_I2CSlaveInitReadBuf()
SCB_I2CSlaveInitWriteBuf()
SCB_I2CSlaveClearReadStatus()
SCB_I2CSlaveClearWriteStatus()
SCB_I2CMasterClearStatus()
SCB_I2CMasterStatus()
SCB_I2CMasterClearWriteBuf()
SCB_I2CMasterClearReadBuf()
SCB_EzI2CSetBuffer1()
SCB_EzI2CSetBuffer2()
1.20
1.0.a
1.0
Cypress Semiconductor Corporation, 2015. 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 lifesupport systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges.
PSoC is a registered trademark, and PSoC Creator and Programmable System-on-Chip are trademarks of Cypress Semiconductor Corp. All other trademarks or registered trademarks
referenced herein are property of the respective corporations.
Any 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 lifesupport 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.