<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-gb">
	<link rel="self" type="application/atom+xml" href="https://forums.obdev.at/app.php/feed/topic/5250" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2010-12-10T12:46:59+02:00</updated>

	<author><name><![CDATA[Objective Development Forums]]></name></author>
	<id>https://forums.obdev.at/app.php/feed/topic/5250</id>

		<entry>
		<author><name><![CDATA[dzairo]]></name></author>
		<updated>2010-12-10T12:46:59+02:00</updated>

		<published>2010-12-10T12:46:59+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=5250&amp;p=16986#p16986</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=5250&amp;p=16986#p16986"/>
		<title type="html"><![CDATA[Check if is USB or not .... SOLVED]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=5250&amp;p=16986#p16986"><![CDATA[
Hi all.<br />Today I'm think and find any solution how to check if is USB connected or not.<br />Some user use USB only short time , other time use native function and with interrupt too.<br />If use interrupt (timer, UART ...) than can't use USB . There is big time critical function for emulate USB <br />on AVR MCU.O want use USB for upgrade MCU firmware or change any setting in internal EEprom.<br />But it's only if need other use normal program with enabled other interrupt peripherals. For this I don't want<br />use other mcu like FTDI or other. With this I must check if is USB or not. If is plugged into USB , small function check it <br />and disable other interrupt and some special function, switch internal program into USB mode. Make all what I need and if unplug <br />then my small function check so USB is lost and can enable all needed interrupt and user function. My program work normal mode.<br />If plug it in to USB again then check it and disable other interrupt and re-enumerate USB and PC detect USB device normal (not tested now).<br /><br />Check:<br />if use MCU with pin change interrupt then we can enable any D+ or D- used pin for USB and check interrupt flag.<br />If USB communication change any state on this pin then set flag on special function register for pin change interrupt.<br />But If use ATmega8 then we can use this because ATmega8 don't have this.<br />other solution is use any free bit in special function register and append or change any ASM function on usbdrvasm.inc file.<br />I use this solution.<br />In my application never want use Analog comparator and use ACIS0 bit in ACSR special function register.<br />On (I use 12MHz ) usbdrvasm12.inc find this instruction nop2. This instruction is defined in usbportability.h<br />#define nop2 rjmp .... and definitionof jump. This define is used for 2 cycle MCU and one instruction (is possible use 2x nop but it's use 2 instruction)<br />I define new <br />#define nopU sbi ACSR,ACIS0<br />and all nop2 instruction change with this nopU<br />if External Interrupt 0 trigger then set this bit and SFR and on my program can check it and clear .<br />in my program check if is this bit set , if is then clear it and wait 100mS. after this time I check again if is then I know so is plugged in to USB .<br />if not can I run my normal function.<br /><br />king regards.<br /><br />PS: I try only detect, with re-enumerate not tested (later)<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=4367">dzairo</a> — Fri Dec 10, 2010 12:46 pm</p><hr />
]]></content>
	</entry>
	</feed>
