Read data from input pin

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
Anonymous
Not applicable

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..

0 Likes
1 Solution
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Datasheet for PSoC4 tells: Ports 4 and larger cannot be used for routing, only for firmware control. Yes, reading and writing is the same for bidirectional pins.

   

 

   

Bob

View solution in original post

0 Likes
17 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
Anonymous
Not applicable

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 ??

0 Likes
Anonymous
Not applicable

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

0 Likes
Anonymous
Not applicable

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.

0 Likes
Anonymous
Not applicable

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.

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

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 ??

0 Likes
Anonymous
Not applicable

 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 */

   

..

   

..

   

 

   

 

   

}

0 Likes
Anonymous
Not applicable

  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();

   

...

   

 

   

 

   

}

0 Likes
Anonymous
Not applicable

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.

0 Likes
Anonymous
Not applicable

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..

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

   

Bob

0 Likes
Anonymous
Not applicable

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 ??

0 Likes
Anonymous
Not applicable

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 ?

0 Likes
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I am facing some problems in pin mapping , am not getting what exactly the problem .

   

please explain  briefly about this error and please let me know the solution. 

   

i am using these two pins as bidirectional , is it same way to  using API's(Read and Write functions used for output pin) for bidirectional pin also?

   

for more information about the pin mapping question , find the below image.

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Datasheet for PSoC4 tells: Ports 4 and larger cannot be used for routing, only for firmware control. Yes, reading and writing is the same for bidirectional pins.

   

 

   

Bob

0 Likes