1 Reply Latest reply on Jan 6, 2018 12:53 PM by user_343889402

    USB HID Keyboard, usage inside IRQ

    user_343889402

      Hello Cypress users,

       

      Project

      I am using the $10 PSoC 5LP kit with a USB socket.
      What I want to to do is send a key (or multiple keypresses) when a button is pressed.

      AN58726 was my guide for configuring the USBFS component.

       

      Setup

      I have a digital input connected to debouncer which negative flank is connected to a interrupt component.

      Interrupts are enabled, and is started with isr_StartEx(BIG_Btn_isr).

      Inside the CY_ISR(BIG_Btn_isr) I want to use the following code:

       

          while(!USBFS_bGetEPAckState(1));
          Keyboard_Data[0] = 0x00;
          Keyboard_Data[2] = aASCII_ToScanCode['c' - 0x20];
          USBFS_LoadInEP(1, Keyboard_Data, 8);
          while(!USBFS_bGetEPAckState(1));
          Keyboard_Data[0] = 0x00;
          Keyboard_Data[2] = 0x00;
          USBFS_LoadInEP(1, Keyboard_Data, 8);
          while(!USBFS_bGetEPAckState(1));
      
          Keyboard_Data[0] = 0x00;
          Keyboard_Data[2] = aASCII_ToScanCode['a' - 0x20];
          USBFS_LoadInEP(1, Keyboard_Data, 8);
          while(!USBFS_bGetEPAckState(1));
          Keyboard_Data[0] = 0x00;
          Keyboard_Data[2] = 0x00;
          USBFS_LoadInEP(1, Keyboard_Data, 8);
          while(!USBFS_bGetEPAckState(1));
      
          Keyboard_Data[0] = 0x00;
          Keyboard_Data[2] = aASCII_ToScanCode['t' - 0x20];
          USBFS_LoadInEP(1, Keyboard_Data, 8);
          while(!USBFS_bGetEPAckState(1));
          Keyboard_Data[0] = 0x00;
          Keyboard_Data[2] = 0x00;
          USBFS_LoadInEP(1, Keyboard_Data, 8);
          while(!USBFS_bGetEPAckState(1));
      

      Problem:

      When above code is placed inside the for-loop it displays "cat", exactly as predicted.

      When above code is placed inside the setup it displays "cat", exactly as predicted.

      When above code is placed inside the interrupt it outputs 1 enourmous string of c's: "cccccccccccccccccccccccccccccccccc" until i remove the device.

       

      I don't understand why it failed inside the interrupt.