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

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2015-07-12T19:12:55+02:00</updated>

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

		<entry>
		<author><name><![CDATA[cpldcpu]]></name></author>
		<updated>2015-07-12T19:12:55+02:00</updated>

		<published>2015-07-12T19:12:55+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9042&amp;p=29956#p29956</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=29956#p29956"/>
		<title type="html"><![CDATA[Re: is usb connected (the software method)]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=29956#p29956"><![CDATA[
It should be possible to detect if D+ is pulled low after the forced buis reset. The 10kOhm pull down of the host should do that. It may be beneficial to activate the pull up on the client side for D+.<br /><br />Has anybody tried this, and does it work realiabilty?<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=20062">cpldcpu</a> — Sun Jul 12, 2015 7:12 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[blargg]]></name></author>
		<updated>2014-08-09T08:04:29+02:00</updated>

		<published>2014-08-09T08:04:29+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27897#p27897</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27897#p27897"/>
		<title type="html"><![CDATA[Re: is usb connected (the software method)]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27897#p27897"><![CDATA[
If I were in your position, I'd start a fresh test program, without usbdrv, and get the USB detection working on INT1 connected to a switch. Once that worked, I'd get it working with USB D-. And then finally integrate that back into the main code.<br /><br />From what I've learned, on the AVR you generally want to have interrupts disabled, configure them, and then <strong class="text-strong">clear the appropriate interrupt flag</strong> so it doesn't fire the moment you enable them. Usually it's some xxxF register. On the '328, to set up INT1 to trigger on a level change, my reading of the manual is<br /><div class="codebox"><p>Code: </p><pre><code>EICRA  = (EICRA &amp; ~(3&lt;&lt;ISC10)) | 1&lt;&lt;ISC10; // int on level change<br />EIFR   = 1&lt;&lt;INTF1; // clear flag (yes, write, don't OR, the bit to clear it)<br />EIMSK |= 1&lt;&lt;INT1;<br />sei();<br /><br />ISR( INT1_vect )<br />{<br />   usbConnected = 1;<br />}<br /></code></pre></div><br />Your original post mentioned using PCINT (rather than INT). If you go that route, using PCINT0 (PB0):<br /><div class="codebox"><p>Code: </p><pre><code>PCMSK0 |= 1&lt;&lt;PCINT0;<br />PCIFR   = 1&lt;&lt;PCIF0;<br />PCICR  |= 1&lt;&lt;PCIE0;<br />sei();<br /><br />ISR( PCINT0_vect )<br />{<br />   usbConnected = 1;<br />}<br /></code></pre></div><br /><br />I'm not totally sure that writing to the flags register just after configuring the interrupt will avoid it being set immediately. Insert some nops just after the EICRA/PCMSK0 write if the above code doesn't work in your test.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=20076">blargg</a> — Sat Aug 09, 2014 8:04 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[psc]]></name></author>
		<updated>2014-08-08T22:10:05+02:00</updated>

		<published>2014-08-08T22:10:05+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27895#p27895</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27895#p27895"/>
		<title type="html"><![CDATA[Re: is usb connected (the software method)]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27895#p27895"><![CDATA[
It's still not working on my end. Since I am using INT0 (d+) and INT1 (-d) I was not able to write a custom IRS for INT0 (already used in usbdrv), but I was able to use IRS INT1 vector. But I have a trigger on INT1 even when powering my board from an external supply (USB not even connected).<br /><br />Is this define somewhat important?<br />#define USB_CFG_IS_SELF_POWERED0<br />/* Define this to 1 if the device has its own power supply. Set it to 0 if the<br /> * device is powered from the USB bus.<br /><br />Thanks for all the help so far guys!<br />(For the time being I will use a switch on an I/O)<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1494">psc</a> — Fri Aug 08, 2014 10:10 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[blargg]]></name></author>
		<updated>2014-08-08T21:57:52+02:00</updated>

		<published>2014-08-08T21:57:52+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27894#p27894</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27894#p27894"/>
		<title type="html"><![CDATA[Re: is usb connected (the software method)]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27894#p27894"><![CDATA[
Have your main code sit in a loop waiting for usbConnected to become true, then light an LED or give some feedback. Does it trigger when you plug USB in (and your project is externally-powered)? Then it's set up right. <img class="smilies" src="./../../../images/smilies/icon_smile.gif" alt=":)" title="Smile" /><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=20076">blargg</a> — Fri Aug 08, 2014 9:57 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ulao]]></name></author>
		<updated>2014-08-05T18:10:16+02:00</updated>

		<published>2014-08-05T18:10:16+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27884#p27884</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27884#p27884"/>
		<title type="html"><![CDATA[Re: is usb connected (the software method)]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27884#p27884"><![CDATA[
make sure you set your check before you init the usb. and make sure you turn on interrupts.<br /><br />PCMSK0 |= (1 &lt;&lt; PCINT0);<br />PCICR |= (1 &lt;&lt; PCIE0);<br />sei();                    // turn on interrupts<br /><br />ISR(PCINT0_vect)<br />{<br />   usbConnected = 1;<br />}<br /><br />also don't you want PCINT17 or PCINT16 <br /><img src="https://sites.google.com/site/qeewiki/_/rsrc/1297558518457/books/avr-guide/external-interrupts/ATmega328%20-%20PCINTx.JPG" class="postimage" alt="Image" /><br /><br />PIND0 is PCINT16 which is in the PCIE2 group (there are 8 pins in each of 3 interrupts)<br /><div class="codebox"><p>Code: </p><pre><code>int main(void) {<br /> PCICR |= (1&lt;&lt;PCIE2); // enable its group of 8<br /> PCMSK2 |= (1&lt;&lt;PCINT16); // enable just that 1 in 8<br /> sei(); // globally enable interrupts<br /> while(1); // sit and wait for one<br />}<br /><br />ISR(PCINT2_vect) {<br /> // ta-da<br />} <br /></code></pre></div><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1281">ulao</a> — Tue Aug 05, 2014 6:10 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[psc]]></name></author>
		<updated>2014-08-04T19:34:06+02:00</updated>

		<published>2014-08-04T19:34:06+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27881#p27881</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27881#p27881"/>
		<title type="html"><![CDATA[Re: is usb connected (the software method)]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27881#p27881"><![CDATA[
Still trying to figure this out. I tried using this piece of code:<br /><br /><div class="codebox"><p>Code: </p><pre><code>PCMSK0 |= (1 &lt;&lt; PCINT0);<br />PCICR |= (1 &lt;&lt; PCIE0);<br /><br />ISR(PCINT0_vect) <br />{<br />   usbConnected = 1;<br />} <br /></code></pre></div><br /><br />I am using PCINT0 = D-: is it the right way?<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1494">psc</a> — Mon Aug 04, 2014 7:34 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ulao]]></name></author>
		<updated>2014-06-13T17:14:09+02:00</updated>

		<published>2014-06-13T17:14:09+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27094#p27094</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27094#p27094"/>
		<title type="html"><![CDATA[Re: is usb connected (the software method)]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27094#p27094"><![CDATA[
well UsbPoll() is a bool 1 or 0 so its as simple as <br /><br />if ( UsbPoll() ) <br /><br />but inorder to use that the USB init has to have run, and if you ran that its assumed you know the usb is connected, so I think that is out? Again depends how you do things.<br /><br />Pin change is the best bet and very easy. You should not do this when the USB is running, only use it to detect it.<br /><!-- m --><a class="postlink" href="https://sites.google.com/site/qeewiki/books/avr-guide/external-interrupts">https://sites.google.com/site/qeewiki/b ... interrupts</a><!-- m --><br /><br />When the usb is first plugged in I believe you will see many pin changes. You may want to set the pins lo to avoid a hi-z state false trigger.<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1281">ulao</a> — Fri Jun 13, 2014 5:14 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[psc]]></name></author>
		<updated>2014-06-13T16:55:21+02:00</updated>

		<published>2014-06-13T16:55:21+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27093#p27093</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27093#p27093"/>
		<title type="html"><![CDATA[Re: is usb connected (the software method)]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27093#p27093"><![CDATA[
Yes I have a standalone mode (powering my circuit from another source than USB). I want the same firmware to work without the USB calls. So if I understand correctly, I can:<br /><br />- use UsbPoll()<br />- watching for a pin change (D- or D+)<br /><br />Any code example?<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1494">psc</a> — Fri Jun 13, 2014 4:55 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ulao]]></name></author>
		<updated>2014-06-13T16:43:06+02:00</updated>

		<published>2014-06-13T16:43:06+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27092#p27092</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27092#p27092"/>
		<title type="html"><![CDATA[Re: is usb connected (the software method)]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27092#p27092"><![CDATA[
I'm not familiar with the midi interface so I assume it gets power from the midi bus? Normally you get power from the USB so you are always connected to the usb. Though in the event your are not, you could watch for a pin change on the usb data lines, I'd do it wrapped in disable/enable interrupts. Or you could check for usb poll? Really depends on when you need to check for this. v-usb has its own usb connect disconnect function that merely pulls up on the data - line. So I'm guessing you want to init the usb when a users connects it? If so I would go the pin change way...<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1281">ulao</a> — Fri Jun 13, 2014 4:43 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[psc]]></name></author>
		<updated>2014-06-13T04:42:31+02:00</updated>

		<published>2014-06-13T04:42:31+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27079#p27079</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27079#p27079"/>
		<title type="html"><![CDATA[is usb connected (the software method)]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=9042&amp;p=27079#p27079"><![CDATA[
Hi all,<br /><br />I am trying to detect if there's a USB cable connected (i am using the v-usb midi firmware by horo if it matter). I am wondering what's the best method. I cannot change the pcb so I am looking for a software solution... Any insight would be useful (using register?, a special variable in v-usb? a timer?)...<br /><br />Thanks<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1494">psc</a> — Fri Jun 13, 2014 4:42 am</p><hr />
]]></content>
	</entry>
	</feed>
