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

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2012-12-19T19:05:03+02:00</updated>

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

		<entry>
		<author><name><![CDATA[cocojack]]></name></author>
		<updated>2012-12-19T19:05:03+02:00</updated>

		<published>2012-12-19T19:05:03+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=8015&amp;p=24208#p24208</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=8015&amp;p=24208#p24208"/>
		<title type="html"><![CDATA[Re: usbFunctionWrite doesn't get called]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=8015&amp;p=24208#p24208"><![CDATA[
I think i found the mistake, <br />the tutorial said &quot; argv[2], strlen(argv[2])+1,&quot;<br />i wanted to reply a char[] and argv is a **char ..<br /><br />so I changed  strlen(argv[2])+1, to  strlen(inputbuffer)+1, and it seemed to be wrong.<br />Now I changed this to sizeof(inputbuffer)+1 and for some reason this works now..<br /><br />anyway thanks for readiny my post <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=14473">cocojack</a> — Wed Dec 19, 2012 7:05 pm</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[cocojack]]></name></author>
		<updated>2012-12-19T18:01:51+02:00</updated>

		<published>2012-12-19T18:01:51+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=8015&amp;p=24207#p24207</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=8015&amp;p=24207#p24207"/>
		<title type="html"><![CDATA[usbFunctionWrite doesn't get called]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=8015&amp;p=24207#p24207"><![CDATA[
Good evening,<br />at first i want to appologize, if my english is not the very best, its not my navie language.<br /><br />I already posted my Problem on a german - speaking board, but it seems noone has a clue about the misake i made.<a href="http://www.mikrocontroller.net/topic/280724" class="postlink">Mikrocontroller.net</a><br /><br />I followed the V-USB Tutorial on <!-- m --><a class="postlink" href="http://codeandlife.com">http://codeandlife.com</a><!-- m --> and accomplished part 1-3 successfull. Now I wanted to try to send random char[16] to my attiny2313 and recive them back.<br /><br />This is the code I've used:<br /><div class="codebox"><p>Code: </p><pre><code>static uchar replyBuf&#91;16&#93;   = &quot;Hello, USB!&quot;;<br />static uchar reciveBuf&#91;16&#93;  = {&quot;TEST&quot;};<br />static uchar dataReceived = 0, dataLength = 0; // for USB_DATA_IN<br /><br /><br />USB_PUBLIC uchar usbFunctionSetup(uchar data&#91;8&#93;) <br />{<br />    <br />   <br />   usbRequest_t *rq = (void *)data; // cast data to correct type<br />        <br />    switch(rq-&gt;bRequest) <br />   {   <br />      // custom command is in the bRequest field<br />      case USB_LED_ON:<br />            PORTB |= (1&lt;&lt;PB0); // turn LED on<br />            return 0;<br />      case USB_LED_OFF: <br />            PORTB &amp;= ~(1&lt;&lt;PB0); // turn LED off<br />            return 0;   <br />            <br />      case USB_DATA_OUT:   <br />            usbMsgPtr = replyBuf;<br />            return sizeof(replyBuf);<br />            <br />      case USB_DATA_WRITE:<br />                  <br />            dataLength = (uchar)rq-&gt;wLength.word;<br />            dataReceived = 0;<br />                <br />            if(dataLength &gt; sizeof(reciveBuf)) <br />            {dataLength = sizeof(reciveBuf);}   //setzte wieviele Bytes empfangen werden können<br />                <br />            return USB_NO_MSG;   // ruft usbFunctionWrite auf<br />            //return 0xFF;<br />            <br />      case    USB_DATA_ACT:<br />            <br />            for(uint8_t i = 0; i&lt;16; i++)<br />            {<br />               replyBuf&#91;i&#93;=reciveBuf&#91;i&#93;;<br />            }<br />            return 0;<br />}   <br /><br />    return 0; // should not get here<br />}<br /><br /><br />///<br /><br />USB_PUBLIC uchar usbFunctionWrite(uchar *data, uchar len) {<br />   uchar i;<br />   PORTB ^= (1&lt;&lt;PB1);  // to indicate the function got called<br />   for(i = 0; dataReceived &lt; dataLength &amp;&amp; i &lt; len; i++, dataReceived++)<br />      reciveBuf&#91;dataReceived&#93; = data&#91;i&#93;;<br />      <br />    return (dataReceived == dataLength); // 1 if we received it all, 0 if not<br />}<br /><br /></code></pre></div><br /><br /><br />On the pc-side I've used following code<br /><div class="codebox"><p>Code: </p><pre><code>// int main...<br />   using namespace std;<br />   int wtd;<br />   bool loop = true;<br /><br /><br />    usb_dev_handle *handle = NULL;<br />    int nBytes = 0;<br />    char buffer&#91;256&#93;;<br />   char inputbuffer&#91;16&#93; = {&quot;hl&quot;}<br /><br /><br />///... <br />   while(loop)<br />   {<br />      printf(&quot;\n\n\n\n\n0 : LED an\n1 : LED aus\n2 : Daten Ausgeben\n3 : Daten Schreiben\n4 : AusgabePuffer aktualisieren\n5 : Programm Beenden\n\n&quot;);<br />      printf(&quot;Ihre Wahl?:   &quot;);<br />      cin &gt;&gt; wtd;<br />      nBytes = -1;<br />      switch(wtd){<br />      case USB_LED_OFF   :   nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, USB_LED_ON    , 0, 0, (char *)buffer, sizeof(buffer), 5000);         continue;<br />      case USB_LED_ON      :   nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, USB_LED_OFF   , 0, 0, (char *)buffer, sizeof(buffer), 5000);         continue;<br />      case USB_DATA_OUT   :   nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, USB_DATA_OUT  , 0, 0, (char *)buffer, sizeof(buffer), 5000);<br />                        printf(&quot;\nEmpfangene Bytes: %d \nInhalt: %s\n&quot;, nBytes, buffer);                                                                     continue;<br />      case USB_DATA_WRITE   :   cin &gt;&gt; inputbuffer;   <br />                        cout &lt;&lt; endl &lt;&lt; &quot;Ihre Eingabe: &quot; &lt;&lt; inputbuffer &lt;&lt; endl;<br />                        nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, USB_DATA_WRITE, 0, 0, inputbuffer, strlen(inputbuffer)+1, 5000);      continue;<br />      case USB_DATA_ACT   :   nBytes = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, USB_DATA_ACT  , 0, 0, (char *)buffer, sizeof(buffer), 5000);         continue;<br />      case 5            :   loop = false; nBytes = 0; break;<br />   <br />      }<br /><br />      <br />      if(nBytes &lt; 0)      // fehlerbehandlung<br />      {<br />         fprintf(stderr, &quot;USB error: %sn&quot;, usb_strerror());<br />      }<br />   <br />      <br />   }</code></pre></div><br /><br /><br />The problem is, the usbFunctionWrite doesnt get called...<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=14473">cocojack</a> — Wed Dec 19, 2012 6:01 pm</p><hr />
]]></content>
	</entry>
	</feed>
