You are here

PSoC 1 GPIO Demystified - Part 1 | Cypress Semiconductor

PSoC 1 GPIO Demystified - Part 1

GPIOs play an important role in creating a bridge between the internals of a microcontroller to the external world.  Let us take a look at the important features of PSoC 1 GPIO and application scenarios.  Because of the large amount of information to be covered, I have split this into a two part series.

Part-1 is about various features of the GPIO like the Drive modes, GPIO registers, Interrupts and the PSoC Designer interface to configure the GPIO.  This is mostly boring stuff from the Technical Reference Manual. If you would like to get to the interesting stuff, skip to Part-2 which covers application scenarios like writing to a GPIO, reading from a GPIO, Read Modify Write Instructions and writing a GPIO ISR.

DRIVE MODES

PSoC1 GPIO pins can be configured into one of 8 drive modes.




#

Drive Mode

HIGH

LOW

Comments

1

Pull down

Strong

Resistive

Input / Output

2

Strong

Strong

Strong

Output

3

High Impedance

HighZ

HighZ

Input (Schmitt Trigger enabled)

4

Pull Up

Resistive

Strong

Input / Output

5

Open Drain High

Strong

HighZ

Input / Output

6

Slow Strong

Strong Slow

Strong Slow

Output (Slope controlled)

7

High Impedance Analog

HighZ

HighZ

Analog Input / Output

8

Open Drain Low

HighZ

Strong Slow

Input / Output, I2C




Strong and Slow Strong are used as outputs.  The Slow strong mode introduces a slew rate control on the pin that increases the slope on the rising and falling edges of the pins thus reducing EMI and RFI radiations.

HighZ mode is used as input for both analog and digital signals and also for analog output.  HighZ Analog mode is used for Analog input and output.  Remember, in the HighZ Analog mode, the Schmitt trigger circuit on the digital input path is disabled and hence the pin cannot be used to read digital signals nor will it generate interrupts.

Pull Up, Pull Down, Open Drain High, and Open Drain Low can be used as Input as well as Output.  An exception is when a pin is connected to the Global Input bus to route the signal to a digital block.  When a pin is connected to the Global Input bus, it cannot be configured in Pull up or Pull down modes.

REGISTERS

The GPIO pins are controlled by various registers.

Data Register: The state of a GPIO can be controlled / read by writing / reading the PRTxDR register.  For example to make P1[5] HIGH, Bit5 of PRT1DR should be set.  More about writing and reading GPIO pins in Part-2.

Drive Mode Registers:  There are three drive mode registers for each port that control the drive mode of the pins in a particular port.  These are the PRTxDM0, PRTxDM1 and PRTxDM2 registers. The combination of the bits of these three registers decide the drive mode of a particular pin.  For example, the drive mode of P2[3] will be decided the combination of Bit3 of PRT2DM0, PRT2DM1 and PRT2DM2 registers.  Details can be found in the Technical Reference Manual.

Global Select register: The PRTxGS register decides if a GPIO pin is under the control of the CPU or is connected to the Global In or Global Out bus.  When the bit in PRTxGS register is cleared, the pin can be controlled by the CPU by writing to the PRTxDR register.  When the bit in PRTxGS register is set, the pin is connected to the Global bus and connects to the internal hardware blocks.

Interrupt Control Registers: PRTxIE, PRTxIC0 and PRTxIC1 are registers that control the interrupt mode of a GPIO pin.

INTERRUPTS

Each GPIO pin may be configured to generate an interrupt on Rising Edge, Falling Edge or a Change from Read event.  The interrupt behavior of GPIO pins are controlled by the following registers.

PRTxIE Register: This register enables or disables the interrupt for a particular GPIO pin.  For example, if the interrupt has to be enabled on P1[5], Bit5 of PRT1IE register has to be set.  When the interrupt type is selected in the GPIO configuration pane in the PSoC Designer device editor, the designer automatically sets the PRTxIE register in the boot up code.

PRTxIC0 and PRTxIC1 Registers: These two registers are used in combination to choose between four options of interrupt type for each pin – Disabled, Rising Edge, Falling Edge and Change from Read.  Following are the bit combinations of PRTxIC0 and PRTxIC1 registers.  For example to configure P2[1] as a Rising Edge interrupt, Bit1 of PRT2IC0 should be cleared and Bit1 of PRT2IC1 should be set.  When the interrupt type is selected in the GPIO configuration pane in the PSoC Designer device editor, the designer automatically sets the PRTxIC0 and PRTxIC1 registers accordingly in the boot up code.

