calucio24
Posts: 13
Joined: Thu Feb 01, 2018 11:02 pm

Problem with 500 Hz signal detection interrupt with PI4J [solved]

Thu Apr 18, 2019 9:44 am

Hi guys, this is Carlo.
I'm developing a java application with pi4j 1.1 and raspberry pi zero w. I have external hardware that sends to a raspberry a square signal at 500Hz.
My problem is that with interrupt I don't detect any pin edge event variation. Instead, if I read a signal in a loop cycle I can read that the signal is low and then high.
My interrupt code is this:

Code: Select all

InputOutputManager.getInstance().getSpi_cs().addListener(new GpioPinListenerDigital() {
            @Override
            public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
                  if(event.getEdge().equals(PinEdge.FALLING) )    {  
                      System.out.println("F");
                  }
            }
        });
        
        InputOutputManager.getInstance().getSpi_cs().addListener(new GpioPinListenerDigital() {
            @Override
            public void handleGpioPinDigitalStateChangeEvent(GpioPinDigitalStateChangeEvent event) {
                  if(event.getEdge().equals(PinEdge.RISING) )    {  
                      System.out.println("R");
                  }
            }
        });
My loop code instead is this:

Code: Select all

if(InputOutputManager.getInstance().getSpi_cs().getState().isHigh())    {
           System.out.println("H");
      }
      else    {     
          System.out.println("L");
      }
If I physically connect the interrupt input with ground I read "F", when I physically connect the interrupt input with 3,3V I read "R". So the interrupt works good.
So my question is: why with interrupt I can't detect FALLING and RISING events from the 500Hz signal?

thanks to everyone

calucio24
Posts: 13
Joined: Thu Feb 01, 2018 11:02 pm

Re: Problem with 500 Hz signal detection interrupt with PI4J

Thu Apr 18, 2019 3:50 pm

I have used the wrong class. I fix it with the following code:

Code: Select all

if (Gpio.wiringPiSetup() == -1) {
            System.out.println(" ==>> GPIO SETUP FAILED");
            return;
        }
        
        Gpio.pinMode(4, Gpio.INPUT) ;
        Gpio.pullUpDnControl(4, Gpio.PUD_UP);


        Gpio.wiringPiISR(4, Gpio.INT_EDGE_FALLING, new GpioInterruptCallback() {
            @Override
            public void callback(int pin) {
                mosiManager.setIsWritingTime(false);
            }
        });

Return to “Java”