Time-Sharing a PSoC® 4 Serial Communication Block (SCB) Between Two Functions – KBA90605

Version: **

 

Question: Can an SCB in a PSoC® 4 device be time-shared between two communication functions, such as an I2C master and a UART Tx? How do you implement this?

 

Answer:

Yes, an SCB in a PSoC 4 device can be time-shared between two communication functions. PSoC Creator™ gives an unconfigured SCB as a standard Component and generates all the APIs required to configure the block for the required function.

One nice feature of an SCB is that, although it is unconfigured, it can store one set of configuration values for all the communication functions (I2C, SPI, and UART). The user only has to enable the required communication function in the code, when required, and change only the parameters that need to be changed.

The steps below show how to configure an SCB as an I2C master and as a UART Tx communication block and multiplex between these two functions.

  1.   Drag the SCB Component to the TopDesign, and then attach a clock Component.  

       Figure 1. SCB Component

     

       SCB component

  2.   Double-click the Component and configure the I2C parameters as required. Click Apply to save the configuration (Figures 2–3). Repeat these steps for the UART (Figures 4–5).  

       Figure 2. Selecting the I2C Protocol

     

       I2C protocol

     

       Figure 3. Setting the I2C Parameters

     

       I2C parameters

     

       Figure 4. Selecting the UART Protocol

     

       UART protocol

     

       Figure 5. Setting the UART Parameters

     

       UART parameters

  3.   Enable the I2C function, when needed, using the code below. Note that the I2C parameters are already set in the Component Configuration. These values are stored in a constant structure. Here, after calling the I2CInit function, these values are loaded into the I2C registers of the SCB.  

       SCB_1_Stop(); // Stop the SCB block

     

       Clock_1_SetDivider(15); // Set the clock as required by the communication function

     

       SCB_1_I2CInit(&SCB_1_configI2C); // Initiate the function

     

       SCB_1_Start(); // Enable the SCB block

  4.   Enable the UART function, when needed, using the code below.  

       SCB_1_Stop(); // Stop the SCB block

     

       Clock_1_SetDivider(52); // Set the clock as required by the communication function

     

       SCB_1_UartInit(&SCB_1_configUart); // Initiate the function

     

       SCB_1_Start(); // Enable the SCB block

  5.   To time-share an SCB, call the above two code blocks using conditions as required by the application code.
  6.   Note that the SCB uses the same pin for different communication functions. For example, the SCB 0 block uses pin P4[1] as the I2C-SDA, UART-Tx, and SPI-MISO. If the SCB is time-shared between the I2C and the UART, then you should use the proper mechanism to enable pull-up resistors for I2C operation and disable the same for UART operation. This can be done using an extra GPIO to enable and disable pull-up resistors (Figure 6).  

       Figure 6. I2C Pull-Up Resistors

     

       pull-up resistors