dinuxbg / pru-gcc-examples

Simple example projects for PRU-GCC
49 stars 12 forks source link

Modified the BlinkingLED to include Button: Read Not working #5

Closed deebot closed 4 years ago

deebot commented 4 years ago

Hello. I modified your blinkingLED c code so that the blinking of LED starts when the button is pressed. Here is my code. https://pastebin.com/LtfA4Pmu

The problem is with reading the register 31 for the input pin. My button is in the pulled down state using a external 1k resistance such that when the button is not pressed the PRU input pin is having GND Value and when the button is pressed the PRU input pin has HIGH value on it. Am i missing something. Also if you could point to some code to activate internal pullup and pulldown in PRU configuration. On successfully testing this code i wish to submit a pull request to include another example for beginners

dinuxbg commented 4 years ago

Did you setup PRU0 IN2 pin mux? Here is an example for PocketBeagle: $ config-pin P2_32 pruin # pru0_pru_r31_2

deebot commented 4 years ago

yes i did that. i have also mentioned this on line 32 of my pastebin

dinuxbg commented 4 years ago

The logic is not correct. Upon detecting non-pressed button, you exit main. Perhaps that's what you meant:

int main(void)
{
    unsigned int c;

    for(c=0;;c++) {
         if (read_r31() &  BUTTON) {
        write_r30(c & 1 ? (read_r30()|(1<<LED)) : ~(1<<LED)&read_r30());
        delay_us (period_us);
        }
    }
    return 0;
}
deebot commented 4 years ago

thanks tested the code it worked flawless. Have made a pull request to include the example