Check for USB connection in software

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

cross mob
MaWo_1214996
Level 3
Level 3
First like given

Hello,

I am sitting on a project based on the AN82072 USB General Data Transfer with Standard HID Drivers.

I would like to realize that I have a decision wether USB is connected or not and run different code respectively.

So I would like to detect USB connection in software.

If USB cable is connected to the host, it should display data in my host application, as it is realized in the AN now.

If no USB connection is present, I would like to record data to an SD card.

I have read that I can do this with detecting the BUS Voltage on the USB Component. I probably will realize it that way, but for now I am still sitting with the demo board and it would be convenient to have that in software.

Anyone can help here?

0 Likes
1 Solution
MiSt_296941
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

Here is what I did - I thought I got this from an example PSoC project...

if (USBFS_GetConfiguration())       // Only process USB stuff if it is connected.

{

}

View solution in original post

0 Likes
4 Replies
MiSt_296941
Level 4
Level 4
25 replies posted 10 replies posted 10 questions asked

Here is what I did - I thought I got this from an example PSoC project...

if (USBFS_GetConfiguration())       // Only process USB stuff if it is connected.

{

}

0 Likes

I needet a small delay before GetConfiguration.

I have done it now like this:

USBFS_Start(0, USBFS_DWR_VDDD_OPERATION);

//while(USBFS_bGetConfiguration() == 0x00)

//    {

//    }

/* Check for USB connection */

    CyDelay(1000);

    if(USBFS_bGetConfiguration() == 0) /* If USB connection is present run this */

     {

        for(;;)

        {

        }

     }

    else /* If USB is not connected, run this */

    {

    }

BTW: Anyone know what is the small letter "b" in the functions for the USB component?

0 Likes

If you are using latest USB component in creator4.2, you can use "USBFS_GetConfiguration()" instead of "USBFS_bGetConfiguration()"

0 Likes

Thank you, anks. Will keep that in mind.

I am using at the moment still 3.3.

0 Likes