Announcements
Community Announcement : Welcome to the NEW Cypress Developer Community.
cancel
Showing results for 
Search instead for 
Did you mean: 

PSoC 4 MCU

ThBa_1159851
New Contributor II

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
Expert II

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
Expert II

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
rola_264706
Honored Contributor II

Here is the manual on IO pins.

0 Likes
rola_264706
Honored Contributor II

Here is a small program.

0 Likes
ThBa_1159851
New Contributor II

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
Expert II

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

   

 

   

Happy coding

   

Bob

0 Likes
ThBa_1159851
New Contributor II

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
Expert II

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
New Contributor II

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
New Contributor II

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
Expert II

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