>
>
> How did you solve your cdc line status check problem ?
>
>
I had this problem for a circuit which has a battery and works in a dual
way:
When connected to PC, it was needed to deliver the data to the PC, and
if it wasn't connected on startup, it should work in another forever loop
and acquire data.
Also when plugged out when running, it should be reset by own, and go to the
other mode,
and when it is connected to pc when logging, it had to stop logging and go
to usb comm
emulation mode.
I couldn't do this with line status or usb enabled flag, it always stuck (i
think it is come too early in usb mode, since comm has to initialize for a
while, i couldn't do it anyway, it freezed when changing mode, since the
device was already running and started up with battery) , so i did find my
solution. Like in bootloader, i used a pin as input, a pulldown to the
ground, a diode array connected from usb power line to the power pin of
micro., and a resistor to the USB power from the dedicated pin described
above.
I named it with an alias USB_SENSE ,
-------------------------------------------------------------------------------------
alias USB_SENSE is PORTA_RA0
alias USB_SENSE_direction is pin_A0_direction
alias RED_LED is PORTB_RB0
alias RED_LED_direction is pin_B0_direction
RED_LED_direction = output
USB_SENSE_direction = input
procedure DoEvalUSBActive is
if ( USB_SENSE == high ) then
asm goto 0x800
end if
end procedure
procedure DoEvalUSBInActive is
if ( USB_SENSE == low ) then
asm goto 0x800
end if
end procedure
if ( USB_SENSE == low ) then
;indicate USB disconnection
for 10 loop
RED_LED = on
delay_100ms(1)
RED_LED = off
delay_100ms(1)
end loop
forever loop
;Check if USB connected, if connected reset chip and go to connected mode
DoEvalUSBActive
; do the non-connected stuff
end loop
else
;; USB connected
;;;; here is the rest running with USB, the same in Albert's code..
else
for 3 loop
RED_LED = on
delay_1ms(25)
RED_LED = off
delay_100ms(3)
end loop
end if
....
....
...
-- interrupts? No thanks
while INTCON_GIE loop
INTCON_GIE = false
end loop
--- INTCON_RBIE = false
-- setup the USB device
usb_setup()
-- enable the interrupt flags, move to library?
turn_usb_ints_on()
delay_1ms(200)
-- enable USB device
usb_enable_module()
...
...
....
USB_SENSE_direction = input
forever loop
DoEvalUSBInActive ;;;; if usb disconnected, go to the reset PIC and go to
non connected mode...
-- poll the usb ISR function on a regular base, in order to
-- serve the USB requests
usb_tasks()
-- check if USB device has been configured by the HOST
if usb_is_configured() then
if usb_initialized == false ....
....
...
...
while ( usb_cdc_rx_avail() == high ) loop
DoEvalUSBInActive ;;;; if usb disconnected, go to the reset PIC and go to
non connected mode...
var byte ch = usb_cdc_getc()
if ( ch == "a" ) then
...
..
end if
...
....
end loop ;;;; while ( usb_cdc_rx_avail() == high ) loop
else ;;;
end if ;;; if enable_modem then
end loop ;; forever loop
--------------------------------------------------------------------------------------------------------
my solution was with hardware, but it could be nice if it could work with
software...
Greetings,
Serdar
--
You received this message because you are subscribed to the Google Groups
"jallib" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/jallib?hl=en.