Detecting USB Power on VBUS pin

I am using a nrf52833 with NCS and was wondering if there are events I can subscribe to (or polling if events don't exist) that will notify me when USB power is connected/plugged in ? This would have to detect the USB power supplied to the device (on the VBUS pin). I can detect when a device is connected using CDC to the nrf52833, but this doesn't solve the issue when a power supply is powering the device (no CDC communications).

Thanks in advance.

Parents
  • Hi

    To subscribe to the USBDETECTED event you need to enable the interrupt for it. From the HW level registers you could do something like the following:

    • Enable the USBDETECTED interrupt using the INTENSET register:
      Set the USBDETECTED bit in the INTENSET register of the POWER peripheral. This can be done by writing a 1 to bit 4 of the INTENSET register.
      NRF_POWER->INTENSET = POWER_INTENSET_USBDETECTED_Msk;
    • Implement an interrupt handler for the POWER peripheral events.
    • In your interrupt handler, check if the USBDETECTED event has occurred:
      if (NRF_POWER->EVENTS_USBDETECTED)
      {
      // Handle the USBDETECTED event
      NRF_POWER->EVENTS_USBDETECTED = 0; // Clear the event
      }
    • Remember to enable the POWER peripheral interrupt in the NVIC (Nested Vectored Interrupt Controller).

    Also, please check out the pull request here that aims to implements this functionality directly in Zephyr. https://github.com/zephyrproject-rtos/zephyr/issues/51034 

    Best regards,

    Simon

Reply
  • Hi

    To subscribe to the USBDETECTED event you need to enable the interrupt for it. From the HW level registers you could do something like the following:

    • Enable the USBDETECTED interrupt using the INTENSET register:
      Set the USBDETECTED bit in the INTENSET register of the POWER peripheral. This can be done by writing a 1 to bit 4 of the INTENSET register.
      NRF_POWER->INTENSET = POWER_INTENSET_USBDETECTED_Msk;
    • Implement an interrupt handler for the POWER peripheral events.
    • In your interrupt handler, check if the USBDETECTED event has occurred:
      if (NRF_POWER->EVENTS_USBDETECTED)
      {
      // Handle the USBDETECTED event
      NRF_POWER->EVENTS_USBDETECTED = 0; // Clear the event
      }
    • Remember to enable the POWER peripheral interrupt in the NVIC (Nested Vectored Interrupt Controller).

    Also, please check out the pull request here that aims to implements this functionality directly in Zephyr. https://github.com/zephyrproject-rtos/zephyr/issues/51034 

    Best regards,

    Simon

Children
No Data
Related