Reading From an Output Pin

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

cross mob
ThBa_1159851
Level 3
Level 3
First like received First like given

In the hardware design (PSoC Creator 3.3, PSoC 4 Prototyping Kit) I use some digital components with external inputs to decide how to set a digital output with hardware connection outside the PSoC. This works quite good. Now I want to read this output and use the value in the c-program to display additional stuff on the LCD-Display. But I have no luck in getting a value from the output-pin.

   

I start with defining a variable...

   
int CutOffVariable = 1
   

and later I'm polling the digital output "Cut_Off" with...

   
CutOffVariable = Cut_Off_Read();
   

but the variable doesn't change although I measure that the the hardware pin has changed it's status.

   

I tried also with ...

   
CutOffVariable = Cut_Off_ReadDataReg()
   

but I had no luck,  probably don't understand the format of the returned value.

   

Any ideas how to solve this problem?
Cheers
Thomas

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

You are quite right with your estimation.

   

When you want to see which value you set the pin to, use Pin_ReadDataReg (). I do not know whether this API works when the pin was set by an internal signal (as your mentioned flip-flop), but I think you cannot read back the signal value.

   

 

   

Bob

View solution in original post

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

Can you please post your complete project or a reduced excerpt that shows the error, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is the manual on IO pins.

0 Likes
lock attach
Attachments are accessible only for community members.
rola_264706
Level 8
Level 8
50 likes received 25 likes received 10 likes received

Here is a small program.

0 Likes
lock attach
Attachments are accessible only for community members.
ThBa_1159851
Level 3
Level 3
First like received First like given

OK here's the project.
As I said, the output-pin "Cut-Off" changes and triggers an external electronic device. But how can I read the state of the "Cut-Off"-pin in the c-code? Line 103 doesn't change the value of the variable.

   

Thanks
Thomas

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

Quite easy: You just have to enable the "Digital Input" in the Cut_Off pin configuration.

   

 

   

Happy coding

   

Bob

0 Likes
ThBa_1159851
Level 3
Level 3
First like received First like given

Sounds easy, so I enabled the digital input of the Cut_Off pin, but when I code ...

   

CutOffVariable = Cut_Off_Read();

   

... the CutOffVariable is always 0, although the Cut_Off pin is connected to a LED that is changing its's status???

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

What digital value do you expect when an LED is connected to the pin? Even with a removed LED there will be no correct Hi-level.

   

Way out(s):

   
        
  • Measure the voltage and use a comparator at the input.
  •     
  • Use an ADC
  •     
  • Remove the LED or use another pin for it. (Set the drive mode to resistive pull up or pull down)
  •    
   

 

   

Bob

0 Likes
ThBa_1159851
Level 3
Level 3
First like received First like given

Thanks, using a second pin parallel to the Cut_Off pin helped.

   

The Cut_Off pin is in open drain drive mode. I did expect to read  a 0 or 1 from the digital pin but only got 0 in any case.

   

Thomas

0 Likes
ThBa_1159851
Level 3
Level 3
First like received First like given

Everything is working fine here 🙂
Just to be sure I understand the principle correct: When I read out a pin with a component-API, I don't get the signal that is driving the pin (for instance a signal coming from a Flip-Flop to the pin) but the signal that is actually present at the physical pin?

   

Thanks a lot!
Thomas

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

You are quite right with your estimation.

   

When you want to see which value you set the pin to, use Pin_ReadDataReg (). I do not know whether this API works when the pin was set by an internal signal (as your mentioned flip-flop), but I think you cannot read back the signal value.

   

 

   

Bob

0 Likes