Cypress Perform

Home > Design Support > Cypress Developer CommunityTM > Cypress Forums > PSoC® 3 > Read data from input pin

Bookmark and Share
Cypress Developer CommunityTM
Forums | Videos | Blogs | Training | Rewards Program | Community Components



Read data from input pin
Moderator:
RKRM

Post Reply
Follow this topic



Read data from input pin

blueblood posted on 25 Nov 2011 9:48 AM PST
Member
10 Forum Posts

Hello !! I am beginner in psoc. i am having a simple problem that i want to assign any pin as a input and when the input to that particular pin is given logic high then it should perform the desired looping operation. Plz help abt how to keep tht pin as input and how to read data from it..




Re: Read data from input pin

Bob Marlowe posted on 25 Nov 2011 09:54 AM PST
Top Contributor
1768 Forum Posts

Hi,

first download and install PSoC Creator software.

Then drop an Input Pin component on the schematic and adjust the number of pins you like to experiment with.

In your main() program you read the pins with

uint8 Values;
Values = PinName_Read()

Happy coding

Bob

 



Re: Read data from input pin

blueblood posted on 25 Nov 2011 09:58 AM PST
Member
10 Forum Posts

thnx for quick reply.. :) but if i want to use p1[7] as input pin then how should i go forward with it ?? tht means how to initialise it and how to get data from it ??



Re: Read data from input pin

Gautam Das posted on 25 Nov 2011 10:36 AM PST
Cypress Employee
742 Forum Posts

Hi blueblood,

 

You can drag and place a Digital Input Pin component from the component catalog onto the schematic.

You can double click on the component to open the Configuration Window where you can select its Drive Mode (if you want to alter).

The schematic will look like this

 



Re: Read data from input pin

Gautam Das posted on 25 Nov 2011 10:42 AM PST
Cypress Employee
742 Forum Posts

Once you save the project, open the .cydwr file from the Workspace Explorer.

In the Pins tab select the Port Pin to which you want to assign this pin (in this case it's P1[7]).

 

 

Once you select the required pin, you can build the project. APIs will be generated for this Pin.



Re: Read data from input pin

Gautam Das posted on 25 Nov 2011 10:48 AM PST
Cypress Employee
742 Forum Posts

As Bob Marlowe has already mentioned, the Pin value can be ready by simply using the API <PinName>_Read( ) in the main.

The default Drive Mode of Digital Input Pin is High Impedance Digital. However, you can select other drive modes, if the situation demands, to Resistive Pull-up, Resistive Pull-down, etc.

 



Re: Read data from input pin

blueblood posted on 25 Nov 2011 08:04 PM PST
Member
10 Forum Posts

thnx all.. i made following connections as mentioned above.. but it is giving errors.. i have attached the screenshot for verification.. have i done wrong intialization ??



Re: Read data from input pin

H L posted on 25 Nov 2011 08:26 PM PST
Top Contributor
679 Forum Posts

 You should put the line 

uint8 Values;

at the bdginning  of you function before any opertions. EG

void main (void)

{

/* all variable declare first */

uint8 a;

uint16 b;

...

 

/* Then  the c program here */

..

..

 

 

}

 

 



Re: Read data from input pin

H L posted on 25 Nov 2011 08:28 PM PST
Top Contributor
679 Forum Posts

  You should put the line 

uint8 Values;

at the bdginning  of you function before any opertions. EG

void main (void)

{

/* all variable declare first */

uint8 a;

uint16 b;

uint8 Values;

...

 

/* Then  the c program here */

..

..

pga_start();

values = PIN_2_Read();

...

 

 

}



Re: Read data from input pin

Gautam Das posted on 26 Nov 2011 12:46 AM PST
Cypress Employee
742 Forum Posts

Yes, as lleung has already mentioned, declare all the variables used in the code before calling the component APIs.

Rearranging the declarations should eliminate the error.



Re: Read data from input pin

blueblood posted on 26 Nov 2011 01:19 AM PST
Member
10 Forum Posts

thank you everyone for the help.. :) the method worked !! i also found other technique of using "CyPins_ReadPin(Pin_2_0)" which simply does the reading of the port pin without initialization..



Re: Read data from input pin

Bob Marlowe posted on 26 Nov 2011 01:19 AM PST
Top Contributor
1768 Forum Posts

http://publications.gbdirect.co.uk/c_book/ is a pretty good C-Syntax description.

C is not easy or simple, there are lots(!!!) of pitfalls and misunderstandings you will experience, so don't get frustrated.

Happy coding

Bob



Re: Read data from input pin

Bob Marlowe posted on 26 Nov 2011 01:39 AM PST
Top Contributor
1768 Forum Posts

I am a professional programmer (for about 40 years now) and I would like to put you on the right track.

The main goal for a good program is not "It Works!". If it doesn't work, its not a program at all, a piece of wood doesn't work eather.

So what are the kriteria for a "good" program?

Here are some of mine:

Cheap - Programmed and tested in a short time

Cheap - Re-usable code from former projects

Cheap - Flexible programming adopts easily to different hardware

Cheap - Make the program human readable as much as possible

You can add yours here...

 

Reading directly in your program from a specific pin violates some of the above kriteria, saving the initialization part has the downgrade that there IS NO initialization part. HAVING an initialization part makes it easy to pre-check some external situations before the program really runs (or deny the running with an error-message.

All my PSoC-programs have the following structure which make it easy to look up, control or change the appropiate part:

Title of the Program, date, version and what it should perform

#includes

#defines

Global Variables (but only a few!)

void InitializeHardvare(void

{

   Yes, exactly that, nomen est omen...

}

void main(void)

{

 InitializeHardware();

Here goes the initialization of the software

while(forever) // #define forever 1 helps readability

{

The main task, normally calling some functions defined in other files

}

// NO FINALIZATION, forever is forever, this code will never be reached

 

Happy coding

Bob

 

 



Re: Read data from input pin

Bob Marlowe posted on 26 Nov 2011 01:41 AM PST
Top Contributor
1768 Forum Posts

Ooops, forgot a ")" here are some spare, insert where requred "(())){{{}}}[[]];;;"

Bob



Re: Read data from input pin

blueblood posted on 27 Nov 2011 10:35 PM PST
Member
10 Forum Posts

thanx bob for the suggestions !! it was my first experience with psoc.. i must say it is great piece of software.. very easy to use !! Just one simple query that i have made my sub modules individually.. tht means in different projects.. but when i combine them, one of the sub modules doesn't work.. any idea why this is happening ??



Re: Read data from input pin

U2 posted on 27 Nov 2011 09:37 PM PST
Cypress Employee
589 Forum Posts

Interesting conversation. Blueblood, could you tell us what submodules are you referring to ? Do you mean different projects or C funtions to do smaller tasks ?






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.

Spec No: None; Sunset Owner: KXP; Secondary Owner: VWA; Sunset Date: 01/01/20