- 1、本文档共7页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
《Code and Life – AVR ATtiny USB Tutorial Part 4》.pdf
Home | Electronics | Raspberry Pi | V-USB tutorials | Reviews | General | Web coding
February AVR ATtiny USB Tutorial Part 4
4
2012 Electronics , V-USB tutorials 59 Comments or trackbacks
All right. Now that we got the basic USB code working in part 3, it’s time to wrap things up in this tutorial
series. This fourth section will explain how to send data from your device to PC and also the other way
around. I may later do a fifth part on how to make a USB HID device like a keyboard or mouse, so if you
haven’t already, I’d recommend subscribing to the RSS feed to get updates.
Sending data f rom device to PC
If you look carefully at our command-line client code, you probably noticed that the control messages sent
to toggle the led are of type USB_ENDPOINT_IN and we have a 256-byte buffer in place to receive any data
the device sends. So far we have not received any data and the return value stored in nBytes has been
zero. Let’s change that.
If you read through the documentation in usbdrv/usbdrv.h, more specifically the comments for
usbFunctionSetup() we used to toggle our LED on device side, you can see that there are two ways to
return data from usbFunctionSetup():
1. Set the global pointer usbMsgPtr to a (static RAM) memory block and return the length of data from the
function
2. Define usbFunctionRead() function to do it yourself
We will be using the first method. First we define an additional message USB_DATA_OUT and a static buffer
to store the data we want to send from device to PC:
#define USB_DATA_OUT 2
static uchar replyBuf[16] Hello, USB!;
Then we add a new case to usbFunctionSetup() to return the contents of that buffer:
case USB_DATA_OUT: // send data to PC
usbMsgPtr replyBuf;
return sizeof(replyBuf);
Whoa, that was easy! V-USB does all the rest for us.
Now
您可能关注的文档
- 《castel_Valves》.pdf
- 《CCNP实验大全--Single_Area_OSPF(简版)》.pdf
- 《CDK Corp Profile Broch (CN-8.5x11) 041311 (Single Pgs)》.pdf
- 《CEIBS_Part-time_Finance_MBA_Programme》.pdf
- 《CEM_Time-Cost-Quality Trade-Off Analysis for Highway Construction》.pdf
- 《Center Still Holds》.pdf
- 《CentOS 6.2下Socket编程总结》.pdf
- 《CentOS 7 安装教程、硬盘分区、LVM、网络配置、软件源配置、制作USB Disk、U盘安装、网络安装》.pdf
- 《CEREBYX® (Fosphenytoin Sodium Injection)》.pdf
- 《CET-6 Translation》.ppt
文档评论(0)