When the pin is configured for a Change From Read interrupt, an interrupt is generated whenever the state of the pin changes from the state that was read from the pin.  So, to generate an interrupt from both rising and falling edges, whenever an interrupt is generated from the pin, a read operation should be performed on the PRTxDR register.  Even if there is no requirement for such a read, a dummy read operation has to be performed for the interrupt to work.

INT_MSK0 Register:  Bit5 in the INT_MSK0 bit is the Mask bit for GPIO interrupt.  Only when this bit is set, the interrupts raised by GPIO pins will be processed by the CPU.  The device editor does not take care of setting this bit.  This bit has to be set in the firmware.

Notes:

  • Remember to enable the Global interrupts for the GPIO interrupt (or any other interrupts) to work.
  • If the drive mode is set to “HighZ Analog”, interrupt will not work.

PSOC DESIGNER – CONFIGURING A GPIO

All the GPIO pins can be configured using the GPIO configuration window in the PSoC Designer device editor.

 

Name: Giving meaningful names to the GPIO pins will make the project more readable.  For example, LED, SPI_MOSI, SPI_MISO, UART_TX etc.  Giving names to the GPIO also will be useful in controlling the pins using the register definitions in the psocgpioint.h file.  More about this later.

Select: This parameter selects the mode of the pin like Analog Input, Global Input, Global Output etc.  On specific pins, special functions like XTAL_IN, XTAL_OUT, I2C_SCL, I2C_SDA etc also will be available.  When the type of pin is selected, the drive mode will be automatically be set.

Drive:  This parameter selects one of 8 drive modes for the pin.  Though the drive mode will be automatically set according to the pin type selected in the previous parameter, it can be overridden.

Interrupt: This parameters sets the interrupt type of the pin

Continued in Part-2...

Comments

timgclark's picture

The drive modes are shown numbered from 1 to 8; presumably you really mean 0 to 7, corresponding to the values of (DM2,DM1,DM0) bits? That is (DM2,DM1,DM0) = (0,0,0), (0,0,1),...,(1,1,1) correspond to the numbers 1,2,...,8 in your table?

graa's picture

Yes. You are correct. The drive modes correspond to the DM2:DM1:DM0 combinations 000 to 111. The numbers in the table are just serial numbers. Regards, Ganesh

sweil's picture

I'm trying to configure a simple digital input pin in a CY8C20236A using PSoC Designer 5.4
According to this table, I want Row #3 (High Impedance, HighZ, HighZ, Input (Schmitt Trigger enabled).

However, I don't know how to map this to the options in designer, where the choices are:

Select (AnalogMUXInput, Default, StdCPU, or StdCPUInput)
Drive (High Z Analog, Open Drain Low, Pull Up, or Strong)
AnalogMUXBus (AnalogMUXBus or Normal)

I can't find these options documented in the datasheet.

jordanss123 jordanss123's picture

Thanks for you share great topic with us. fake yeezy boost 350

 

taylorshaw151_2687531's picture

The site has been providing a lot of such interesting topics regarding PSOC 6 early adopter program. The codes offered here are very helpful in making the project all by myself. The detailed instructions along with the codes come pretty handy to clear any doubts while doing it. My Paris Tours

ALL CONTENT AND MATERIALS ON THIS SITE ARE PROVIDED "AS IS". CYPRESS SEMICONDUCTOR AND ITS RESPECTIVE SUPPLIERS MAKE NO REPRESENTATIONS ABOUT THE SUITABILITY OF THESE MATERIALS FOR ANY PURPOSE AND DISCLAIM ALL WARRANTIES AND CONDITIONS WITH REGARD TO THESE MATERIALS, INCLUDING BUT NOT LIMITED TO, ALL IMPLIED WARRANTIES AND CONDITIONS OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT OF ANY THIRD PARTY INTELLECTUAL PROPERTY RIGHT. NO LICENSE, EITHER EXPRESS OR IMPLIED, BY ESTOPPEL OR OTHERWISE, IS GRANTED BY CYPRESS SEMICONDUCTOR. USE OF THE INFORMATION ON THIS SITE MAY REQUIRE A LICENSE FROM A THIRD PARTY, OR A LICENSE FROM CYPRESS SEMICONDUCTOR.

Content on this site may contain or be subject to specific guidelines or limitations on use. All postings and use of the content on this site are subject to the Terms and Conditions of the site; third parties using this content agree to abide by any limitations or guidelines and to comply with the Terms and Conditions of this site. Cypress Semiconductor and its suppliers reserve the right to make corrections, deletions, modifications, enhancements, improvements and other changes to the content and materials, its products, programs and services at any time or to move or discontinue any content, products, programs, or services without notice.