AN2094 - PSoC® 1 GPIO Pin-Port Reconfiguration
AN2094 - PSoC® 1 GPIO Pin-Port Reconfiguration
AN2094 - PSoC® 1 GPIO Pin-Port Reconfiguration
AN2094
Associated Project: Yes Associated Part Families: CY8C24x23A, CY8C24x94, CY8C21x34, CY8C20x34, CY8C21x23, CY8C27x43, CY8C28xxx, CY8C29x66, CY7C64215, CYWUSB6953 Software Version: PSoC Designer 5.1 SP1 Associated Application Notes: AN2033
Introduction
Input and output (I/O) pin configuration is performed using two methods. The first method is to define the configuration as part of the initialization in PSoC Designers Device Editor. The easiest way to configure the pins is if the pin configuration is fixed at all times. The second method is to use firmware to reconfigure a pin. Pin configuration may be changed at any time by using assembler or C code.
In the first field shown in Figure 1, Name, the name of the pin is shown. You can rename the pin to make its purpose more obvious. The Port field shows the physical mapping of the pin. This field is not editable. The Select field configures some of the special behaviors of pins: AnalogInput. Only Port 0 and Port 2 have additional analog input and analog output options. AnalogInput gets analog signals from the outside world and connects to the analog column input MUX or to PSoC blocks directly. For example, if you use an ADC, you must configure at least one of the pins as AnalogInput to get analog signals from the outside world. AnalogOutputBuf. Only Port 0 has additional analog output options. Default. The global bus is not connected and the drive strength is High Z Analog. StdCPU. Normal I/O through the port. This is controlled by the CPU. Global_IN, Global_OUT. Global inputs and outputs provide capability to route clock and data signals to the digital PSoC blocks. If you configure a pin as a Global_IN (input) or Global_OUT (output), then that pin can talk to the digital blocks. For example, if the Global_IN is selected, then this selection connects that particular pin to the Global_INPUT bus. This bus is then used as an input to the digital PSoC blocks. Apart from the previously mentioned pin types, there are pins that have special features, and are listed. For example, P1[0] and P1[1] have XtalOut and XtalIn, P1[4] has ExtSysClk, P1[5] and P1[7] have I2C_SDA and I2C_SCL, and so on.
AN2094
Pull-down. In this mode, HIGH output is driven strong, and LOW output is through an internal pull-down resistor of approximately 5.6K. This mode may be used as an input, for example with a switch connected to VCC. This mode may also be used as output. Pull-up. This mode is the opposite of the Pull-down mode. In this mode, HIGH output is driven strong and LOW output is through an internal pull-down resistor of approximately 5.6K. This mode may be used as an input, for example with a switch connected to GND. When used as input, the corresponding bit in the PRTxDR register must be set to enable the pull-up resistor. Once the pull-up resistor is enabled, the state of the pin is read using the PRTxDR register. This mode may also be used as output. Strong Slow. This mode is similar to the Strong mode, but the slope of the output is slightly controlled so that high harmonics are not present when the output switches. The Interrupt field in the Pinout window sets the interrupt type of the pins. Pins may have rising edge or falling edge interrupts, or both, or neither. The Initial Value field in the Pinout window sets the initial output value of the pin at startup. This value is imposed by populating the pins data register during the execution of automatically generated boot code, and can be overridden by the user at runtime.
AN2094
Note Port Drive Mode 0 Registers are 8 bits wide. All bits are Read or Write.
Port 0 Drive Mode 0 Register (PRT0DM0, Address = Bank 1, 00h) Port 1 Drive Mode 0 Register (PRT1DM0, Address = Bank 1, 04h) Port 2 Drive Mode 0 Register (PRT2DM0, Address = Bank 1, 08h) Port 3 Drive Mode 0 Register (PRT3DM0, Address = Bank 1, 0Ch) Port 4 Drive Mode 0 Register (PRT4DM0, Address = Bank 1, 10h) Port 5 Drive Mode 0 Register (PRT5DM0, Address = Bank 1, 14h) Port 6 Drive Mode 0 Register (PRT5DM0, Address = Bank 1, 18h) Port 7 Drive Mode 0 Register (PRT5DM0, Address = Bank 1, 1Ch) Table 2. Port m Drive Mode 1 Registers (PRTxDM1)
Control Pin # Bit Name Port_x_7 DM1[7] Port_x_6 DM1[6] Port_x_5 DM1[5] Port_x_4 DM1[4] Port_x_3 DM1[3] Port_x_2 DM1[2] Port_x_1 DM1[1] Port_x_0 DM1[0]
Note Port Drive Mode 1 Registers are 8-bits wide. All bits are Read or Write.
Port 0 Drive Mode 1 Register (PRT0DM1, Address = Bank 1, 01h) Port 1 Drive Mode 1 Register (PRT1DM1, Address = Bank 1, 05h) Port 2 Drive Mode 1 Register (PRT2DM1, Address = Bank 1, 09h) Port 3 Drive Mode 1 Register (PRT3DM1, Address = Bank 1, 0Dh) Port 4 Drive Mode 1 Register (PRT4DM1, Address = Bank 1, 11h) Port 5 Drive Mode 1 Register (PRT5DM1, Address = Bank 1, 15h) Port 6 Drive Mode 1 Register (PRT6DM1, Address = Bank 1, 19h) Port 7 Drive Mode 1 Register (PRT7DM1, Address = Bank 1, 1Dh) Table 3. Port m Drive Mode 2 Registers (PRTxDM2)
Control Pin # Port_x_7 Port_x_6 Port_x_5 Port_x_4 Port_x_3 DM2[3] Port_x_2 DM2[2] Port_x_1 DM2[1] Port_x_0 DM2[0]
Bit Name DM2[7] DM2[6] DM2[5] DM2[4] Note Port Drive Mode 2 Registers are 8-bits wide. All bits are Read or Write.
Port 0 Drive Mode 2 Register (PRT0DM2, Address = Bank 0, 03h) Port 1 Drive Mode 2 Register (PRT1DM2, Address = Bank 0, 07h) Port 2 Drive Mode 2 Register (PRT2DM2, Address = Bank 0, 0Bh) Port 3 Drive Mode 2 Register (PRT3DM2, Address = Bank 0, 0Fh) Port 4 Drive Mode 2 Register (PRT4DM2, Address = Bank 0, 13h) Port 5 Drive Mode 2 Register (PRT5DM2, Address = Bank 0, 17h) Port 6 Drive Mode 2 Register (PRT6DM2, Address = Bank 0, 1Bh) Port 7 Drive Mode 2 Register (PRT7DM2, Address = Bank 0, 1Fh) The Port x Drive Mode 0, Port x Drive Mode 1 and Port x Drive Mode 2 registers together control the I/O configuration of pins (ports) as shown in Figure 2. DM2[0] DM1[0] DM0[0] control pin 0 of port x DM2[1] DM1[1] DM0[1] control pin 1 of port x DM2[2] DM1[2] DM0[2] control pin 2 of port x
June 15, 2011
DM2[3] DM1[3] DM0[3] control pin 3 of port x DM2[4] DM1[4] DM0[4] control pin 4 of port x DM2[5] DM1[5] DM0[5] control pin 5 of port x DM2[6] DM1[6] DM0[6] control pin 6 of port x DM2[7] DM1[7] DM0[7] control pin 7 of port x
AN2094
For example, to configure Port_2_5 then you must write to the DM2[5], DM1[5] and DM0[5] bits of PORT 2 DRIVE MODE registers (PRT2DM2, PRT2DM1, PRT2DM0). For example, configure P2_0 to be a Strong drive. The following steps must be performed. From Figure 2 on page 3 find the DM2, DM1, DM0 values for Strong. (If you want a pin to be output, you may choose Strong. Do not choose High Z for digital outputs.) DM2 = 0 DM1 = 0 and DM0 = 1 for Strong drive. Use assembly or C instructions to set bit 5 of PRT2DM0 and clear bit 5 of PRT2DM1 and PRT2DM2 registers.
Port 6 Data Register (PRT6DR, Address = Bank 0, 18h) Port 7 Data Register (PRT7DR, Address = Bank 0, 1Ch)
To write to a particular port pin, use the corresponding mask and bitwise AND or OR operation. For example, to set and clear P3[4]:
Assembly Example
or reg[PRT3DR], 0x10 ; Set P3[4] and reg[PRT3DR], ~0x10 ; Clear P3[4]
C Example
PRT3DR |= 0x10; PRT3DR &= ~0x10; To read from a port pin, read the PRTxDR register and use the corresponding bit mask. For example, to check the status of P2[3]:
Assembly Example
M8C_SetBank1 or reg[PRT2DM0], 0x20 and reg[PRT2DM1], ~0x20 M8C_SetBank0 and reg[PRT2DM2], ~0x20 In the previous assembly example, the first line is a call to the M8C_SetBank1 macro, which switches the register bank to 1. This is done because PRT2DM0 and PRT2DM1 are in register bank 1. Then using the OR instruction and using a mask of 0x20, bit 5 of PRT2DM0 register is set. Then using AND instruction and a mask of inverse of 0x20, bit 5 of the PRT2DM1 register is cleared. Using M8C_SetBank0, it is switched back to register bank 0, and using the AND instruction and a mask of inverse of 0x20, bit 5 or the PRT2DM2 register is cleared. The OR and AND instructions are read, modify or write instructions. The content of the register is first read, a OR or AND operation is done on the value and then the result is written back to the same register. With this method, particular bits are modified without affecting the others.
Assembly Example
mov A, reg[PRT2DR] and A,0x08 jnz PinHigh ; Code to process Pin cleared state PinHigh: ; Code to process Pin set state C Example if (PRT2DR & 0x08) { // Code to process Pin Set state } Else { // Code to process Pin cleared state }
C Example
PRT2DM0 |= 0x20; PRT2DM1 &= ~0x20 PRT2DM2 &= ~0x20; In C, the code becomes much simpler. The switching of the banks is taken care of by the C compiler. The bitwise AND (&=) or the bitwise OR (|=) must be used with the corresponding masks on the registers.
AN2094
Example Projects
Example projects in assembly and C have been created to demonstrate the reconfiguration of pins. In this example, Port 1 is reconfigured. They are meant to be run on a CY3210-PSoC EVAL1 kit attached to a CY3215-DK PSoC1 debugger. Four LEDs are connected to Port 1 and the effects of the pin drive modes are observed by checking the status of the LEDs. The test setup is shown in Figure 3 and Figure 4. The project may be modified to operate on different hardware by changing the port registers that are modified to a different port. Figure 3. Picture of the Complete Test Setup
AN2094
AN2094
AN2094
Document History
Document Title: PSoC 1 GPIO Pin-Port Reconfiguration Document Number: 001-40480
Revision ECN Orig. of Change Submission Date Description of Change
** *A *B *C
Recatalogued application note. Associated Project files zipped with source document. Corrected Table 1. Drive Mode Configuration. (project files zipped with source files) Adapted example project to operate on CY3210-EVAL1 board. Updated firmware for PSoC Designer 5.1 SP1. General information and readability updates.
*D
3283657
MAXK
06/15/2011
In March of 2007, Cypress recataloged all of its Application Notes using a new documentation number and revision code. This new documentation number and revision code (001-xxxxx, beginning with rev. **), located in the footer of the document, will be used in all subsequent revisions. PSoC is a registered trademark of Cypress Semiconductor Corp. "Programmable System-on-Chip," PSoC Designer and PSoC Express are trademarks of Cypress Semiconductor Corp. All other trademarks or registered trademarks referenced herein are the property of their respective owners.
Cypress Semiconductor 198 Champion Court San Jose, CA 95134-1709 Phone: 408-943-2600 Fax: 408-943-4730 http://www.cypress.com/ Cypress Semiconductor Corporation, 2003-2011. The information contained herein is subject to change without notice. Cypress Semiconductor Corporation assumes no responsibility for the use of any circuitry other than circuitry embodied in a Cypress product. Nor does it convey or imply any license under patent or other rights. Cypress products are not warranted nor intended to be used for medical, life support, life saving, critical control or safety applications, unless pursuant to an express written agreement with Cypress. Furthermore, Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress products in life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. This Source Code (software and/or firmware) is owned by Cypress Semiconductor Corporation (Cypress) and is protected by and subject to worldwide patent protection (United States and foreign), United States copyright laws and international treaty provisions. Cypress hereby grants to licensee a personal, non-exclusive, non-transferable license to copy, use, modify, create derivative works of, and compile the Cypress Source Code and derivative works for the sole purpose of creating custom software and or firmware in support of licensee product to be used only in conjunction with a Cypress integrated circuit as specified in the applicable agreement. Any reproduction, modification, translation, compilation, or representation of this Source Code except as specified above is prohibited without the express written permission of Cypress. Disclaimer: CYPRESS MAKES NO WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, WITH REGARD TO THIS MATERIAL, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. Cypress reserves the right to make changes without further notice to the materials described herein. Cypress does not assume any liability arising out of the application or use of any product or circuit described herein. Cypress does not authorize its products for use as critical components in life-support systems where a malfunction or failure may reasonably be expected to result in significant injury to the user. The inclusion of Cypress product in a life-support systems application implies that the manufacturer assumes all risk of such use and in doing so indemnifies Cypress against all charges. Use may be limited by and subject to the applicable Cypress software license agreement.