I’m trying to find a way to know if the usb port is plugged and is powering the board.
I’m currently trying to read the state of RXD0 as it have to be HIGH when idle (see serial specification https://learn.sparkfun.com/tutorials/serial-communication)
But i’m still unsuccessful as a digitalRead nor an analogRead seems to give any result.
I would gladly welcome any insight on that topic.
thx
Unlike with the AVR based boards (such as the Mbili), on the SodaqONE (and Autonomo) the USB does not use the hardware UART labelled Serial. It uses the native USB support of the Samd21.
You could test the FSM state of the USB DEVICE register:
USB->DEVICE.FSMSTATUS.bit.FSMSTATE
There are a few definitions which you can test against:
USB_FSMSTATUS_FSMSTATE_OFF_Val
USB_FSMSTATUS_FSMSTATE_ON_Val
USB_FSMSTATUS_FSMSTATE_SUSPEND_Val
USB_FSMSTATUS_FSMSTATE_SLEEP_Val
USB_FSMSTATUS_FSMSTATE_DNRESUME_Val
USB_FSMSTATUS_FSMSTATE_UPRESUME_Val
USB_FSMSTATUS_FSMSTATE_RESET_Val
These reference specific bits in the FSMSTATE register.
See page 791 of the datasheet: http://www.atmel.com/Images/Atmel-42181-SAM-D21_Datasheet.pdf
Ok thank you for your quick answer !