Anyone know how to read a digital input pin?

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

cross mob
lock attach
Attachments are accessible only for community members.
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 As silly as it sounds, I have been fiddling for hours to get my project to read a digital input pin.

   

The device is a PSOC 4200 (SSOIC-28)

   

I have a Digital Input pin on P4[0], P4[1] and P4[2].

   

I see from the technical manual there are limitations on P4 with routing but it appears the pins can be used as GPIO.

   

My Power supply is 3V

   

The signals are slow (1 is a 100ms enable signal and the other a 2ms period clock and data pin)

   

I have tried CMOS trip levels, transparency mode, buffer on and off, high impedance, pull down, initial value = 0, initial value = 1.

   

I have a logic analyser connected to the input pins on the micro and the signal is stable and consistant, packets are being sent every 350ms.

   

I have tried CyPins_ReadPin(PINALIAS) and PIN_Read() but neither is detecting the high level of pin.

   

Earlier I did have an interrupt running on one of the pins and it was working but when single stepping the code, the interrupt remained being tripped by new packets coming in and causing the code to branch to isr. I changed back to pin read in an attempt to read the pin

   

My last attempt is bundled up and attached.

   

Surely, I have done something stupid, I cannot imagine reading a digital input pin would be so involved.

   

I will attach the wavforms in next post

0 Likes
13 Replies
lock attach
Attachments are accessible only for community members.
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 Wavform of signal applied to pins

0 Likes
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 I finally have the digital inputs working. Now just need to figure out how to make one of them an interrupt in firmware.

   

For my 3 pins on Port 4;

   

    CY_SYS_PINS_SET_DRIVE_MODE(CYREG_PRT4_PC,0,CY_SYS_PINS_DM_DIG_HIZ);     

   

    CY_SYS_PINS_SET_DRIVE_MODE(CYREG_PRT4_PC,1,CY_SYS_PINS_DM_DIG_HIZ);     

   

    CY_SYS_PINS_SET_DRIVE_MODE(CYREG_PRT4_PC,2,CY_SYS_PINS_DM_DIG_HIZ);     

   

    CyGlobalIntEnable;     

   

    for(;;){

   

        WakePin = CY_SYS_PINS_READ_PIN(CYREG_PRT4_PS,2);     

   

        if(WakePin){     

   

 

   

          SampleLFData();

   

        }

   

     

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

I had to change a bit to make your project run on a Pioneer Kit:

   

Connect P2_6 (J3 1) ---- J2 P0_3 (LED Blue) as indicator

   

P4_0 now input for WAKE (J3 10) since the original pin is only used internally.

   

Changing WAKE changes the LED from off to on as expected --- No error

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Interrupt

   

 

   

Bob

0 Likes
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 Bob,

   

How did you read the digital inputs? I tried all sorts of combinations an eventually only managed to get them working using the read pins code shown in my last post.

   

As I do not now have the pin components on the scematic, I am not sure how to set up an interrupt for the pins entirely in firmware?

   

I presume I need to use some API call to set the pin (say p4.2) as an input and then define an interrupt for it and us ethe startex?

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

I am still working on your problem, but I did not understand yet why you are doing the configuration dynamically and not by setting the properties of the pin component.

   

 

   

Bob

0 Likes
ViDv_264506
Level 5
Level 5
50 sign-ins 25 sign-ins 5 solutions authored

 Hi Orbitcoms,

   

please, can you be so kind, can you share - attatch the DataSheet of the AS3393 device?

   

Viktor

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

Attached latest elaborate. Reading of pins I usually do with the _Read() API which is able to read several pins of a port at once.

   

 

   

Bob

0 Likes
lock attach
Attachments are accessible only for community members.
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Did I say "Attached"?

0 Likes
HeLi_263931
Level 8
Level 8
100 solutions authored 50 solutions authored 25 solutions authored

@bob: yes you did, but your actions did not match your speech 🙂

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

@hli

   

My mouse was scared by one of my seven cats ;-))

   

 

   

Bob

0 Likes
DaHu_285096
Level 5
Level 5
10 likes received 250 replies posted 100 replies posted

 Bob,

   

So, for PSCO4 port 4 port pins, you need to read the entire port and then check the pin states of interest. Rather than doing a bitwise read per pin? 

   

ie.

   

PortState = MYPORT_Read()

   

if(PortState & 0x01){

   

//P4.0 is high

   

}

   

Then if I want interrupt, I add isr for the entire port and look at which pin caused int in the handler routine? (I want to sleep the device and only wake up on a particulr pin going high).

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

This might help -

   

 

   

    

   

         

   

http://www.cypress.com/?rID=93401     AN86439 - PSoC® 4 - Using GPIO Pins

   

    

   

         

   

http://www.cypress.com/?rID=95069     AN90799 - PSoC® 4 Interrupts

   

 

   

http://www.cypress.com/?rID=38267     AN54460 - PSoC® 3, PSoC 4, and PSoC 5LP Interrupts

   

 

   

 

   

 

   

Regards, Dana.

0 Likes