Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CDC "on demand"
21-08-2014, 02:53 PM,
#1
CDC "on demand"
Is there a possiblity to run program whether board is connected to computer USB or not when using CDC?

I've observed that when I use CDC my program won't start unless I connect board to computer, but I want my program to run, wether it is conected to computer or just to usb power supply.
Reply
26-08-2014, 09:50 AM,
#2
RE: CDC "on demand"
No. This is still a function to write. Something like :

if CDC.available()
{
...
}

Please add a request here : https://github.com/PinguinoIDE/pinguino-libraries/pulls
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
26-08-2014, 10:52 AM,
#3
RE: CDC "on demand"
You can use the following code.

Code:
extern u8 control_signal_bitmap;    // in libusb.a
extern u8 USBDeviceState;

#define cdc_dtr_clear()      (control_signal_bitmap &= 0xfe)
#define cdc_dtr_status()     ((control_signal_bitmap & 0x01) == 0x01)
#define cdc_usb_connected()  ((U1OTGSTATbits.VBUSVD != 0) && (U1OTGSTATbits.SESVD != 0))
#define cdc_usb_configured() (USBDeviceState == 0x20)

The cdc_usb_connected() shows if USB is connected. Enhanced version is implemented as CDCUSBIsConnected() in cdc library.

cdc_usb_configured() shows if the Pinguino and host PC established CDC connection. That means CDC COM port is available for use on host PC. It is implemented as USBCDCisConfigured() in cdc library.

cdc_dtr_status() shows the DTR status set by the host PC application. Most terminal emulation programs on the host PC will set DTR high after opening the CDC com port. Enhanced version is implemented in cdc library as DCClearDTR() and CDCDTRIsReady().

Once Pinguino IDE detects any reference to CDC function in the code, it will attach the USB port and initialize it regardless if you actually execute it. If you want to save about 4mA current used by the USB regulator, you can use USBDeviceDetach() to disable the USB module. You can also enable it by USBDeviceAttach() and USBDeviceInit().

DJ
Reply
26-08-2014, 11:21 AM,
#4
RE: CDC "on demand"
I think Daniel has made a 8-bit Pinguino not a 32-bit one.
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply
26-08-2014, 07:15 PM,
#5
RE: CDC "on demand"
If P8 is used, the above library functions won't work.

If the device is self powered (by another power source), it is necessary to connect VBus (5V from USB) to one of the digital input via 100k resistor to detect the presence of the USB connection.

Daniel's case is different that the device is USB bus powered. I can see his problem that CDC_init() in main.c will wait forever until the USB becomes CONFIGURED, and it will never happen if the USB is connected to the power supply (not PC).

One way to overcome this problem is changing the CDC processing code block.

1) disable CDC_init() in main.c
2) execute first part of CDC_init() in setup() till EnableUSBModule().
3) execute ProcessUSBTransactions() in loop().
4) check if (deviceState == CONFIGURED) in loop() after ProcessUSBTransactions(). If so, execute the rest part of CDC_init().
5) if condition 4) match, it is safe to execute CDC function.

DJ
Reply
27-08-2014, 06:50 PM,
#6
RE: CDC "on demand"
(26-08-2014, 07:15 PM)djpark Wrote: If P8 is used, the above library functions won't work.

If the device is self powered (by another power source), it is necessary to connect VBus (5V from USB) to one of the digital input via 100k resistor to detect the presence of the USB connection.

Daniel's case is different that the device is USB bus powered. I can see his problem that CDC_init() in main.c will wait forever until the USB becomes CONFIGURED, and it will never happen if the USB is connected to the power supply (not PC).

One way to overcome this problem is changing the CDC processing code block.

1) disable CDC_init() in main.c
2) execute first part of CDC_init() in setup() till EnableUSBModule().
3) execute ProcessUSBTransactions() in loop().
4) check if (deviceState == CONFIGURED) in loop() after ProcessUSBTransactions(). If so, execute the rest part of CDC_init().
5) if condition 4) match, it is safe to execute CDC function.

DJ

It is P8( PIC18LF2550). You've got my case perfectly djpark. Thanks for informations. I see that I'll have to get more familiar with what is going on in background of pinguino environment.
Reply
27-08-2014, 09:22 PM,
#7
RE: CDC "on demand"
I'd be pleased to update the code if your tests are successful ;-)
It is easier to complain than it is to do, but it is better to do than it is to complain.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)