<?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/3125" />

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2009-09-22T10:16:25+02:00</updated>

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

		<entry>
		<author><name><![CDATA[christian]]></name></author>
		<updated>2009-09-22T10:16:25+02:00</updated>

		<published>2009-09-22T10:16:25+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=3125&amp;p=11048#p11048</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=11048#p11048"/>
		<title type="html"><![CDATA[Re: How to know if device has been connected to the USB ?]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=11048#p11048"><![CDATA[
<blockquote><div><cite>Grendel wrote:</cite>Christian, usbConfiguration should be cleared during a reset condition (usbPoll(), where usbDevice Addr is cleared).</div></blockquote><br /><br />I considered this, but it costs two bytes of code space. Some boot loaders fit extremely tight and the two bytes may be a problem there. On the other hand, usbConfiguration is rarely used.<br /><br />If you need to have it reset on USB Reset, add a USB_RESET_HOOK to your usbconfig.h and clear it there.<br /><br />Regarding the main topic:<br />The safest way to find out whether USB is connected is the +5V supply from USB. You would normally decouple VBus from the stand-alone supply via a diode and connect the 1k5 pull-up to VBus, not the stand-alone supply. This way you can monitor D- from the main loop. If it is high level, you are connected to a bus. If it is low level for several samples in a row, you are disconnected.<br /><br />You probably won't ever sample a low level data bit because the interrupt routine is running while data is transferred.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=8">christian</a> — Tue Sep 22, 2009 10:16 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[spiky]]></name></author>
		<updated>2009-08-28T18:49:05+02:00</updated>

		<published>2009-08-28T18:49:05+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10715#p10715</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10715#p10715"/>
		<title type="html"><![CDATA[Re: How to know if device has been connected to the USB ?]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10715#p10715"><![CDATA[
thanks grendel. That looks like the easiest way.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=2578">spiky</a> — Fri Aug 28, 2009 6:49 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Grendel]]></name></author>
		<updated>2009-08-27T10:12:39+02:00</updated>

		<published>2009-08-27T10:12:39+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10674#p10674</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10674#p10674"/>
		<title type="html"><![CDATA[Re: How to know if device has been connected to the USB ?]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10674#p10674"><![CDATA[
On a 2nd thought -- the SOFs also go away if the device is suspended, that could be a problem. Am afraid that the only really safe way to detect a disconnect is monitoring the VBus signal.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=101">Grendel</a> — Thu Aug 27, 2009 10:12 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[spiky]]></name></author>
		<updated>2009-08-27T10:01:12+02:00</updated>

		<published>2009-08-27T10:01:12+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10673#p10673</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10673#p10673"/>
		<title type="html"><![CDATA[Re: How to know if device has been connected to the USB ?]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10673#p10673"><![CDATA[
thanks. i'll try it out .<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=2578">spiky</a> — Thu Aug 27, 2009 10:01 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Grendel]]></name></author>
		<updated>2009-08-27T08:21:02+02:00</updated>

		<published>2009-08-27T08:21:02+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10671#p10671</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10671#p10671"/>
		<title type="html"><![CDATA[Re: How to know if device has been connected to the USB ?]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10671#p10671"><![CDATA[
Hm, that's probably because V-USB doesn't detect the disconnect. Forgot about that <img class="smilies" src="./../../../images/smilies/icon_sad.gif" alt=":(" title="Sad" /> In order for this to work you could enable the SOF counter (see USB_COUT_SOF in usbconfig-prototype.h) and monitor the SOFs. If they stop comming you are disconnected and could manually reset the driver with this function:<br /><br /><div class="codebox"><p>Code: </p><pre><code>void usbUnplugged ( void )<br />{<br />    usbNewDeviceAddr = 0 ;<br />    usbDeviceAddr = 0 ;<br />    usbConfiguration = 0 ;<br />    usbResetStall() ;<br />}</code></pre></div><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=101">Grendel</a> — Thu Aug 27, 2009 8:21 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[spiky]]></name></author>
		<updated>2009-08-26T16:30:54+02:00</updated>

		<published>2009-08-26T16:30:54+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10660#p10660</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10660#p10660"/>
		<title type="html"><![CDATA[Re: How to know if device has been connected to the USB ?]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10660#p10660"><![CDATA[
Thanks for the tip Grendel , but it doesnt seem to help. usbConfiguration doesnt seem to change at all.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=2578">spiky</a> — Wed Aug 26, 2009 4:30 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Grendel]]></name></author>
		<updated>2009-08-24T08:20:12+02:00</updated>

		<published>2009-08-24T08:20:12+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10636#p10636</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10636#p10636"/>
		<title type="html"><![CDATA[Re: How to know if device has been connected to the USB ?]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10636#p10636"><![CDATA[
Christian, could you flag this for inclusion w/ the next release please ?<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=101">Grendel</a> — Mon Aug 24, 2009 8:20 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Grendel]]></name></author>
		<updated>2009-08-20T01:39:17+02:00</updated>

		<published>2009-08-20T01:39:17+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10595#p10595</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10595#p10595"/>
		<title type="html"><![CDATA[Re: How to know if device has been connected to the USB ?]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10595#p10595"><![CDATA[
<blockquote><div><cite>spiky wrote:</cite>I tested the variable usbConfiguration in the main loop. It doesnt change at all. If i disconnect or re-connect the device , it remains the same. Is there something i did wrong ?</div></blockquote><br />No, the driver has a bug (oversight actually), usbConfiguration doesn't get cleared if a reset happens on the bus:<br /><br /><blockquote><div><cite>Grendel wrote:</cite>Christian, usbConfiguration should be cleared during a reset condition (usbPoll(), where usbDevice Addr is cleared).</div></blockquote><br />Try adding the line<br /><br /><div class="codebox"><p>Code: </p><pre><code>usbConfiguration = 0 ;</code></pre></div><br />in usbdrv.c:usbPoll() after the line<br /><br /><div class="codebox"><p>Code: </p><pre><code>usbDeviceAddr = 0;</code></pre></div><br />Now, usbConfiguration != 0 should signal that the device is connected &amp; enumerated.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=101">Grendel</a> — Thu Aug 20, 2009 1:39 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[spiky]]></name></author>
		<updated>2009-08-19T13:54:41+02:00</updated>

		<published>2009-08-19T13:54:41+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10584#p10584</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10584#p10584"/>
		<title type="html"><![CDATA[Re: How to know if device has been connected to the USB ?]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10584#p10584"><![CDATA[
My apologies for the late reply.<br /><br />Thanks for the suggestion grendel. But it doesnt work for me. I tested the variable usbConfiguration in the main loop. It doesnt change at all. If i disconnect or re-connect the device , it remains the same. Is there something i did wrong ?<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=2578">spiky</a> — Wed Aug 19, 2009 1:54 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[Grendel]]></name></author>
		<updated>2009-08-13T21:54:49+02:00</updated>

		<published>2009-08-13T21:54:49+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10542#p10542</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10542#p10542"/>
		<title type="html"><![CDATA[Re: How to know if device has been connected to the USB ?]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=3125&amp;p=10542#p10542"><![CDATA[
Usually the last thing the host does during enumeration is setting the configuration. You can check if the variable usbConfiguration is not zero for an indication if the device is plugged in and enumerated.<br /><br />Christian, usbConfiguration should be cleared during a reset condition (usbPoll(), where usbDevice Addr is cleared).<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=101">Grendel</a> — Thu Aug 13, 2009 9:54 pm</p><hr />
]]></content>
	</entry>
	</feed>
