USB HID Keyboard, usage inside IRQ

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

cross mob
Rova_1179706
Level 2
Level 2
First like received First like given

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.

0 Likes
1 Solution
Rova_1179706
Level 2
Level 2
First like received First like given

Discovered the problem:

The USB-interrupts must be higher then the button-interrupts.

By default they are all 7, USB needs to be 6 or higher.

View solution in original post

0 Likes
2 Replies
Rova_1179706
Level 2
Level 2
First like received First like given

Discovered the problem:

The USB-interrupts must be higher then the button-interrupts.

By default they are all 7, USB needs to be 6 or higher.

0 Likes
alderbaran74815
Level 1
Level 1
First reply posted First question asked Welcome!

Hi Rova, it is an old post but would be able to share you project? or you function aASCII_ToScanCode. Thank you

0 Likes