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

	<title>Objective Development Forums</title>
	
	<link href="https://forums.obdev.at/index.php" />
	<updated>2012-01-10T06:14:40+02:00</updated>

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

		<entry>
		<author><name><![CDATA[ulao]]></name></author>
		<updated>2012-01-10T06:14:40+02:00</updated>

		<published>2012-01-10T06:14:40+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=6337&amp;p=20633#p20633</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=6337&amp;p=20633#p20633"/>
		<title type="html"><![CDATA[Re: sample project, write 512 bytes to controller]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=6337&amp;p=20633#p20633"><![CDATA[
you can set it in chunks like so. <br /><br />while (!usbInterruptIsReady()){ usbPoll(); }usbSetInterrupt((void *)&amp;reportBuffer + 0, <img class="smilies" src="./../../../images/smilies/icon_cool.gif" alt="8)" title="Cool" />;<br />while (!usbInterruptIsReady()){ usbPoll(); }usbSetInterrupt((void *)&amp;reportBuffer + 8, <img class="smilies" src="./../../../images/smilies/icon_cool.gif" alt="8)" title="Cool" />; <br />while (!usbInterruptIsReady()){ usbPoll(); }usbSetInterrupt((void *)&amp;reportBuffer + 16, <img class="smilies" src="./../../../images/smilies/icon_cool.gif" alt="8)" title="Cool" />; <br />while (!usbInterruptIsReady()){ usbPoll(); }usbSetInterrupt((void *)&amp;reportBuffer + 24, <img class="smilies" src="./../../../images/smilies/icon_cool.gif" alt="8)" title="Cool" />; <br />while (!usbInterruptIsReady()){ usbPoll(); }usbSetInterrupt((void *)&amp;reportBuffer + 32, <img class="smilies" src="./../../../images/smilies/icon_cool.gif" alt="8)" title="Cool" />; ...<br /><br />if you want to send more at once you need to abuse 1.0 standards. You would need to try this<br /><!-- l --><a class="postlink-local" href="http://forums.obdev.at/viewtopic.php?f=8&amp;t=4776&amp;p=16050#p16050">viewtopic.php?f=8&amp;t=4776&amp;p=16050#p16050</a><!-- l --><br /><br />Maybe using bulk in will allow it but I dont have any experience with that. <br /><br />512 maybe pushing it a bit....<p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=1281">ulao</a> — Tue Jan 10, 2012 6:14 am</p><hr />
]]></content>
	</entry>
		<entry>
		<author><name><![CDATA[ageurtse]]></name></author>
		<updated>2012-01-08T10:51:46+02:00</updated>

		<published>2012-01-08T10:51:46+02:00</published>
		<id>https://forums.obdev.at/viewtopic.php?t=6337&amp;p=20618#p20618</id>
		<link href="https://forums.obdev.at/viewtopic.php?t=6337&amp;p=20618#p20618"/>
		<title type="html"><![CDATA[sample project, write 512 bytes to controller]]></title>

		
		<content type="html" xml:base="https://forums.obdev.at/viewtopic.php?t=6337&amp;p=20618#p20618"><![CDATA[
Hello, <br /><br />i'm a newby on this forum. <br />I read and search the forum but i can't find some answers on my problem's <br /><br />i build a test project around an ATmega8 running on 12Mhz attached is an lcd, backlight goes through the pwm. (schematic by lcd2usb project)<br /><br />1) is it possible to send 512 bytes of data to the controller? (this is becaus i wan't to make an interface to a glcd)<br />2) is it possible to send more than 8 bytes at once to the controller ?<br />3) when i write 255 bytes, according to the output to the display all datapackets are writen. but when i use buffer[255] to control the backlight this won't work, what could be the cause of this?<br /><br /><br />you have to see this project, more as a learning project. I'm pretty new in C++ normaly i am a hobby programmer in Delphi. so the program on windows side is written in Delphi <img class="smilies" src="./../../../images/smilies/icon_smile.gif" alt=":)" title="Smile" /><br /><br /><br /><div class="codebox"><p>Code: </p><pre><code>/* Name: main.c<br /> * Project: custom-class, a basic USB example<br /> * Author: Christian Starkjohann<br /> * Creation Date: 2008-04-09<br /> * Tabsize: 4<br /> * Copyright: (c) 2008 by OBJECTIVE DEVELOPMENT Software GmbH<br /> * License: GNU GPL v2 (see License.txt), GNU GPL v3 or proprietary (CommercialLicense.txt)<br /> * This Revision: $Id: main.c 790 2010-05-30 21:00:26Z cs $<br /> */<br /><br />/*<br />This example should run on most AVRs with only little changes. No special<br />hardware resources except INT0 are used. You may have to change usbconfig.h for<br />different I/O pins for USB. Please note that USB D+ must be the INT0 pin, or<br />at least be connected to INT0 as well.<br />We assume that an LED is connected to port B bit 0. If you connect it to a<br />different port or bit, change the macros below:<br />*/<br /><br />#include &lt;avr/eeprom.h&gt;<br />#include &lt;avr/io.h&gt;<br />#include &lt;avr/wdt.h&gt;<br />#include &lt;avr/interrupt.h&gt;  /* for sei() */<br />#include &lt;util/delay.h&gt;     /* for _delay_ms() */<br /><br />#include &lt;avr/pgmspace.h&gt;   /* required by usbdrv.h */<br />#include &quot;usbdrv.h&quot;<br />#include &quot;oddebug.h&quot;        /* This is also an example for using debug macros */<br />#include &quot;requests.h&quot;       /* The custom request numbers we use */<br /><br />#include &quot;lcd.h&quot;<br /><br />#ifndef EEMEM<br />// alle Textstellen EEMEM im Quellcode durch __attribute__ ... ersetzen<br />#define EEMEM  __attribute__ ((section (&quot;.eeprom&quot;)))<br />#endif<br /> <br />/* bitmask of detected lcd controllers */<br />uchar controller = 0;<br /><br />/* ------------------------------------------------------------------------- */<br />/* PWM units are used for contrast and backlight brightness */<br /><br />/* contrast and brightness are stored in eeprom */<br />uchar eeprom_valid EEMEM;<br />uchar eeprom_contrast EEMEM;<br />uchar eeprom_brightness EEMEM;<br /><br />static uchar buffer&#91;512&#93;;<br />static uchar currentPosition, bytesRemaining;<br /><br />struct {<br />  uchar report_id;<br />  unsigned short offset;<br />  uchar len;<br />} cmd_state;<br /><br /><br />void pwm_init(void) {<br /><br />  /* check if eeprom is valid and set default values if not */<br />  /* initial values: full contrast and full brightness */<br />  if(eeprom_read_byte(&amp;eeprom_valid) != 0x42) {<br /><br />    /* write magic &quot;eeprom is valid&quot; marker 0x42 and default values */<br />    eeprom_write_byte(&amp;eeprom_valid, 0x42);<br />    eeprom_write_byte(&amp;eeprom_contrast, 0xff);<br />    eeprom_write_byte(&amp;eeprom_brightness, 0xff);<br />  }<br /><br />  /* PortB: set DDB1 and DDB2 =&gt; PORTB1 and PORTB2 are output */<br />  DDRB |= _BV(1) | _BV(2);<br /> <br />  /* Set Timer1:<br />    - Fast PWM,8bit =&gt; Mode 5 (WGM13=0,WGM12=1,WGM11=0,WGM10=1)<br />    - Output-Mode: lower voltage is higher contrast<br />      =&gt; Set OC1A on Compare Match, clear OC1A at BOTTOM, (inverting mode)<br />    COM1A1=1,COM1A0=1<br />    higher voltage is higher brightness<br />      =&gt; Clear OC1B on Compare Match, set OC1B at BOTTOM, (non-inverting mode)<br />    COM1B1=1,COM1B0=0<br />    - Timer runs at inernal clock with no prescaling =&gt; CS12=0,CS11=0,CS10=1<br />  */<br />  TCCR1A = _BV(COM1A1) | _BV(COM1A0) | _BV(COM1B1) | _BV(WGM10);<br />  TCCR1B = _BV(WGM12) | _BV(CS10);<br /><br />  TIMSK &amp;=( (~_BV(2)) &amp; (~_BV(3)) &amp; (~_BV(4)) &amp; (~_BV(5)));<br /><br />  OCR1A = eeprom_read_byte(&amp;eeprom_contrast);<br />  OCR1B = eeprom_read_byte(&amp;eeprom_brightness);<br />}<br /><br />void set_contrast(uchar value) {<br />  /* store value in eeprom if it actually changed */<br />  if(value != eeprom_read_byte(&amp;eeprom_contrast))<br />    eeprom_write_byte(&amp;eeprom_contrast, value);<br /><br />  OCR1A = value;  // lower voltage is higher contrast<br />}<br /><br />void set_brightness(uchar value) {<br />  /* store value in eeprom if it actually changed */<br />  if(value != eeprom_read_byte(&amp;eeprom_brightness))<br />    eeprom_write_byte(&amp;eeprom_brightness, value);<br /><br />  OCR1B = value;  // higher voltage is higher brightness<br />}<br /><br /><br /><br />/* ------------------------------------------------------------------------- */<br />/* ----------------------------- USB interface ----------------------------- */<br />/* ------------------------------------------------------------------------- */<br /><br />usbMsgLen_t usbFunctionSetup(uchar data&#91;8&#93;)<br />{<br />usbRequest_t    *rq = (void *)data;<br />static uchar    dataBuffer&#91;4&#93;;  /* buffer must stay valid when usbFunctionSetup returns */<br /><br /><br />    if(rq-&gt;bRequest == CUSTOM_RQ_ECHO){ /* echo -- used for reliability tests */<br />        dataBuffer&#91;0&#93; = rq-&gt;wValue.bytes&#91;0&#93;;<br />        dataBuffer&#91;1&#93; = rq-&gt;wValue.bytes&#91;1&#93;;<br />        dataBuffer&#91;2&#93; = rq-&gt;wIndex.bytes&#91;0&#93;;<br />        dataBuffer&#91;3&#93; = rq-&gt;wIndex.bytes&#91;1&#93;;<br />        usbMsgPtr = dataBuffer;         /* tell the driver which data to return */<br />        return 4;<br />    }<br /><br />   if(rq-&gt;bRequest == 1){<br />      currentPosition = 0;                // initialize position index<br />          lcd_clrscr(LCD_CTRL_0);<br />        lcd_puts(LCD_CTRL_0, &quot;start &quot;);<br /><br /><br />      bytesRemaining = rq-&gt;wLength.word;  // store the amount of data requested<br />        if(bytesRemaining &gt; sizeof(buffer)) // limit to buffer size<br />            bytesRemaining = sizeof(buffer);<br />        return USB_NO_MSG;        // tell driver to use usbFunctionWrite()   <br />      }<br /><br />   if(rq-&gt;bRequest == 2){<br />      lcd_clrscr (LCD_CTRL_0);<br />        return 0;        // tell driver to use usbFunctionWrite()   <br />      }<br /><br />    return 0x00;   /* default for not implemented requests: return no data back to host */<br />}<br /><br /><br />uchar usbFunctionWrite(uchar *data, uchar len)<br />{<br />    uchar i;<br /> <br />   if(len &gt; bytesRemaining)            // if this is the last incomplete chunk<br />       len = bytesRemaining;               // limit to the amount we can store<br /><br /><br />   lcd_puts(LCD_CTRL_0, &quot;.&quot;);   <br /><br />    bytesRemaining -= len;<br />    for(i = 0; i &lt; len; i++)<br />        buffer&#91;currentPosition++&#93; = data&#91;i&#93;;<br /><br />   if (bytesRemaining ==0)<br />   lcd_puts(LCD_CTRL_0, &quot; stop&quot;);   <br /><br />   return bytesRemaining == 0;             // return 1 if we have all data<br /><br /><br />      <br /><br />}<br /><br /><br /><br /><br /><br /><br />/* ------------------------------------------------------------------------- */<br /><br />int __attribute__((noreturn)) main(void)<br />{<br />uchar   i;<br /><br />    wdt_enable(WDTO_1S);<br />    /* Even if you don't use the watchdog, turn it off here. On newer devices,<br />     * the status of the watchdog (on/off, period) is PRESERVED OVER RESET!<br />     */<br />    /* RESET status: all port bits are inputs without pull-up.<br />     * That's the way we need D+ and D-. Therefore we don't need any<br />     * additional hardware initialization.<br />     */<br />    odDebugInit();<br />    DBG1(0x00, 0, 0);       /* debug output: main starts */<br />    lcd_init(LCD_CTRL_0);<br />   usbInit();<br /><br /><br />   pwm_init();<br /><br />    lcd_puts(LCD_CTRL_0, &quot;LCD2USB v1.2&quot;);<br /><br /><br />    usbDeviceDisconnect();  /* enforce re-enumeration, do this while interrupts are disabled! */<br />    i = 0;<br />    while(--i){             /* fake USB disconnect for &gt; 250 ms */<br />        wdt_reset();<br />        _delay_ms(1);<br />    }<br />    usbDeviceConnect();<br />   <br />    sei();<br />    DBG1(0x01, 0, 0);       /* debug output: main loop starts */<br />    for(;;){                /* main event loop */<br />        wdt_reset();<br />        usbPoll();<br />      set_brightness(buffer&#91;63&#93;);<br />    }<br />}<br /><br />/* ------------------------------------------------------------------------- */<br /><br /></code></pre></div><p>Statistics: Posted by <a href="https://forums.obdev.at/memberlist.php?mode=viewprofile&amp;u=6237">ageurtse</a> — Sun Jan 08, 2012 10:51 am</p><hr />
]]></content>
	</entry>
	</feed>
