PDIUSBD12
USB数据通信接口模块的元器件选型

USB数据通信接口模块的元器件选型本模块选用USB 接口芯片为Philips 公司生产的PDIUSBD 12 芯片,由于设计的需要,下面对该芯片进行简单的描述。
PDIUSBD 12 是一款性价比很高的USB 器件,它通常用作微控制器系统中实现与微控制器进行通信的高速通用并行接口,它还支持本地的DMA 传输。
1.芯片工作方式PDIUSBD12 可编程为单周期DMA 或突发模式DMA。
在单周期DMA 中DMREQ 在每单个应答后直到被DMACK N 重新激活之前保持无效。
在突发模式DMA 中DMREQ 在器件中突发编程时一直保持有效。
该过程持续到PDIUSBD12 通过E0T N 接收到一个DMA 终止信息,这时产生一个中断指示本地CPU,DMA 操作已经完成。
在DMA 读操作时,DMREQ 仅当缓冲区完全表示主机成功地发送了一个信息包到PDIUSBD12 时才有效。
由于具有双缓冲,配置主机可以在第一个缓冲区被读出时对第二个缓冲区进行填充,这种并行的处理有效地增加了数据吞吐量。
当主机没有完全填满缓冲区的情况下(单向ISO 配置时小于64 或128 字节),DMREQ 会在缓冲区的最后一个字节时无效,而不管当前的DMA 突发计数。
在更新了DMA 突发计数的下一个包发送时,DMREQ 再次被激活。
DMA 的写操作与之相似,当缓冲区未装满时,DMREQ 一直有效;当缓冲区填满时,下一个IN 标志将信息包送入主机,当传输完成之后DMREQ 变为无效。
同样,双缓冲配置也改善了数据的吞吐量。
在非同步传输中(批量模式和中断),在数据被发送到主机之前,缓冲区需要通过DMA 写操作完全装满。
惟一的例外是,在DMA 传输结束时,EOT N 接收的信号将会停止DMA 写操作并且在下一个IN 标志置位时将缓冲区的内容传送到主机。
USB接口信号发生器-英文资料及翻译

英文资料及中文翻译PDIUSBD12----USB interface device with parallel busThe PDIUSBD12 is a cost and feature optimized USB device. It is normally used in microcontroller based systems **municates with the system microcontroller over the high-speed general purpose parallel interface. It also supports local DMA transfer.This modular approach to implementing a USB interface allows the designer to choose the optimum system microcontroller from the available wide variety. This flexibility cuts down the development time, risks, and costs by allowing the use of the existing architecture and minimize firmware investments.This results in the fastest way to develop the most cost effective USB peripheral solution.The PDIUSBD12 fully conforms to the USB specification Rev. 2.0 (basic speed). It is also designed to be compliant with most device class specifications: Imaging Class, Mass Storage Devices, Communication Devices, Printing Devices, and Human Interface Devices.Assuch, the PDIUSBD 12 is ideally suited for many peripherals like Printer, Scanner, External Mass Storage (Zip Drive), Digital Still Camera, etc. It offers an immediate cost reduction for applications that currently use SCSI implementations.The PDIUSBD12 low suspend power consumption along with the Lazy Clock output allowsfor easy implementation of equipment that is compliant to the ACPI(TM),OnNOW(TM), and USB power management requirements. The low operating power allows the implementation of bus powered peripherals. In addition; it also incorporates features like SoftConnect(TM), GoodLink(TM), programmable clock output, low frequency crystal oscillator, and integration of termination resistors. All of these features contribute to significant cost savings in the system implementation and at the same time ease the implementation of advanced USB functionality into the peripherals.1. DMA transferDirect Memory Address (DMA) allows an efficient transfer of a block of data between ingaDMAcontroller, data transfer between thePDIUSBD12’s main endpoint (endpoint 2) and local shared memory can happen autonomously without local CPU intervention.Preceding any DMA transfer, the local CPU receives from the host the necessary setup information and programs the DMA controller accordingly. Typically, the DMA controller is set up for demand transfer mode and the byte count register and the address counter are programmed with the right values. In this mode, transfers occur only when the PDIUSBD12 requests them and are terminated when the byte count register reaches zero. After the DMA controller has been programmed, the DMAenable bit of the PDIUSBD12 is set by the local CPU to initiate the transfer.The PDIUSBD12 can be programmed for single-cycle DMA or burst mode DMA. In single-cycle DMA, the DMREQ pin is deactivated for every single acknowledgement by the DMACK_N before being re-asserted. In burst mode DMA, the DMREQ pin is kept active for the number of bursts programmed in the device before going inactive.This process continues until the PDIUSBD12 receives a DMA termination notice through pin EOT_N. This will generate an interrupt to notify the local CPU that DMA operation is completed.For DMA read operation,the DMREQ pin will only be activated whenever the buffer is full, signalling that the host has successfully transferred a packet to the PDIUSBD12.With the double buffering scheme, the host can start filling up the second buffer while the first buffer is being read out. This parallel processing increases the effective throughput.When the host does not fill up the **pletely (lessthan64 bytesor 128 bytes for single direction ISO configuration), the DMREQ pin will be deactivatedat the last byte of the buffer regardless of the current DMA burst count. It will be re-asserted on the next packet with a refreshed DMA burst count.Similarly, for DMA write operations, the DMREQ pin remains active whenever the buffer is not full. When the buffer is filled up, the packet is sent over to the host on the next IN token and DMREQ will be reactivated if the transfer was successful. Also, the double buffering scheme here will improve throughput. For non-isochronous transfer (bulk and interrupt), the buffer needs to be completely filled up by the DMA writeoperation before the data is sent to the host. The only exception is at the end of DMA transfer, when the reception of pin EOT_N will stop DMA write operation and the buffer content will be sent to the host on the next IN token.For isochronous transfers, the local CPU and DMA controller have to guarantee that they are able to sink or source the maximum packet size in one USB frame (1 ms).The assertion of pin DMACK_Nautomatically selects the main endpoint (endpoint 2), regardless of the current selected endpoint. The DMA operation of the PDIUSBD12 can be interleaved with normal I/O access to other endpoints.DMA operation can be terminated by resetting the DMA enable register bit or the assertion of EOT_N together with DMACK_N and either RD_N or WR_N.The PDIUSBD12 supports DMA transfer in single address mode and it can also work in dual address mode of the DMA controller. In the single address mode, DMA transfer is done via the DREQ, DMACK_N, EOT_N, WR_N and RD_N control lines. In the dual address mode, pins DMREQ, DMACK_N and EOT_N are not used; instead CS_N, WR_N and RD_N control signals are used. The I/O mode Transfer Protocol of PDIUSBD12 needs to be followed. The source of the DMAC is accessed during the read cycle and the destination during the write cycle. Transfer needs to be done in two separate bus cycles, storing the data temporarily in the DMAC. Command description2. Command procedureThere are three basic types of commands: Initialization, Data Flow and GeneralCommands. Respectively, these are used to initialize the function; for data flow between the function and the host; and some **mands.** **mands**mands are used during the enumeration process of the USB network. **mands are used to enable the function endpoints. They are also used to set the USB assigned address.⑴Set Address/EnableCode (Hex):D0Transaction: write 1 byte**mand is used to set the USB assigned address and enable the function.⑵Set endpoint enableCode (Hex):D8Transaction: write 1 byteThegeneric/Isochronous endpoints can only been abled when the function is enabled via the Set Address/**mand.⑶Set modeCode (Hex):F3Transaction: write 2 bytesThe Set **mand is followed by two data writes. The first byte contains the configuration bits. The second byte is the clock division factor byte.⑷CLOCK DIVISIONThe value indicates the clock division factor for CLKOUT. The FACTOR output frequency is 48 MHz/(N+1) where N is the Clock Division Factor. The reset value is 11. This will produce the output frequency of 4 MHz which can then be programmed up or down by the user. The minimum value is 1 giving the range of frequency from 4 to 24 MHz. The minimum value of N is 0, giving a maximum frequency of 48 MHz.The maximum value of N is 11 giving a minimum frequency of 4 MHz.The PDIUSBD12 design ensures no glitching during frequency change. The programmed value will not be changed by a bus reset.⑸Set DMACode (Hex): FBTransaction: read/write 1 byteThe set **mand is followed by one data write/read to/from the DMA configuration register.DMA Configuration register: During DMA operation, the two-byte buffer header (status and byte length information) is not transferred to/from the local CPU. This allows DMA data to be continuous and not interleaved by chunks of this headers.For DMA read operations, the header will be skipped by the PDIUSBD12. For DMA write operations, the header will be automatically added by the PDIUSBD12. This provides for a clean and simple DMA data transfer.** Data **mandsData **mands are used to manage the data transmission between the USB endpoints and the external microcontroller. Much of the data flow is initiated via an interrupt to the microcontroller. The microcontroller utilizes **mands to access and determine whether the endpoint FIFOs have valid data.⑴Read interrupt registerCode (Hex):F4Transaction: read 2 bytes**mand indicates the origin of an interrupt. The endpoint interrupt bits (bits 0 to 5) are cleared by reading the endpoint last transaction status register through Read Last Transaction **mand. The other bits are cleared after reading the interrupt registers.⑵Select EndpointCode (Hex):00 to 05Transaction: read 1 byte (optional)The Select **mand initializes an internal pointer to the start of the selected buffer. Optionally, **mand can be followed by a data read, which returns this byte.FULL/EMPTY: A ‘1’ indicates the buffer is full, ‘0’ indicates an empty buffer.STALL: A ‘1’ indicates the selected endpoint is in the stall state.Fig 11. Select **mand: bit allocation.⑶Read Endpoint statusCode (Hex):80 to 85Transaction: read 1 byte⑷Read last transaction status registerCode (Hex):40 to 45Transaction: read 1 byteThe Read Last Transaction **mand is followed by one data read that returns the status of the last transaction of the endpoint. **mand also resets the corresponding interrupt flag in the interrupt register, and clears the status, indicating that it was read.**mand is useful for debugging purposes. Since it keeps track of every transaction, the status information is overwritten for each new transaction.⑸Read bufferCode (Hex):F0Transaction: read multiple bytes (max. 130)The Read **mand is followed by a number of data reads, which returns the contents of the selected endpoint data buffer. After each read, the internal buffer pointer is incremented by 1.The buffer pointer is not reset to the top of the buffer by the Read **mand.This means that reading or writing a buffer can be interrupted by any **mand (except for Select Endpoint).The data in the buffer are organized as follows:* byte 0: reserved; can have any value* byte 1: number/length of data bytes* byte 2: data byte 1* byte 3: data byte 2* etc.The first two bytes will be skipped in the DMA read operation. Thus, the first read will get Data byte 1, the second read will get Data byte 2, etc. The PDIUSBD12 can determine the last byte of this packet through the EOP termination of the USB packet.⑹Write bufferCode (Hex):F0Transaction: write multiple bytes (max. 130)The Write **mand is followed by a number of data writes, which load the endpoints buffer. The data must be organized in the same way as described in the Read **mand. The first byte (reserved) should always be ‘0’.During DMA writes operation, the first two bytes will be bypassed. Thus, the first write will write into Data byte 1, the second write will write into Data byte 2, etc.For non-isochronous transfer(bulk or interrupt), the buffer should be completely filled before the data is sent to the host and a switch to the next buffer occurs. The exception is at the end of DMA transfer indicated by activation of EOT_N, when the current buffer content (completely full or not) will be sent to the host.Remark: There is no protection against writing or reading ov er a buffer’s boundary or against writing into an OUT buffer or reading from an IN buffer. Any of these actions could cause an incorrect operation.Data in an OUT buffer are only meaningful after asuccessful transaction.The exception is during DMA operation on the main endpoint (endpoint 2), in which case the pointer is automatically pointed to the second buffer after reaching the boundary (double buffering scheme).⑺Clear bufferCode (Hex):F2Transaction: noneWhen a packet is **pletely, an internal endpoint buffer full flag is set. All Subsequent packets will be refused by returning a NAK.When the microcontroller has read the data, it should free the buffer by the Clear **mand. When the bufferis cleared, new packets will be accepted.⑻Validate bufferCode (Hex): FATransaction: noneWhen the microprocessor has written data into an IN buffer, it should set the buffer full flag by the Validate **mand. This indicates that the data in the buffer are valid and can be sent to the host when the next IN token is received.⑼Set endpoint statusCode (Hex):40 to 45Transaction: write 1 byteA stalled control endpoint is automatically unstalled when it receives a SETUP token, regardless of the content of the packet. If the endpoint should stay in its stalled state, the microcontroller can re-stall it.When a stalled endpoint is unstalled (either by the Set Endpoint **mand or by receiving a SETUP token), it is also re-initialized. This flushes the buffer and if it is an OUT buffer it waits for a DATA 0 PID, if it is an IN buffer it writes a DATA 0 PID.Even when unstalled, writing Set Endpoint Status to ‘0’ initializes the endpoint.** **mandsSend resumeCode (Hex):F6Transaction:noneSends an upstream resume signal for 10 ms.**mand is normally issued when the device is in suspend. The **mand is not followed by a data read or write.Read current frame numberCode (Hex):F5Transaction:read 1 or 2 bytes**mand is followed by one or two data reads and returns the frame number of the last successfully received SOF. The frame number is returned Least Significant byte first.PDIUSBD12带并行总线的USB接口器件PDIUSBD12是一款性价比很高的USB器件,它通常用作微控制器系统中实现与微控制器进行通信的高速通用并行接口,它还支持本地的DMA传输。
USB驱动程序

PDIUSBD12 USB 仿真试验及驱动程序一.实验目的PDIUSBD12(简称D12)USB 芯片符合USB1.1 协议,广泛应用于各种的USB 设备。
本实验程序展示了如何在Small RTOS51 操作系统中实现D12 驱动程序的编写。
示例主要实现了如下功能:USB 设备的枚举,通过D12 的端点2 接受来自上位机的数据,并通过单片机的串口转发回上位机,同时驱动ZLG7290 显示0~9 的数字。
二.实验设备及器件PC 机一台DP-51PROC 单片机综合仿真实验仪一台USB D12 PARK 模块一台USB 连接线一根三.实验步骤1.D12 PARK 插到A6 区的排针内;2.使用导线把A2 区的INT1 与A6 区的P1_INT0 相连;3.使用导线把A2 区的T0 与A6 区的P1_IO2 相连;4.使用导线把A2 区的T1 与A6 区的P1_IO5 相连;5.使用导线把A2 区的A15 与A6 区的P1_CS 1 相连;6.使用导线把A2 区的P16、P17 分别与D5 区的SCL、SDA 相连;7.使用导线把A2 区的P10 与D5 区的/RST 相连,并短接D5 区的JP1;8.使用导线连接A2 区的P14 与B10 区的ZDJ_A;9.B10 区的ZDJ_B 连接到C1 的GND;10.短接B10 区JP18 的电机电源跳线四.实验参考程序主要部分/**************************************************************Small RTOS(51)The Real-Time Kernel(For Keil c51)(c) Copyright 2002-2004, chenmingjiAll Rights ReservedV1.20***************************************************************/#include "config.h"/**************************************************************声明全局变量**********************************************************/extern EPPFLAGS bEPPflags; /*USB 事件标志*/extern uint8 xdata GenEpBuf[]; /*信号包缓冲区(命令区)*/extern uint8 xdata EpBuf[]; /*信号包缓冲区(数据区)*/extern uint16 data D12_DATA; /*D12 数据的地址变量*/extern uint16 data D12_COMMAND; /*D12 命令的地址变量*///指针的NULL 为0,这个变量占用0 地质避免出现有效的NULL 指针uint8 OS_Q_MEM_SEL NotUse _at_ 0x0000;uint8 xdata ShowCase[8];uint8 xdata PWMH; //高电平脉冲的个数uint8 xdata PWM; //PWM 周期uint8 xdata COUNTER;uint8 key_buf[2];void enumerate_task(void);void USB_REC_task(void);void change_speed_task(void);void get_key_task(void);void INTT1() interrupt 3{COUNTER++;if(COUNTER < PWMH){P1_4 = 1; //P1.4 变为高电平}else{P1_4 = 0;}}void usb_ISR(void) interrupt 2{OS_INT_ENTER();EX1 = 0;OSSemIntPost(D12_isr);OSIntExit();}/************************************************************名称:init_port()**功能:端口初始化,D12SUSPD 复位为0****************************************************************/ void init_Hard(){P0 = 0XFF;P1 = 0XFF;P2 = 0XFF;P3 = 0XFF;D12SUSPD = 0;}/**************************************************************** 函数名称: init** 功能描述: 初始化函数,一般在多任务环境启动前调用**************************************************888**************/ void init(void){TMOD &= 0XF0;TMOD |= 0X01;// 每10ms 发生一次T0 中断TL0 = (65536 - (11059200 / 12) / 100) % 256;TH0 = (65536 - (11059200 / 12) / 100) / 256;ET0 = 1;TR0 = 1;PT0 = 0;EA = 1;}void control_init(void){PWMH=0x00;COUNTER=0x01;PWM=255;TMOD = TMOD & 0x0f;TMOD = TMOD | 0x20; //定时器1 在模式2 下工作TL1=0x00;TH1=0x00; //自动重装的值TR1=1;ET1 = 1;}/**************************************************************** 函数名称: void init_display(void)** 功能描述: 初始化LED 显示*****************************************************************/ void init_display(void){uint8 i;ZLG7290_RST = 0;_nop_();_nop_();ZLG7290_RST = 1;for (i = 0; i < 8; i++){ShowCase[i] = 31;}ZLG7290_SendBuf(ShowCase,8);}void main(void){OSInit();init_Hard(); /*初始化硬件*/init();control_init();IT1 = 0;EX1 = 1;PX1 = 1;init_display();D12_DATA = 0x7002; /*定义数据地址*/D12_COMMAND = 0x7003; /*定义命令地址*/D12_SetDMA(0x0); /*不使用DMA 功能*/bEPPflags.value = 0; /*初始化USB 寄存器*/OSTaskCreate(USB_REC_task , NULL , 0); //创建USB 中断处理任务while(1){PCON = PCON |0x01 ; /* CPU 进入休眠状态*/}}/************************************************************* ** 函数名称: void enumerate(void)** 功能描述: 完成USB 请求处理的任务************************************************************/ void enumerate_task(void){//创建其他优先级低的任务OSTaskCreate(get_key_task, NULL,2);OSTaskCreate(change_speed_task, NULL,3);while(1){OSWait(K_TMO, 2);IT1 = 0;EX1 = 1;reconnect_USB();while(USB_VIN){usbserve();OSWait(K_TMO, 1);}}}/********************************************************* 函数名称: void USB_REC(void)** 功能描述: USB 中断处理任务**************************************************************/ void USB_REC_task(void){OSSemCreate(D12_isr , 0);OSSemCreate(D12_use , 1);OSTaskCreate(enumerate_task , NULL ,1); //创建USB 请求处理任务while(1){OSSemPend(D12_isr , 0);OSSemPend(D12_use , 0);fn_usb_isr();OSSemPost(D12_use);EX1=1;}}/************************************************************* ** 函数名称: void change_speed_task(void)** 功能描述: 修改马达速度任务。
基于PDIUSBD12的USB控制器的设计

基于PDIUSBD12的USB控制器的设计
USB是一种新型的通用串行总线,它具有即插即用、可热插拔和传输速率高的特点,在工业界已经获得了广泛的支持和应用。
迄今为止,各种USB 的外设已有上千种,除了象显卡这种需要极高数据量和实时性要求特别高的控制设备,几乎所有的PC外设都可以移植到USB上来。
一般的USB设备都使用一片微控制器作为其核心部件,通过微控制器强火的控制和运算功能,开发者可以很容易地实现USB设备的智能化。
而嵌入式设备的实时、小巧等特性使得USB的协议栈和总线驱动的开发设计显得尤为重要,因为它的好坏会直接对USB主机产生影响,从而会对嵌入式系统性能和稳定产生较大影响。
本文以PDIUSBD12为USB接口芯片,以AT89C52为控制器,给出了一种USB接口的设计方法。
1 PDIUSBD12芯片介绍
PHILIPS公司生产PDIUSBD12接口芯片是一款性价比很高的USB器件,它通常通过其高速并行接口进行和微控制器通信,支持本地的DMA传输,支持3个USB端点,其中一个端点128B容量,另外2个端点具有256B容量。
该器件允许在众多可用的微控制器中选择最合适的系统控制器可,允许使用现存的体系结构并使设备软件投资成本减少,是开发低成本,高效率的USB外围设备的最佳途径。
PDIUSBD12特性:
(1) 符合通用串行总线USB1.1版规范
(2)高性能USB接口器件集成了SIE FIFO存储器收发器以及电压调整器 (3) 符合大多数器件的分类规格
(4) 可与任何外部微控制器/微处理实现高速并行接口2M字节/秒。
采用PDIUSBD12的USB系统固件程序设计(1)解析

采用PDIUSBD12的USB系统固件程序设计(1)摘要:在设计USB系统的过程中,固件程序的编写是非常重要的一个环节,它直接影响到开发产品的数据传输速度。
以Phillips公司的USB控制芯睡PDIUSBD12为例,介绍了在设计开发USB 外设中。
固件的作用以及固件程序的编写流程,并给出了相应程序。
关键词:USB 固件程序 PDIUSBD12 端点单片机USB(Universal Serial Bus)即通用串行总线,是现在非常流行的一种快速、双向、廉价、可以进行热插拨的接口,在现在的每一台PC机上都可以找到一对USB接口。
在遵循 USB1.1规范的基础上,USB接口最高传输速度可达12Mb/s:而在最新的USB2.0规范下,更可以达到480Mb/s.同时它可以连接127个 USB设备,而且连接的方式也十分灵活,既可以使用串行连接,也可以使用集线器(Hub)把多个设备连接在一起,再同PC机的USB接口相连.此外,它还可以从系统中直接汲取电流,无需单独的供电系统.USB的这些特点使它获得了广泛的应用.但是使用上的方便则意味着开发上的复杂,主要是编程的复杂性大大的增加了.在设计开发一个USB外设的时候,开发者主要需要编写三部分的程序: ①固件程序;②USB驱动程序;③客户应用程序.本文主要阐述固件程序的编写.1 固件要完成的主要工作固件是FIREWARE的对应中文词,它实际上是单片机的程序文件,其编写语言可以采用C语言或是汇编语言.它的操作方式与硬件联系紧密,包括 USB设备的连接USB协议、中断处理等,它不是单纯的软件,而是软件和硬件的结合,开发者需要对端口、中断和硬件结构非常熟悉。
固件程序一般放入MCU 中,当把设备连接到主机上(USB连接线插入插孔)时,上位机可以发现新设备,然后建立连接。
因此。
编写固件程序的一个最主要的目的就时让Windows 可以检测和识别设备。
2 PDIUSBD12芯片特点PDIUSBD12是一个性能优化的USB器件,通常用于基于微控制器的系统,并通过高速通用并行接口与微控制器进行通信,而且支持本地DMA传输。
PDIUSBD12 USB接口芯片C代码

#include "PDIUSBD12.H"
/********************************************************************
函数功能:D12写命令。
入口参数:Command:一字节命令。
返 回:无。
备 注:无。
********************************************************************/
D12SetWr(); //WR置高
D12SetPortIn(); //将数据口设置为输入状态,以备后面输入使用
}
////////////////////////End of function//////////////////////////////
/********************************************************************
D12WriteCommand(D12_READ_BUFFER); //发送读缓冲区的命令
D12ReadByte(); //该字节数据是保留的,不用。
j=D12ReadByte(); //这里才是实际的接收到的数据长度
if(j>Len) //如果要读的字节数比实际接收到的数据长
{
入口参数:Value:要写的一字节数据。
返 回:无。
备 注:无。
********************************************************************/
void D12WriteByte(uint8 Value)
PDIUSBD12开发的一些问题集合

同意上面的说法,
为了可靠,你可以把INF文件中和你想卸载的驱动程序相关的。INF,OEM*。INF和DERIVER下的驱动都删掉,也把注册表中的也删了。一定成功。
你可以先调试你的程序看到底调用了UNLOAD了没有?一般PNP硬件插入PC机,windows系统首先是在inf文件夹里搜索相应的.inf,所以你应当从控制面板里卸载driver,在把inf文件夹你的inf删除掉。
PDIUSBD12开发的一些问题集合.txt每个女孩都曾是无泪的天使,当遇到自己喜欢的男孩时,便会流泪一一,于是坠落凡间变为女孩,所以,男孩一定不要辜负女孩,因为女孩为你放弃整个天堂。朋友,别哭,今夜我如昙花绽放在最美的瞬间凋谢,你的泪水也无法挽回我的枯萎~~~PDIUSBD12开发的一些问题集合
3 外设再一次接收到GetDescriptor请求。主机分析描述符的信息。主机操作系统根据描述符信息寻找相应的设备驱动程序。
4 操作系统会继续发出GetConfiguration请求,读取设备的配置信息。要把外设的各个端点的配置情形回送到主机中。如果有多个配置信息,有多次请求发生。
5 在设备能通讯前,主机给外设一个SetConfiguration请求,主机根据整个系统的USB使用情况确认设备的哪一个配置有效,告诉其怎样工作,设备收到后调整有关配置,使设备能合理使用。
我是菜鸟,真心请教各位了谢谢
A:把windows\\inf目录下的oem*.inf打开,找到,你的那个,因为系统会吧它改名为oem*.inf,*是不确定的,然后把它删掉。要在没插硬件的时候。然后把windows\\system32\\drivers目录下你的的驱动程序也删掉,就行了,注册表不用管。
经过上面的调试后,USB外设可以发送和接收数据,设备如果不立即使用则会进入挂起状态,直到使用。
PDIUSBD12

1.General descriptionThe PDIUSBD12is a cost-and feature-optimized USB peripheral controller.It is normally used in microcontroller-based systems and communicates with the system microcontroller over the high-speed general-purpose parallel interface. It also supports local DMA transfer.This modular approach to implementing a USB interface allows the designer to choose the optimum system microcontroller from the wide variety available. This flexibility cuts down development time, risks and costs, by allowing the use of the existing architecture,minimizing firmware investments. This results in the fastest way to develop the most cost-effective USB peripheral solution.The PDIUSBD12fully conforms to Universal Serial Bus Specification Rev.2.0,supporting data transfer at full-speed (12Mbit/s).It is also designed to be compliant with most device class specifications: imaging class, mass storage devices, communication devices,printing devices and human interface devices. The PDIUSBD12 is ideally suited for many peripherals, such as printer, scanner, external mass storage (Zip drive) and digital still camera. It offers an immediate cost reduction for applications that currently use SCSI implementations.The PDIUSBD12low suspend power consumption along with the LazyClock output allows for easy implementation of equipment that is compliant to the ACPI, OnNow and USB power management requirements.The low operating power allows the implementation of bus powered peripherals.It also incorporates features,such as SoftConnect,GoodLink,programmable clock output,low frequency crystal oscillator, and integration of termination resistors. All of these features contribute to significant cost savings in the system implementation and at the same time ease the implementation of advanced USB functionality into peripherals.2.Featuress Complies with Universal Serial Bus specification Rev.2.0s Supports data transfer at full-speed (12Mbit/s)s High performance USB peripheral controller with integrated SIE, FIFO memory,transceiver and voltage regulators Compliant with most device class specificationss High-speed (2MB/s) parallel interface to any external microcontroller or microprocessors Fully autonomous DMA operations Integrated 320B of multi-configuration FIFO memoryPDIUSBD12Universal Serial Bus peripheral controller with parallel busRev. 09 — 11 May 2006Product data sheets Double buffering scheme for main endpoint increases throughput and eases real-time data transfers Data transfer rates: 1MB/s achievable in bulk mode, 1Mbit/s achievable inisochronous modes Bus-powered capability with very good EMI performances Controllable LazyClock output during suspends Software-controllable connection to the USB bus (SoftConnect)s Good USB connection indicator that blinks with traffic (GoodLink)s Programmable clock frequency outputs Complies with the ACPI, OnNow and USB power management requirementss Internal Power-On Reset (POR) and low-voltage reset circuits Available in SO28 and TSSOP28 pin packagess Full industrial grade operation from−40°C to +85°Cs Full-scan design with high fault coverage (>99%) ensures high qualitys Operation with dual voltages: 3.3V±0.3V or extended 5V supply range of4.0V to5.5Vs Multiple interrupt modes to facilitate both bulk and isochronous transfers3.Ordering informationTable 1.Ordering informationOutside North America North America Package TemperaturerangeVersion Name DescriptionPDIUSBD12D PDIUSBD12D SO28plastic small outline package;28leads;body width 7.5mm−40°C to +85°C SOT136-1PDIUSBD12PW PDIUSBD12PW DH TSSOP28plastic thin shrink small outlinepackage; 28leads; body width 4.4mm−40°C to +85°C SOT361-14.Block diagram5.Pinning information5.1PinningThis is a conceptual block diagram and does not include each individual signal.Fig 1.Block diagram6 MHzD+D −PLLSoftConnectD+3.3 V1.5 k Ω004aaa796VOLTAGE REGULATORANALOG TX/RXPARALLEL AND DMA INTERFACEMEMORY MANAGEMENTUNITINTEGRATEDRAMPHILIPS SIEBIT CLOCK RECOVERYUPSTREAM PORTFig 2.Pin configurationPDIUSBD12DATA0A0DATA1VOUT3.3DATA2D+DATA3D −GND V CC DATA4XTAL2DATA5XTAL1DATA6GL_N DATA7RESET_N ALE EOT_N CS_N DMACK_N SUSPEND DMREQ CLKOUT WR_N INT_N RD_N004aaa532123456789101112131416151817201922212423262528275.2Pin descriptionTable 2.Pin descriptionSymbol Pin Type[1]DescriptionDA T A01IO2bit0 of bidirectional data; slew-rate controlledDA T A12IO2bit1 of bidirectional data; slew-rate controlledDA T A23IO2bit2 of bidirectional data; slew-rate controlledDA T A34IO2bit3 of bidirectional data; slew-rate controlledGND5P groundDA T A46IO2bit4 of bidirectional data; slew-rate controlledDA T A57IO2bit5 of bidirectional data; slew-rate controlledDA T A68IO2bit6 of bidirectional data; slew-rate controlledDA T A79IO2bit7 of bidirectional data; slew-rate controlledALE10I Address Latch Enable: The falling edge is used to close the latch ofthe address information in a multiplexed address or data bus.Permanently tied to LOW for separate address or data busconfiguration.CS_N11I chip select (active LOW)When the CS_N pin is LOW, ensure that the RESET_N pin is ininactive state; otherwise, the device will enter test mode.SUSPEND12I, OD4device is in the suspend stateCLKOUT13O2programmable output clock (slew-rate controlled)INT_N14OD4interrupt (active LOW)RD_N15I read strobe (active LOW)WR_N16I write strobe (active LOW).DMREQ17O4DMA requestDMACK_N18I DMA acknowledge (active LOW)EOT_N19I end of DMA transfer (active LOW); double up as V BUS sensing.EOT_N is only valid when asserted together with DMACK_N andeither RD_N or WR_N.RESET_N20I reset (active LOW and asynchronous); built-in power-on reset circuitis present on-chip, so the pin can be tied HIGH to V CCWhen the RESET_N pin is LOW, ensure that the CS_N pin is ininactive state; otherwise, the device will enter test mode.GL_N21OD8GoodLink LED indicator (active LOW)XT AL122I crystal connection1 (6MHz)XT AL223O crystal connection2 (6MHz); if the external clock signal, instead ofthe crystal, is connected to XTAL1, then XTAL2 should be floated V CC24P voltage supply (4.0V to5.5V)To operate the IC at3.3V,supply3.3V to both the V CC and VOUT3.3pins.D−25A USB D− data lineTable 2.Pin description …continuedSymbol Pin Type[1]DescriptionD+26A USB D+ data lineVOUT3.327P 3.3V regulated output; to operate the IC at 3.3V, supply a 3.3V toboth the V CC and VOUT3.3 pinsA028I address bitA0=1 —Selects the command instructionA0=0 —selects the data phaseThis bit is a don’t care in a multiplexed address and data busconfiguration and should be tied to HIGH.[1]P:power or ground;A:analog;I:input;O:Output;O2:Output with2mA drive;OD4:Output open-drain with4mA drive; OD8: Output open-drain with 8mA drive; IO2: Input and output with 2mA drive; O4: Output with 4mA drive.6.Functional description6.1Analog transceiverThe integrated transceiver directly interfaces to USB cables through termination resistors.6.2Voltage regulatorA 3.3V regulator is integrated on-chip to supply the analog transceiver. This voltage isalso provided as an output to connect to the external1.5kΩpull-up resistor.Alternatively,the PDIUSBD12 provides the SoftConnect technology with an integrated 1.5kΩ pull-upresistor.6.3PLLA 6MHz-to-48MHz clock multiplier Phase-Locked Loop (PLL) is integrated on-chip. Thisallows the use of a low-cost 6MHz crystal. ElectroMagnetic Interference (EMI) is alsominimized because of the lower frequency crystal. No external components are neededfor the operation of the PLL.6.4Bit clock recoveryThe bit clock recovery circuit recovers the clock from the incoming USB data stream using4×over-sampling principle. It can track jitter and frequency drift specified by UniversalSerial Bus Specification Rev.2.0.6.5Philips Serial Interface Engine (PSIE)The Philips SIE implements the full USB protocol layer. It is completely hardwired forspeed and needs no firmware intervention. The functions of this block include:synchronization pattern recognition,parallel or serial conversion,bit stuffing or discardingstuffed bits, CRC checking or generation, PID verification or generation, addressrecognition, and handshake evaluation or generation.6.6SoftConnectThe connection to the USB is accomplished by connecting D+(for full-speed USB device)to HIGH through a 1.5kΩ pull-up resistor. In the PDIUSBD12, the 1.5kΩ pull-up resistoris integrated on-chip and is not connected to V CC by default. The connection isestablished through a command sent by the external or system microcontroller. Thisallows the system microcontroller to complete its initialization sequence before deciding toestablish connection to the USB. Re-initialization of the USB bus connection can also beperformed without requiring to pull out the cable.The PDIUSBD12 will check for USB V BUS availability before the connection can beestablished.The V BUS sensing is provided using pin EOT_N.For details,see Section5.2.Sharing of the V BUS sensing and EOT_N can be easily accomplished by using the V BUSvoltage as the pull-up voltage for the normally open-drain output of the DMA controller pin.Remark:The tolerance of internal resistors is higher (25%) than that specified inUniversal Serial Bus Specification Rev.2.0(5%).The overall voltage specification for theconnection,however,can still be met with good margin.The decision to make sure of thisfeature lies with users.6.7GoodLinkA good USB connection indication is provided through the GoodLink technology. During enumeration, the LED indicator will momentarily blink on corresponding to theenumeration traffic. When the PDIUSBD12 is successfully enumerated and configured,the LED indicator will be permanently on.Subsequent successful (with acknowledgment)transfer to and from the PDIUSBD12 will blink off the LED. During suspend, the LED will be off.This feature provides a user-friendly indication on the status of the USB device, the connected hub and the USB traffic. It is a useful field diagnostics tool to isolate faulty equipment. This feature helps lower field support and hotline costs.6.8Memory Management Unit (MMU) and integrated RAMThe difference between MMU and the integrated RAM buffer lies in the speed between USB, running in bursts of 12Mbit/s and the parallel interface to the microcontroller. This allows the microcontroller to read and write USB packets at its own speed.6.9Parallel and DMA interfaceA generic parallel interface is defined for ease-of-use and speed, and allows directinterfacing to major microcontrollers. To a microcontroller, the PDIUSBD12 appears as a memory device with 8-bit data bus and 1-bit address line (occupying two locations). The PDIUSBD12 supports both multiplexed and non-multiplexed address and data bus. The PDIUSBD12 also supports Direct Memory Access (DMA) transfer that allows the main endpoint (endpoint 2) to directly transfer to and from the local shared memory. Both single-cycle and burst mode DMA transfers are supported.6.10Example of parallel interface to an 80C51 microcontrollerIn the example shown in Figure 3, the ALE pin is permanently tied to LOW to signify a separate address and data bus configuration. The A0 pin of the PDIUSBD12 connects to any of the 80C51 I/O ports. This port controls the command or data phase to thePDIUSBD12. The multiplexed address and data bus of the 80C51 can now be directly connected to the data bus of the PDIUSBD12. The address phase will be ignored by the PDIUSBD12. The clock input signal of the 80C51 (pin XTAL1) can be provided by output CLKOUT of the PDIUSBD12.Fig 3.Example of a parallel interface to an 80C51 microcontrollerPDIUSBD1280C51INT_NA0DATA [7:0]WR_N RD_N CLKOUT CS_N ALEXTAL1RD/P3.7WR/P3.6P [0.7:0.0]/AD [7:0]ANY I/O PORT (for example, P3.3)INTO/P3.2004aaa155ANY I/O PORT7.Direct Memory Access (DMA) transferDMA allows an efficient transfer of a block of data between the host and local sharedmemory. Using a DMA Controller (DMAC), the data transfer between the main endpoint(endpoint2) of the PDIUSBD12 and the local shared memory can occur autonomously,without the local CPU intervention.Preceding any DMA transfer, the local CPU receives from the host the necessary setupinformation and accordingly programs the DMA controller.Typically,the DMA controller isset up for demand transfer mode, and the Byte Count register and the address counterare programmed with the correct values. In this mode, transfers occur only when thePDIUSBD12 requests them and are terminated when the Byte Count register reacheszero.After the DMA controller is programmed,the DMA ENABLE bit of the PDIUSBD12isset by the local CPU to initiate the transfer.The PDIUSBD12 can be programmed for single-cycle DMA or burst mode DMA. Insingle-cycle DMA, the DMREQ pin is deactivated for every single acknowledgment byDMACK_N before being re-asserted. In burst mode DMA, the DMREQ pin is kept activefor the number of bursts programmed in the device before going inactive. This processcontinues until the PDIUSBD12 receives a DMA termination notice through pin EOT_N.This will generate an interrupt to notify the local CPU that the DMA operation iscompleted.For the DMA read operation,the DMREQ pin will only be activated whenever the buffer isfull,signaling that the host has successfully transferred a packet to the PDIUSBD12.Withthe double buffering scheme, the host can start filling up the second buffer while the firstbuffer is being read out.This parallel processing increases the effective throughput.Whenthe host does not completely fill up the buffer (less than 64B or 128B for single directionISO configuration), the DMREQ pin will be deactivated at the last byte of the buffer,regardless of the current DMA burst count.It will be re-asserted on the next packet with arefreshed DMA burst count.Similarly,for DMA write operations,the DMREQ pin remains active whenever the buffer isnot full.When the buffer isfilled up,the packet is sent over to the host on the next IN tokenand DMREQ will be reactivated if the transfer was successful. Also, the double bufferingscheme here will improve throughput. For non-isochronous transfer (bulk and interrupt),the buffer needs to be completelyfilled up by the DMA write operation before data is sentto the host. The only exception is at the end of DMA transfer, when the reception of theEOT_N pin will stop the DMA write operation and the buffer content will be sent to the hoston the next IN token.For isochronous transfers, the local CPU and DMA controller have to guarantee that theycan sink or source the maximum packet size in one USB frame (1ms).The assertion of pin DMACK_N automatically selects the main endpoint (endpoint2),regardless of the current selected endpoint. The DMA operation of the PDIUSBD12 canbe interleaved with normal I/O access to other endpoints.The DMA operation can be terminated by resetting the DMA ENABLE register bit or theassertion of EOT_N together with DMACK_N and either RD_N or WR_N.The PDIUSBD12 supports DMA transfer in single address mode and it can also work indual address mode of the DMA controller. In single address mode, the DMA transfer isdone using the DREQ, DMACK_N, EOT_N, WR_N and RD_N control lines. In dualaddress mode, pins DMREQ, DMACK_N and EOT_N are not used; instead CS_N,WR_N and RD_N control signals are used. The I/O mode transfer protocol of thePDIUSBD12 needs to be followed. The source of the DMAC is accessed during the readcycle and the destination during the write cycle.Transfer needs to be done in two separatebus cycles, temporarily storing data in the DMAC.8.Endpoint descriptionThe PDIUSBD12 endpoints are sufficiently generic to be used by various device classesranging from imaging, printer, mass storage and communication device classes. ThePDIUSBD12endpoints can be configured for four operating modes,depending on the SetMode command. The four modes are:Mode 0Non-isochronous transfer (Non-ISO mode)Mode 1Isochronous output only transfer (ISO-OUT mode)Mode 2Isochronous input only transfer (ISO-IN mode)Mode 3Isochronous input and output transfer (ISO-I/O mode)Table 3.Endpoint configurationEndpoint number Endpoint index Transfer type Direction[1]Max. Packet size (bytes) Mode0 (Non-ISO mode)00control OUT161IN1612generic[2]OUT163IN1624generic[2][3]OUT64[4]5IN64[4]Mode1 (ISO-OUT mode)00control OUT161IN1612generic[2]OUT163IN1624isochronous[3]OUT128[4]Mode2 (ISO-IN mode)00control OUT161IN1612generic[2]OUT163IN1625isochronous[3]IN128[4]Mode3 (ISO-I/O mode)00control OUT161IN1612generic[2]OUT163IN1624isochronous[3]OUT64[4]5IN64[4][1]IN: input for the USB host; OUT: output from the USB host.[2]Generic endpoints can be used either as bulk or interrupt endpoint.[3]The main endpoint (endpoint number2) is double-buffered to ease synchronization with real-timeapplications and to increase throughput. This endpoint supports DMA access.[4]Denotes double buffering. The size shown is for a single buffer.9.Main endpointThe main endpoint (endpoint number2) is the primary endpoint for sinking or sourcingrelatively large amounts of data. It implements the following features to ease this task:•Double buffering. This allows parallel operation between the USB access and thelocal CPU access, increasing throughput. Buffer switching is automatically handled.This results in transparent buffer operation.•DMA operation. This can be interleaved with normal I/O operation to other endpoints.•Automatic pointer handling during the DMA operation. No local CPU intervention isnecessary when ‘crossing’ the buffer boundary.•Configurable endpoint for either isochronous transfer or non-isochronous (bulk andinterrupt) transfer.mand summaryTable mand summaryName Destination Code (Hex)TransactionInitialization commandsSet Address/Enable device D0write 1BSet Endpoint Enable device D8write 1BSet Mode device F3write 2BSet DMA device FB write or read 1BData flow commandsRead Interrupt register device F4read 2BSelect Endpoint control OUT00read 1B (optional)control IN01read 1B (optional)endpoint1 OUT02read 1B (optional)endpoint1 IN03read 1B (optional)endpoint2 OUT04read 1B (optional)endpoint2 IN05read 1B (optional)Read Last T ransaction Status control OUT40read 1Bcontrol IN41read 1Bendpoint1 OUT42read 1Bendpoint1 IN43read 1Bendpoint2 OUT44read 1Bendpoint2 IN45read 1BRead Buffer selected endpoint F0read n BWrite Buffer selected endpoint F0write n Bmand description11.1Command procedureThere are three basic types of commands: initialization, data flow and general.Respectively, these are used to initialize the function; for data flow between the function and the host; and some general commands.11.2Initialization commandsInitialization commands are used during the enumeration process of the USB network.These commands are used to enable function endpoints. They are also used to set the USB assigned address.11.2.1Set Address/EnableCode (Hex) —D0Transaction —write 1BThis command is used to set the USB assigned address and enable the function.Set Endpoint Statuscontrol OUT 40write 1B control IN 41write 1B endpoint 1 OUT 42write 1B endpoint 1 IN 43write 1B endpoint 2 OUT 44write 1B endpoint 2 IN45write 1B Acknowledge Setup selected endpoint F1none Clear Buffer selected endpoint F2none Validate Buffer selected endpointFA none General commands Send ResumeF6none Read Current Frame NumberF5read 1 or 2BTable mand summary …continuedNameDestination Code (Hex)Transaction ADDRESS : The value written becomes the address.ENABLE : Logic 1 enables this function.Fig 4.Set Address/Enable command: bit allocation7654320100Power-on value ADDRESS ENABLE004aaa79700000011.2.2Set Endpoint EnableCode (Hex) —D8Transaction —write 1BThe generic or isochronous endpoints can only be enabled when the function is enabled using the Set Address/Enable command.11.2.3Set ModeCode (Hex) —F3Transaction —write 2BThe Set Mode command is followed by two data writes. The first byte contains configuration bits. The second byte is the clock division factor byte.GENERIC OR ISOCHRONOUS ENDPOINTS : Logic 1 indicates that generic or isochronous endpoints are enabled.Fig 5.Set Endpoint Enable command: bit allocation765432X 100Power-on valueGENERIC/ISOCHRONOUS ENDPOINTS reserved; write 0X X X X X X 004aaa798For bit allocation, see Table 5.Fig 6.Set Mode command, configuration byte: bit allocationPower-on value reserved NO LAZYCLOCK CLOCK RUNNING INTERRUPT MODE SoftConnect reserved; write 0ENDPOINT CONFIGURATION765432111001000004aaa799Table 5.Set Mode command, configuration byte: bit allocationBitSymbolDescription7 to 6ENDPOINTCONFIGURA TIONThese two bits set endpoint configurations as follows: Mode 0 (Non-ISO mode) Mode 1 (ISO-OUT mode) Mode 2 (ISO-IN mode) Mode 3 (ISO-I/O mode) For details, see Section 8.4SoftConnectLogic 1indicates that the upstream pull-up resistor will be connected if V BUS is available. Logic 0 means that the upstream resistor will not be connected. The programmed value will not be changed by a bus reset.3INTERRUPT MODELogic 1 indicates that all errors and ‘NAK’ are reported and willgenerate an interrupt.Logic 0indicates that only OK is reported.The programmed value will not be changed by a bus reset.2CLOCK RUNNINGLogic 1 indicates that internal clocks and PLL are always running even during the suspend state. Logic 0 indicates that the internal clock, crystal oscillator and PLL are stopped, whenever not needed.To meet the strict suspend current requirement,this bit must be set to logic 0. The programmed value will not be changed by a bus reset.1NO LAZYCLOCKLogic 1 indicates that CLKOUT will not switch to LazyClock. Logic 0indicates that CLKOUT switches to LazyClock 1ms after theSUSPEND pin goes HIGH. LazyClock frequency is 30kHz ±40%.The programmed value will not be changed by a bus reset.For bit allocation, see Table 6.Fig 7.Set Mode command, clock division factor byte: bit allocation7654321110Power-on value10X X 00CLOCK DIVISION FACTOR reserved 004aaa800SET_TO_ONESOF-ONLY INTERRUPT MODE11.2.4Set DMACode (Hex) —FBTransaction —read or write 1BThe Set DMA command is followed by one data write or read to or from the DMA Configuration register.11.2.4.1DMA Configuration registerDuring the DMA operation, the 2B buffer header (status and byte length information) is not transferred to or from the local CPU. This allows the DMA data to be continuous and not interleaved by chunks of these headers. For DMA read operations, the header will be skipped by the PDIUSBD12.See Section 11.3.5command.For DMA write operations,the header will be automatically added by the PDIUSBD12.This provides a clean and simple DMA data transfer.Table 6.Set Mode command, clock division factor byte: bit allocationBit SymbolDescription7SOF-ONL YINTERRUPT MODE Setting this bit to logic 1will cause the interrupt line to be activated because of the Start-Of-Frame (SOF) clock only, regardless of the setting of PIN-INTERRUPT MODE, bit 5 of Set DMA.6SET_TO_ONEThis bit must be set to logic 1 before any DMA read or DMA write operation. This bit should always be set to logic 1 after power. It is zero after power-on reset.3to 0CLOCK DIVISIONFACTORThe value indicates the clock division factor for CLKOUT . Theoutput frequency is 48MHz /(N +1), where N is the clock division factor. The reset value is 11. This will produce an output frequency of 4MHz that can then be programmed up or down by the user.The minimum value is 1, giving a frequency range of4MHz to 24MHz.The minimum value of N is 0,giving a maximum frequency of 48MHz. The maximum value of N is 11, giving aminimum frequency of 4MHz.The PDIUSBD12design ensures no glitching during frequency change. The programmed value will not be changed by a bus reset.For bit allocation, see Table 7.Fig 8.Set DMA command: bit allocationPower-on value INTERRUPT PIN MODEENDPOINT INDEX 4 INTERRUPT ENABLE ENDPOINT INDEX 5 INTERRUPT ENABLE7654320100000000DMA ENABLE DMA DIRECTION AUTO RELOAD DMA BURST 004aaa80111.3Data flow commandsData flow commands are used to manage the data transmission between USB endpoints and the external microcontroller.Much of the data flow is initiated using an interrupt to the microcontroller. The microcontroller utilizes these commands to access and determine whether endpoint FIFOs have valid data.11.3.1Read Interrupt registerCode (Hex) —F4Transaction —read 2BTable 7.Set DMA command: bit allocation Bit SymbolDescription7ENDPOINT INDEX 5INTERRUPT ENABLELogic 1 allows an interrupt to be generated whenever the endpoint buffer is validated (see Section 11.3.8 command).Normally turned off for the DMA operation to reduce unnecessary CPU servicing.6ENDPOINT INDEX 4INTERRUPT ENABLELogic 1 allows an interrupt to be generated whenever the endpoint buffer contains a valid packet. Normally turned off for the DMA operation to reduce unnecessary CPU servicing.5INTERRUPT PIN MODELogic 0 signifies a normal interrupt pin mode in which an interrupt is generated as a logical OR of all the bits in interrupt registers. Logic 1 signifies that the interrupt will occur when SOF clock is seen on the upstream USB bus.The other normal interrupts are still active.4AUTO RELOAD When this bit is set to logic 1, the DMA operation will automatically restart.3DMA DIRECTIONThis bit determines the direction of data flow during a DMA transfer.Logic 1means from the external shared memory to the PDIUSBD12 (DMA write); logic 0 means from the PDIUSBD12 to the external shared memory (DMA read).2DMA ENABLEWriting logic 1to this bit will start the DMA operation through the assertion of pin DMREQ.The main endpoint buffer must be full (for DMA read) or empty (for DMA write), before DMREQ is asserted. In single cycle DMA mode, the DMREQ is deactivated on receiving DMACK_N. In burst mode DMA, the DMREQ is deactivated after the number of burst is exhausted. It is then asserted again for the next burst. This process continues until EOT_N is assertedtogether with DMACK_N and either RD_N or WR_N, which will reset this bit to logic 0and terminate the DMA operation.The DMA operation can also be terminated by writing logic 0to this bit.1to 0DMA BURSTSelects the burst length for DMA operation: 00Single-cycle DMA 01Burst (4-cycle) DMA 10Burst (8-cycle) DMA 11Burst (16-cycle) DMAThis command indicates the origin of an interrupt. The endpoint interrupt bits (bits 0to 5)are cleared by reading the Endpoint Last Transaction Status register through Read Last Transaction Status command. The other bits are cleared after reading Interrupt registers.For bit allocation, see Table 8.Fig 9.Interrupt register, byte 1: bit allocationDMA EOT : This bit signifies that the DMA operation is completed.Fig 10.Interrupt register, byte 2: bit allocation Table 8.Read Interrupt register, byte 1: bit allocationBit SymbolDescription7SUSPEND CHANGEWhen the PDIUSBD12does not receive three SOFs,it will go into the suspend state and the SUSPEND CHANGE bit will be HIGH. Any change to the suspend or awake state will set this bit to HIGH and generate an interrupt.6BUS RESETAfter a bus reset, an interrupt will be generated and this bit will be logic 1. A bus reset is identical to a hardware reset through theRESET_N pin, except a bus reset generates an interrupt notification and the device is enabled at default address 0.Power-on valueMAIN OUT ENDPOINT MAIN IN ENDPOINT BUS RESET SUSPEND CHANGE7654320100000000CONTROL IN ENDPOINT ENDPOINT 1 OUT ENDPOINT 1 IN CONTROL OUT ENDPOINT 004aaa802765432X 100Power-on value DMA EOT reservedX X X X X X 004aaa803。
采用PDIUSBD12的USB系统固件程序设计解析

采用PDIUSBD12的USB系统固件程序设计摘要:在设计USB系统的过程中,固件程序的编写是非常重要的一个环节,它直接影响到开发产品的数据传输速度。
以Phillips公司的USB控制芯睡PDIUSBD12为例,介绍了在设计开发USB外设中。
固件的作用以及固件程序的编写流程,并给出了相应程序。
关键词:USB 固件程序 PDIUSBD12 端点单片机USB(Universal Serial Bus)即通用串行总线,是现在非常流行的一种快速、双向、廉价、可以进行热插拨的接口,在现在的每一台PC机上都可以找到一对USB接口。
在遵循USB1.1规范的基础上,USB接口最高传输速度可达12Mb/s:而在最新的USB2.0规范下,更可以达到480Mb/s.同时它可以连接127个USB设备,而且连接的方式也十分灵活,既可以使用串行连接,也可以使用集线器(Hub)把多个设备连接在一起,再同PC机的USB接口相连.此外,它还可以从系统中直接汲取电流,无需单独的供电系统.USB的这些特点使它获得了广泛的应用.但是使用上的方便则意味着开发上的复杂,主要是编程的复杂性大大的增加了.在设计开发一个USB外设的时候,开发者主要需要编写三部分的程序: ①固件程序;②USB驱动程序;③客户应用程序.本文主要阐述固件程序的编写.1 固件要完成的主要工作固件是FIREWARE的对应中文词,它实际上是单片机的程序文件,其编写语言可以采用C语言或是汇编语言.它的操作方式与硬件联系紧密,包括USB设备的连接USB协议、中断处理等,它不是单纯的软件,而是软件和硬件的结合,开发者需要对端口、中断和硬件结构非常熟悉。
固件程序一般放入MCU中,当把设备连接到主机上(USB连接线插入插孔)时,上位机可以发现新设备,然后建立连接。
因此。
编写固件程序的一个最主要的目的就时让Windows可以检测和识别设备。
2 PDIUSBD12芯片特点PDIUSBD12是一个性能优化的USB器件,通常用于基于微控制器的系统,并通过高速通用并行接口与微控制器进行通信,而且支持本地DMA传输。
PDIUSBD12 带并行总线的USB接口器件

2
广州周立功单片机发展有限公司 Tel: (020)38730976 38730977 Fax: 38730925
GoodLinkTM
GoodLinkTM 技术可提供良好的 USB 连接指示 在枚举中 LED 指示根据通信的状况间歇闪烁 当
PDIUSBD12 成功地枚举和配置后 LED 指示将一直点亮 随后与 PDIUSBD12 之间成功的传输 带应答
PDIUSBD12 所具有的低挂起功耗连同 LazyClock 输出可以满足使用 ACPI OnNOW 和 USB 电源管理 的要求 低的操作功耗可以应用于使用总线供电的外设
此外它还集成了许多特性 包括 SoftConnetTM GoodLinkTM 可编程时钟输出 低频晶振和终止寄存 器集合 所有这些特性都为系统显著节约了成本 同时使 USB 功能在外设上的应用变得容易
端点数
端点索引
0
0 1
1
2 3
2
4
传输类型
控制输出 控制输入 普通输出 普通输入 普通输出 普通输入
传输类型
控制输出 控制输入 普通输出 普通输入 同步输出
传输类型
控制输出 控制输入 普通输出 普通输入 同步输入
端点类型
默认 普通 普通 普通 普通
置位时将缓冲区的内容传送到主机
在同步模式中 本地 CPU 和 DMA 控制器必须保证它们在一个 USB 帧 1ms 中能够吞吐的最大信
息包的规模 DMACK_N 的激活将自动选择主端点 端点 2 而不管当前选择的端点 PDIUSBD12 的 DMA
操作可通过普通的 I/O 对其它端点的存取实现交叉存取 DMA 操作可通过以下方式终止 复位 DMA 使能
订购信息
51单片机与USB芯片PDIUSBD12接口固件程序

51单片机与USB芯片PDIUSBD12接口固件程序关键词:USB固件程序此函数库可以直接使用PHILIPS的Demo驱动D12TEST以下只用了端点1进行控制传输,端点2的数据传输自己添加,没有使用DMA功能,为简单的固件程序/************************************************************* *************PHILIPS PDIUSBD12 FIRMWARECOPYRIGHT (c) 2005 BY JJJ.-- ALL RIGHTS RESERVED --File Name: D12_USB.hAuthor: Jiang Jian JunCreated: 2005/4/3Modified: NORevision: 1.0************************************************************** *************/#ifndef __D12_USB_H_REVISION_FIRST__#define __D12_USB_H_REVISION_FIRST__#include <REGX51.H>sbit SUSPEND = P3^5;#define D12_INT_ENDP0OUT 0x0001 //中断寄存器位定义#define D12_INT_ENDP0IN 0x0002#define D12_INT_ENDP1OUT 0x0004#define D12_INT_ENDP1IN 0x0008#define D12_INT_ENDP2OUT 0x0010#define D12_INT_ENDP2IN 0x0020#define D12_INT_BUSRESET 0x0040#define D12_INT_SUSPENDCHANGE 0x0080#define D12_INT_EOT 0x0100#define D12_SETUPPACKET 0x20 //读最后处理状态寄存器的设置信息包0010, 0000b#define EP0_PACKET_SIZE 16 //p0最大16byte#define USB_ENDPOINT_DIRECTION_MASK 0x80 //设备请求类型,传输方向D 7 1000,0000b#define USB_REQUEST_TYPE_MASK 0x30 //bmRequest的设置#define USB_REQUEST_MASK 0x0f#define USB_STANDARD_REQUEST 0x00 //5,6位的定义#define USB_VENDOR_REQUEST 0x20#define USB_DEVICE_DESCRIPTOR_TYPE 0x01 //描述符类型设备描述符01h,配置描述符02,接口描述符04,端点描述符05#define USB_CONFIGURATION_DESCRIPTOR_TYPE 0x02#define CONFIG_DESCRIPTOR_LENGTH 0x002E //配置描述符总长度//************************************************************ **************//Port And Macros And Structure And Union Definitions#define SWAP(x) ((((x) & 0x00FF) << 8) | (((x) >> 8) & 0x00FF)) //交换高低8位#define MSB(x) (((x) >> 8) & 0x00FF) //取数据高8位#define LSB(x) ((x) & 0x00FF) //取数据低8位typedef union _Event_Flags_ //定义USB事件标志数据类型{struct _Bit_Flags_{unsigned char Timer : 1; //定时器益出事件标记unsigned char BusReset : 1; //USB总线复位标志unsigned char Suspend : 1; //USB器件挂起标志unsigned char SetupPacket : 1; //收到SETUP包标志unsigned char RemoteWakeup : 1; //远程唤醒标志unsigned char InISR : 1; //USB中断服务标志unsigned char ControlState : 2; //控制端点处理状态//0:IDEL 空闲状态//1:TRANSMIT 数据发送状态//2:RECEIVE 数据接受状态unsigned char Configuration : 1; //配置标志(0:未配置;1:已配置) unsigned char Port1RxDone : 1; //端口1收到数据标志unsigned char Port2RxDone : 1; //端口2收到数据标志unsigned char Port1TxFull : 1; //端口1输出缓冲区满标志unsigned char Port2TxFull : 1; //端口2输出缓冲区满标志unsigned char Reserve : 3; //保留,未使用}Bits;unsigned short int Value;}EVENT_FLAGS; //事件标志数据类型typedef struct _DEVICE_REQUEST_{unsigned char bmRequestType; //请求类型unsigned char bRequest; //USB请求unsigned short wValue; //USB请求值unsigned short wIndex; //USB请求索引unsigned short wLength; //记数长度}DEVICE_REQUEST;#define MAX_CONTROLDATA_SIZE 8typedef struct _control_xfer{DEVICE_REQUEST DeviceRequest; //USB请求结构体unsigned short wLength; //传输数据的总字节数unsigned short wCount; //传输字节数统计unsigned char * pData; //传输数据指针unsigned char dataBuffer[MAX_CONTROLDATA_SIZE]; //请求的数据}CONTROL_XFER;static EVENT_FLAGS EventFlags; //定义为全局变量,用于与主程序的通信static CONTROL_XFER ControlData; //保存SETUP包请求类型和请求数据unsigned char idata EndPoint1Buffer[4]; //控制端点缓存unsigned char idata EndPoint2Buffer[64];//主端点缓存//************************************************************ **************//硬件提取层,多路地址/数据总线方式读写void Outportb(unsigned int Addr, unsigned char Data){*((unsigned char xdata *) Addr) = Data;}unsigned char Inportb(unsigned int Addr){return *((unsigned char xdata *) Addr);}void USB_Delay1ms(unsigned int count){unsigned int i,j;for(i=0;i<count;i++)for(j=0;j<120;j++);}//************************************************************ **************#define D12_DATA 0#define D12_COMMAND 1//PDIUSBD12命令接口函数void D12_SetMode(unsigned char bConfig,unsigned char bClkDiv){Outportb(D12_COMMAND,0xF3);Outportb(D12_DATA,bConfig);Outportb(D12_DATA,bClkDiv);}//设置端点void D12_SetEndpointStatus(unsigned char bEndp,unsigned char bStalled) {Outportb(D12_COMMAND,0x40+bEndp);Outportb(D12_DATA,bStalled);}//应答!!!!!void D12_AcknowledgeEndpoint(unsigned char endp){Outportb(D12_COMMAND,endp);Outportb(D12_COMMAND,0xF1);if(endp==0)Outportb(D12_COMMAND,0xF2);}//设置地址使能void D12_SetAddressEnable(unsigned char bAddress,unsigned char bEnable) {Outportb(D12_COMMAND,0xd0);if(bEnable) bAddress |= 0x80;Outportb(D12_DATA,bAddress);}//设置端点使能void D12_SetEndpointEnable(unsigned char bEnable){Outportb(D12_COMMAND,0xD8);if(bEnable)Outportb(D12_DATA,1);elseOutportb(D12_DATA,0);}//读中断寄存器unsigned short D12_ReadInterruptRegister(void){unsigned char b1;unsigned int j;Outportb(D12_COMMAND,0xF4);b1=Inportb(D12_DATA);j=Inportb(D12_DATA);j<<=8;j+=b1;return j;}//读取端点状态unsigned char D12_ReadEndpointStatus(unsigned char EndPoint){unsigned char BackValue;if(EventFlags.Bits.InISR == 0)EA = 0;Outportb(D12_COMMAND, 0x80 + EndPoint);//读取端点状态BackValue = Inportb(D12_DATA);if(EventFlags.Bits.InISR == 0)EA = 1;return BackValue;}//读端点最后处理状态unsigned char D12_ReadLastTransactionStatus(unsigned char bEndp){Outportb(D12_COMMAND,0x40+bEndp);return Inportb(D12_DATA);}//读端口unsigned char D12_ReadEndpoint(unsigned char endp,unsigned char len,un signed char *buf){unsigned char i,j;Outportb(D12_COMMAND,endp);if((Inportb(D12_DATA)&0xff)==0)//" define D12_FULLEMPTY as 0xFF by newerreturn 0;Outportb(D12_COMMAND,0x80+endp);i=Inportb(D12_DATA);i=i&0x60;Outportb(D12_COMMAND,0xF0);j=Inportb(D12_DATA);j=Inportb(D12_DATA);if(j>len)j=len;for(i=0;i<j;i++)*(buf+i)=Inportb(D12_DATA);Outportb(D12_COMMAND,0xF2);return j;}unsigned char D12_ReadEndpoint_Int(unsigned char endp,unsigned char le n,unsigned char *buf){unsigned char i,j;Outportb(D12_COMMAND,endp);if((Inportb(D12_DATA)&0xff)==0)//" define D12_FULLEMPTY as 0xFF by newerreturn 0;Outportb(D12_COMMAND,0x80+endp);i=Inportb(D12_DATA);i=i&0x60;Outportb(D12_COMMAND,0xF0);j=Inportb(D12_DATA);j=Inportb(D12_DATA);if(j>len)j=len;for(i=0;i<j;i++)*(buf+i)=Inportb(D12_DATA);Outportb(D12_COMMAND,0xF2);return j;}unsigned char D12_WriteEndpoint(unsigned char endp,unsigned char len,un signed char * buf){unsigned char i;Outportb(D12_COMMAND,endp);Inportb(D12_DATA);Outportb(D12_COMMAND,0xF0);Outportb(D12_DATA,0);Outportb(D12_DATA,len);for(i=0;i<len;i++)Outportb(D12_DATA,*(buf+i));Outportb(D12_COMMAND,0xFA);return len;}unsigned char D12_WriteEndpoint_Int(unsigned char endp,unsigned char le n,unsigned char * buf){unsigned char i;Outportb(D12_COMMAND,endp);Inportb(D12_DATA);Outportb(D12_COMMAND,0xF0);Outportb(D12_DATA,0);Outportb(D12_DATA,len);for(i=0;i<len;i++)Outportb(D12_DATA,*(buf+i));Outportb(D12_COMMAND,0xFA);return len;}void DisconnectUSB(void){D12_SetMode(0x02,0x03);//SET TO ONE? by newer}void InitialUSBInt(void);void ConnectUSB(void){EventFlags.Value = 0x0000;InitialUSBInt();D12_SetMode(0x16,0x03);}void ReconnectUSB(void){SUSPEND = 0;DisconnectUSB();USB_Delay1ms(1000);ConnectUSB();}//************************************************************ **************//中断服务程序void InitialUSBInt(void){IT1=0; //低电平中断触发EX1=1; //允许外部中断PX1=0; //优先级低EA =1;}void EP0_Out(void){unsigned char ep_last,i;ep_last=D12_ReadLastTransactionStatus(0);//interrupt symbolif(ep_last&D12_SETUPPACKET){ //recieved SETUP packet ---by newerControlData.wLength=0;ControlData.wCount=0;if(D12_ReadEndpoint_Int(0,sizeof(ControlData.DeviceRequest),(unsigned ch ar *)(&(ControlData.DeviceRequest)))!=sizeof(DEVICE_REQUEST)){D12_SetEndpointStatus(0,1);D12_SetEndpointStatus(1,1);EventFlags.Bits.ControlState=0; //should define USB_IDLE first --by newerreturn;}acket=1;EventFlags.Bits.ControlState=0; //by newer}else{if(ControlData.DeviceRequest.wLength>16)//最大传16byte{EventFlags.Bits.ControlState=0; //by newerD12_SetEndpointStatus(0,1);D12_SetEndpointStatus(1,1);}else{EventFlags.Bits.ControlState=2;//by newer}}}}else if(EventFlags.Bits.ControlState==2){i=D12_ReadEndpoint_Int(0,EP0_PACKET_SIZE,ControlData.dataBuffer+Con trolData.wCount);ControlData.wCount+=i;if(i!=EP0_PACKET_SIZE||ControlData.wCount>=ControlData.wLength){EventFlags.Bits.SetupPacket=1;EventFlags.Bits.ControlState=0;}}elseEventFlags.Bits.ControlState=0;}void EP0_In(void){short i=ControlData.wLength-ControlData.wCount;D12_ReadLastTransactionStatus(1);if(EventFlags.Bits.ControlState!=1) return;if(i>=EP0_PACKET_SIZE){D12_WriteEndpoint_Int(1,EP0_PACKET_SIZE,ControlData.pData+ControlDat a.wCount);ControlData.wCount+=EP0_PACKET_SIZE;EventFlags.Bits.ControlState=1;return;}if(i!=0){D12_WriteEndpoint_Int(1,i,ControlData.pData+ControlData.wCount);ControlData.wCount+=i;EventFlags.Bits.ControlState=0;return;}D12_WriteEndpoint_Int(1,0,0);EventFlags.Bits.ControlState=0;}void EP1_Out(void){unsigned char Length;D12_ReadLastTransactionStatus(2); /* Clear interrupt flag */Length = D12_ReadEndpoint_Int(2, sizeof(EndPoint1Buffer),EndPoint1Buffe r);if(Length != 0)EventFlags.Bits.Port1RxDone = 1;}void EP1_In(void){D12_ReadLastTransactionStatus(3);}void EP2_Out(void){unsigned char Length,EP2Status;D12_ReadLastTransactionStatus(4); /* Clear interrupt flag */EP2Status = D12_ReadEndpointStatus(4);EP2Status&=0x60;Length = D12_ReadEndpoint(4,sizeof(EndPoint2Buffer),EndPoint2Buffer); if(EP2Status==0x60)Length = D12_ReadEndpoint(4,sizeof(EndPoint2Buffer),EndPoint2Buffer); if(Length != 0)EventFlags.Bits.Port2RxDone = 1;}void EP2_In(void){D12_ReadLastTransactionStatus(5); /* Clear interrupt flag */}//************************************************************ **************//请求处理typedef struct _usb_device_descriptor{unsigned char bLength;unsigned char bDescriptorType;unsigned int bcdUSB;unsigned char bDeviceClass;unsigned char bDeviceSubClass;unsigned char bDeviceProtocol;unsigned char bMaxPacketSize0;unsigned int idVendor;unsigned int idProduct;unsigned int bcdDevice;unsigned char iManufacturer;unsigned char iProduct;unsigned char iSerialNumber;unsigned char bNumConfiguations;}USB_DEVICE_DESCRIPTOR;code USB_DEVICE_DESCRIPTOR DeviceDescr={sizeof(USB_DEVICE_DESCRIPTOR),0x01,//USB_DEVICE_DESCRIPTOR_TYPE,SWAP(0x0100),0xDC,//USB_CLASS_CODE_TEST_CLASS_DEVICE,0, 0,EP0_PACKET_SIZE,SWAP(0x0471),SWAP(0x0666),SWAP(0x0100),0, 0, 0,25};//配置描述符typedef struct _usb_configuration_descriptor{unsigned char bLength[0x2e];}USB_CONFIGURATION_DESCRIPTOR;code USB_CONFIGURATION_DESCRIPTOR ConfigDescr={0x09,0x02,0x2e,0x00,0x01,0x01,0x00,0xa0,0x32,0x09,0x04,0x00,0x00,0x04,0xdc,0xa0,0xb0,0x00,0x07,0x05,0x81,0x03,0x02,0x00,0x0a,0x07,0x05,0x01,0x03,0x02,0x00,0x0a,0x07,0x05,0x82,0x02,0x40,0x00,0x0a,0x07,0x05,0x02,0x02,0x40,0x00,0x0a};//code_tramsitvoid code_transmit(unsigned char code *pRomData,unsigned short len) {ControlData.wCount=0;if(ControlData.wLength>len)ControlData.wLength=len;ControlData.pData=pRomData;if(ControlData.wLength>=EP0_PACKET_SIZE)D12_WriteEndpoint(1,EP0_PACKET_SIZE,ControlData.pData);ControlData.wCount+=EP0_PACKET_SIZE;EA = 0;EventFlags.Bits.ControlState=1;EA = 1;}else{D12_WriteEndpoint(1,ControlData.wLength,pRomData);ControlData.wCount+=ControlData.wLength;EA = 0;EventFlags.Bits.ControlState=0;EA = 1;}}//获取描述符void get_descriptor(void){if(MSB(ControlData.DeviceRequest.wValue)==USB_DEVICE_DESCRIPTOR_T YPE){code_transmit((unsigned char code*)&DeviceDescr,sizeof(USB_DEVICE_DE SCRIPTOR));return;}if(MSB(ControlData.DeviceRequest.wValue)==USB_CONFIGURATION_DESCR IPTOR_TYPE){if(ControlData.DeviceRequest.wLength>CONFIG_DESCRIPTOR_LENGTH)ControlData.DeviceRequest.wLength=CONFIG_DESCRIPTOR_LENGTH;//标识符总大小2E byte,第二次请求时wlength=0x00ff}//这里的ConfigDescr其实应该包括其他标识符!code_transmit((unsigned char code*)&ConfigDescr,ControlData.DeviceRequ est.wLength);return;}}//single transmitvoid single_transmit(unsigned char *buf,unsigned char len){if(len<=EP0_PACKET_SIZE){D12_WriteEndpoint(1,len,buf);}}//设置地址void set_address(void){D12_SetAddressEnable((unsigned char)(ControlData.DeviceRequest.wValue &0xff),1);//比如wValue是"02 00" 应该得到02single_transmit(0,0);}//设置配置void set_configuration(void){if(ControlData.DeviceRequest.wValue==0){single_transmit(0,0);EventFlags.Bits.Configuration=0;D12_SetEndpointEnable(0);}else if(ControlData.DeviceRequest.wValue==1){single_transmit(0,0);D12_SetEndpointEnable(0);D12_SetEndpointEnable(1);EventFlags.Bits.Configuration=1;}}//读取配置void get_configuration(void){unsigned char c=EventFlags.Bits.Configuration;single_transmit(&c,1);}//读取设备接口信息void get_interface(void){unsigned char txdat=0;single_transmit(&txdat,1);}static code void (*StandardDeviceRequest[])(void)= {0,0,0,0,0,set_address,get_descriptor,0,get_configuration,set_configuration,get_interface,0,0,0,0,0};static code void (*VendorDeviceRequest[])(void)={0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};void ControlHandler(void){unsigned char type,req;type=ControlData.DeviceRequest.bmRequestType&USB_REQUEST_TYPE_MA SK;//0011,0000breq=ControlData.DeviceRequest.bRequest&USB_REQUEST_MASK;//0000,11 11bif(type==USB_STANDARD_REQUEST)(*StandardDeviceRequest[req])();else if(type==USB_VENDOR_REQUEST)(*VendorDeviceRequest[req])();}void USB_ISR(void) interrupt 2{unsigned int i_st;EA = 0;EventFlags.Bits.InISR=1;i_st=D12_ReadInterruptRegister();if(i_st!=0){if(i_st&D12_INT_ENDP0OUT)EP0_Out();if(i_st&D12_INT_ENDP0IN)EP0_In();if(i_st&D12_INT_ENDP1OUT)EP1_Out();if(i_st&D12_INT_ENDP1IN)EP1_In();if(i_st&D12_INT_ENDP2OUT)EP2_Out();if(i_st&D12_INT_ENDP2IN)EP2_In();}EventFlags.Bits.InISR=0;EA = 1;}//************************************************************ **************#endif//简单主程序文件,自己按需要改写#include <REGX51.H>#include "D12_USB.h"extern EVENT_FLAGS EventFlags; //事件信号extern unsigned char idata EndPoint1Buffer[4];main(){ReconnectUSB();while(1){if(EventFlags.Bits.SetupPacket){EA = 0;EventFlags.Bits.SetupPacket = 0; ControlHandler();EA = 1;}if(EventFlags.Bits.Timer){EventFlags.Bits.Timer = 0;}if(EventFlags.Bits.Port1RxDone){EventFlags.Bits.Port1RxDone = 0; }}}那么可以写5个函数:void print();void copy();void delete();void quit();void help();然后用一个函数指针数组把他们存在一起:void (*p[])() = {print, copy, delete, quit, help}; 然后根据用户入0,1,2,3,4来直接叫函数cin >> index;p[index]();。
USB接口芯片PDIUSBD12与单片机AT89C51通信系统

USB接口芯片PDIUSBD12与单片机AT89C51通信系统目录文摘 (1)英文文摘 (1)1 绪论.............................................................1.1 课题背景.....................................................1.2 课题的提出...................................................1.3 USB简介......................................................1.4 主要工作.....................................................2 USB1.1协议 .........................................................2.1 USB的互连....................................................2.2 USB的主机....................................................2.2.1 USB主机概述..............................................2.2.2 USB驱动(USBD) ............................................2.3USB设备.......................................................2.3.1 USB设备状态..............................................2.3.2 通用USB设备操作..........................................2.3.3 USB设备请求..............................................2.4 USB的物理层..................................................2.5 USB数据流....................................................3 数据采集系统的固件设计 .............................................3.1 固件的开发环境...............................................3.2 采用PDIUSBD12的固件设计......................................3.2.1 固件要完成的主要工作.....................................3.2.2 PDIUSBD12芯片特点........................................3.2.3 PDIUSBD12固件程序的编写..................................3.3 固件的文件结构...............................................3.4 固件的编程实现...............................................3.4.1 底层函数.................................................3.4.2 命令接口.................................................3.4.3 中断服务程序ISR.C ........................................3.4.4 主循环MAINLOOP.C .........................................4 USB设备驱动程序设计 ................................................4.1 Windows2000驱动程序..........................................4.2 WDM驱动程序结构模型..........................................4.2.1 USB设备驱动程序层次结构..................................4.2.2设备对象..................................................4.2.3标准总线驱动程序和类驱动程序..............................4.2.4 WDM驱动程序的结构........................................4.3 USB驱动的开发环境............................................4.3.1 驱动的开发工具...........................................4.3.2 驱动开发环境的安装与设置.................................4.4 驱动程序的实现...............................................4.4.1 驱动入口.................................................4.4.2数据传输控制..............................................5 USB设备应用程序设计 ................................................5.1 Win32 API简介................................................5.2动态链接库....................................................5.3 MFC的应用程序开发............................................5.4设备应用程序与WDM的通信.......................................5.4.1 Win32应用程序对WDM的通信.................................5.4.2 WDM对Win32应用程序的通信.................................5.5 应用程序的实现...............................................6 数据采集系统的硬件设计 .............................................6.1 硬件系统的结构...............................................6.2 接口芯片选择.................................................6.3接口硬件设计................................................6.3.1 A/D与单片机接口电路......................................6.3.2 PDIUSBDI2与单片机接口电路................................1 绪论1.1 课题背景随着数字化的广泛应用,数据采集也越来越重要,传统的外设与主机的通信口一般采用ISA、PCI、C PCI、1394等标准,基于这些接口的产品,安装麻烦,价格昂贵,并受计算机插槽数量、地址中断资源限制,且可扩展性差,USB的出现,很好地解决了以上问题。
基于PDIUSBD12 的USB 设备固件程序开发

收稿日期:2003-12-09;修订日期:2004-02-24 作者简介:程斓(1980-),女,硕士研究生,主要研究方向:伪随机码雷达接收机硬件平台; 杨子杰(1943-),男,教授,博士生导师,主要研究方向:高频地波雷达海洋环境监测技术的总体设计.文章编号:1001-9081(2004)07-0150-03基于PDIUSBD 12的USB 设备固件程序开发程 斓,杨子杰(武汉大学电子信息学院,湖北武汉430079)(liena-520@ )摘 要:介绍了基于PDIUSBD 12芯片的USB 设备硬件组成,详细论述了USB 枚举的具体过程和基于PDIUSBD 12的MCU 固件编程思想,给出了部分单片机C 程序代码,分析了制约实际数据传输速率的原因,并提出了解决方法。
关键词:USB ;PDIUSBD 12;固件;枚举中图分类号:TP 311.11;TP 363.027 文献标识码:AFirmw are Progra mming of USB Device B ased on PDIUSBD 12CHENGLan ,Y ANG Zi 2jie(School of Electronic &Information ,Wuhan University ,Wuhan Hubei 430079,China )Abstract :This paper introduces the hardware constitution of a US B device based on PDIUS BD12.The emphasis is how to enumerate a US B device and how to program firmware.This paper offers parts of MCU C language programs ,analyses the reason why the real data trans fer speed is restricted ,and offers the solution.K ey words :US B ;PDIUS BD12;firmware ;enumerate1 硬件设计PDIUS BD12(以下简称D12)是在US B1.1协议[1]设备端使用最多的芯片之一。
PDIUSBD12 的接口应用设计

USB作为一种新型的接口技术,以其简单易用,速度快等特点而备受青睐.本文简单介绍USB接口的特点和PHILIPS 公司的USB 接口芯片PDIUSBD12,并详细说明USB 软硬件开发过程中应注意的问题。
引言USB是近年来应用在PC领域的新型接口技术,是一些PC 大厂商,如Microsoft、Intel 等为了解决日益增加的PC 外设与有限的主板插槽和端口之间的矛盾而制定的一种串行通信的标准,自1995年在Comdex上亮相以来,至今已广泛地为各PC厂家所支持现在生产的PC 几乎都配备了USB 接口。
Microsoft 的Windows98、NT以及MacOS、Linux、FreeBSD 等流行操作系统都增加了对USB 的支持。
USB 的主要优点:1.使用方便。
连接外设不必再打开机箱允许外设热插拔而不必关闭主机电源;2.速度快。
USB接口的最高传输率可达12 Mb/s;3.提供低速方式,速率为1.5 Mb/s 扣除用于总线状态控制和错误检测等数据传输,最大理论速度也能达到1.2 Mb/s 和9.6 Mb/s。
4.连接灵活。
一个USB 口理论上可以连接127个USB设备,连接的方式也十分灵活,既可以使用串行连接,也可以使用集线器Hub,把多个设备连接在一起,再同PC 机的USB 口相接。
5.独立供电。
USB 接口提供了内置电源。
现在的USB生产厂商很多,几乎所有的硬件厂商都有USB 的产品。
USB控制器一般有两种类型:一种是MCU 集成在芯片里面的如Intel 的8X930AX、CYPRESS的EZ-USB、SIEMENS的C541U以及MOTOLORA、National Semiconductors 等公司的产品。
另一种就是纯粹的USB接口芯片仅处理USB 通信如PHILIPS 的PDIUSBD11(I2C 接口)、PDIUSBP11A、PDIUSBD12(并行接口)、National Semiconductor的USBN9602、USBN9603、USBN9604等、前一种由于开发时需要单独的开发系统,因此开发成本较高;而后一种只是一个芯片与MCU接口实现USB通信功能,因此成本较低,而且可靠性高。
基于PDIUSBD12的USB控制器的设计

基于PDIUSBD12的USB控制器的设计USB是一种新型的通用串行总线,它具有即插即用、可热插拔和传输速率高的特点,在工业界已经获得了广泛的支持和应用。
迄今为止,各种USB 的外设已有上千种,除了象显卡这种需要极高数据量和实时性要求特别高的控制设备,几乎所有的PC外设都可以移植到USB上来。
一般的USB设备都使用一片微控制器作为其核心部件,通过微控制器强火的控制和运算功能,开发者可以很容易地实现USB设备的智能化。
而嵌入式设备的实时、小巧等特性使得USB的协议栈和总线驱动的开发设计显得尤为重要,因为它的好坏会直接对USB主机产生影响,从而会对嵌入式系统性能和稳定产生较大影响。
本文以PDIUSBD12为USB接口芯片,以AT89C52为控制器,给出了一种USB接口的设计方法。
1 PDIUSBD12芯片介绍 PHILIPS公司生产PDIUSBD12接口芯片是一款性价比很高的USB器件,它通常通过其高速并行接口进行和微控制器通信,支持本地的DMA传输,支持3个USB端点,其中一个端点128B容量,另外2个端点具有256B容量。
该器件允许在众多可用的微控制器中选择最合适的系统控制器可,允许使用现存的体系结构并使设备软件投资成本减少,是开发低成本,高效率的USB外围设备的最佳途径。
PDIUSBD12特性: (1) 符合通用串行总线USB1.1版规范 (2)高性能USB接口器件集成了SIE FIFO存储器收发器以及电压调整器 (3) 符合大多数器件的分类规格 (4) 可与任何外部微控制器/微处理实现高速并行接口2M字节/秒 (5) 完全自治的直接内存存取DMA操作 (6) 集成320字节多结构FIFO存储器 (7) 主端点的双缓冲配置增加了数据吞吐量并轻松实现实时数据传输 (8) 在批量模式和同步模式下均可实现1M字节/秒的数据传输速率 (9) 具有良好EMI特性的总线供电能力 (10) 在挂起时可控制LazyClock输出 (11) 可通过软件控制与USB的连接 (12) 采用GoodLink技术的连接指示器,在通信时使LED闪烁 (13) 可编程的时钟频率输出 (14) 符合ACPI OnNOW和USB电源管理的要求 (15) 内部上电复位和低电压复位电路 (16) 有SO28和TSSOP28两种封装 (17) 工业级操作温度-40~+85℃ (18) 高于8kV的在片静电防护电路减少了额外元件的费用 (19) 具有高错误恢复率(>99%)的全扫描设计确保了高品质 (20) 双电源操作3.3V或扩展的5V电源,范围为3.6~5.5V (21) 多中断模式实现批量和同步传输 2 USB通信模块的硬件电路的设计 本系统设计采用PDIUSBD12和AT89C52配合完成通信设计。
D12_USB开发使用说明

D12_USB接口设计1.1PDIUSBD12简介PDIUSBD12是Philips公司推出的一款特点突出的USB接口芯片。
该芯片使用8位并行数据线连接到MCU,1位地址线用来区分写命令或读写数据,他支持3个USB端点,1个端点能保存128 B,另2个能保存256 B。
PDIUSBD12完全遵从USB 1.1协议,他内部集成有串行接口引擎(SIE)、320 b FIFO存储器、收发器(Transceiver)和电压调节器。
还有可编程的时钟输出和状态LED输出(GoodLinkTM),可控制的软件连接(SoftConnectTM)以及内部上电复位和低电压复位电路。
有2种电源供电方式:内部3.3±0.3 V电源和外部电源(电压范围3.6~5.5 V)。
温度范围为-40℃~+85 ℃,采用28脚SSOP 封装此USB芯片PDIUSBD12,与单片机连接方式有两种,分别如下图:方式一方式二方式一为IO方式,方式二为总线方式。
本公司推荐使用第二种方式,原因为:一、连线简单、扩展性强;二、代码编写简单,执行效率高。
使用说明将单片机烧入程序后测试,一般连接无误即可正常工作。
*:使用D12开发USB时,将USB__INT,CS,RD,WR,ALE.插上短路帽.注:这里说明的代码都是在USB文件夹下:文件夹中分别是上位机, 电脑端驱动,和下位机.实验步骤:(1)将流水灯下位机V8.1中HEX文件烧写入单片机;(2)将开发板用USB线插入电脑的USB口,第一次插入,电脑右下角会提示需要安装驱动;(3)打开hhxyUSBdriver V8.1.rar文件夹:点击进入driver文件夹:其中的hhxyUSBdriver.inf是驱动配置文件,hhxyUSBdriver.sys是驱动文件,电脑提示安装驱动,要选择自己安装驱动(不要选择自动安装),然后将驱动路径定位到这个文件夹,驱动即可正确进行安装。
安装完成以后,可在电脑的设备管理器中看到以下信息:(4)用上位机软件进行测试打开LED流水灯上位机V6.20.rar然后点击进入,得到以下界面进入Realse文件夹,双击MyUsbDeviceTestApp.exe文件:点击打开设备,根据下面提示,正常应显示:设备已打开,失败则显示:未找到设备。
PDIUSBD12芯片在USB接口电路中的应用

PDIUSBD12芯片在USB接口电路中的应用摘要:介绍了Philips公司生产的USB系列芯片PDIUSBD12的工作性能与特点,具体给出了PDIUSBD12芯片在扫描仪信号处理USB接口电路的具体应用。
关键词:PDIUSBD12芯片;信号处理;USB接口;扫描仪1PDIUSBD12芯片的性能与特点Philips公司生产的型号为PDIUSBD12的接口芯片是一个具有集成的SIE,FIFO存储器、发送器和电压调整器的高性能USB接口芯片,同时还支持DMA逻辑传输形式。
他通常应用于基于微控制器的系统中,并且可以通过高速的并行接口和系统中的微处理器进行通信,其中最高并行接口速率可以达到2 MB/s,是一个具有8位数据总线和一个地址的存储与数据交换设备。
PDIUSBD12芯片的功能方框图如图1所示。
他采用28PIN脚模式,有SO28和TSSOP28封装,SIE用来实现USB协议层的完整功能。
具体功能如下:同步方式识别、并/串转换、比特填充/解填充、CRC校验/生成、PID确认/生成、地址识别和握手信号的鉴定/生成、批处理数据传输可达1 MB/s,3±0.3 V双极性输入范围,可接受4.5~5.5 V工作电压、工业级标准工作环境温度范围为-40~+85℃。
也就是说,利用该芯片可以完成微控制器所送出的信号到符号USB规范的信号的转换。
2USB工作电路USB相对于其他传统接口而言,其快速数据传输能力和安装简单的和谐平衡在扫描仪上体现得尤为突出。
传统的SCSI接口的扫描仪安装极为麻烦,并且对计算机的要求非常苛求,必须带有SCSI接口,并行接口传输数据又显得实在太慢。
USB接口可以从速度和安装的简易性两方面满足用户的要求。
现在的主流扫描仪生产厂家都在生产USB 接口扫描仪,如HP,ACER和TARGA等公司都在纷纷推出,这种款式的机器具有以下的优点:(1)USB接口可以有效地提升数据的传输速度。
(2)无外置电源设计,采用CIS技术,耗电量只有2 W,便携可靠。
微型计算机系统接口技术实验

微型计算机系统接口技术实验✧实验目标:PDIUSBD12+FPGA实现usb接口,完成枚举和驱动程序并实现简单的应用。
✧实验内容:1.方案选择。
接口协议芯片选择PDIUSBD12,控制器由FPGA实现,控制器的具体实现(1)可以用VHDL语言编程实现状态机实现一个简单的针对d12的控制器。
(2)可以利用EDK提供的Microblaze核实现一个单片机作为控制器。
对于第一种方法需要对VHDL语言比较熟悉,而且能够熟练应用集成开发环境的仿真功能;第二种方法需要熟悉C编程,并能够熟练应用EDK提供的各种IP包。
项目开发流程。
(1)实现Microblaze核,并通过完成显示实验验证其可用性;(2)在(1)的硬件基础上利用EDK提供的EMC实现Microblaze与PDIUSBD12的控制接口;(3)完成PDIUSBD12的固件开发从而完成枚举;――实现底层数据通讯――移植philips公司提供的firmware――Microblaze中断的配置――介绍XMD Debug的配置和使用(4)结合(3)完成驱动程序的开发;(5)实现一个简单的应用2.方案的具体实现。
(1)实现Microblaze核,并通过完成显示实验验证其可用性。
步骤概要:a.在XPS中创建项目文件;b.定义系统硬件;c.定义软件设计:c1.设置驱动interface level;c2.完成源程序;c3.编译代码;c4.Debug.(可选)d.下载代码。
具体步骤参照附件中mb_6.1.pdf的P13-P36,实验用例在文件夹testled中,源程序参照testled/code/testled.c。
我主要介绍一下针对我们这个实验需要进行的参数配置和实验的注意事项。
参数配置:a.定义系统硬件部分:Board V endor:Memec DesignBoard Name:Spartan—II300E LC Develop BoardBoard: 1Select a processor:MicroblazeConfigure Processor :Processor Clock:100MhzDebug I/F:XMD with S/W debugLocal data and instruction Memory:8kCache:disableConfigure IO Interfaces:only choose LEDs_4BitAdd Internal Peripherals:no choiceb.设置驱动interface level部分除了debug_module为0,其余均为1。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
采用PDIUSBD12的USB系统固件程序设计摘要:在设计USB系统的过程中,固件程序的编写是非常重要的一个环节,它直接影响到开发产品的数据传输速度。
以Phillips公司的USB控制芯睡PDIUSBD12为例,介绍了在设计开发USB外设中。
固件的作用以及固件程序的编写流程,并给出了相应程序。
关键词:USB 固件程序 PDIUSBD12 端点单片机USB(Universal Serial Bus)即通用串行总线,是现在非常流行的一种快速、双向、廉价、可以进行热插拨的接口,在现在的每一台PC机上都可以找到一对USB接口。
在遵循USB1.1规范的基础上,USB接口最高传输速度可达12Mb/s:而在最新的USB2.0规范下,更可以达到480Mb/s.同时它可以连接127个USB设备,而且连接的方式也十分灵活,既可以使用串行连接,也可以使用集线器(Hub)把多个设备连接在一起,再同PC机的USB 接口相连.此外,它还可以从系统中直接汲取电流,无需单独的供电系统.USB的这些特点使它获得了广泛的应用.但是使用上的方便则意味着开发上的复杂,主要是编程的复杂性大大的增加了.在设计开发一个USB外设的时候,开发者主要需要编写三部分的程序: ①固件程序;②USB驱动程序;③客户应用程序.本文主要阐述固件程序的编写.1 固件要完成的主要工作固件是FIREWARE的对应中文词,它实际上是单片机的程序文件,其编写语言可以采用C语言或是汇编语言.它的操作方式与硬件联系紧密,包括USB设备的连接USB协议、中断处理等,它不是单纯的软件,而是软件和硬件的结合,开发者需要对端口、中断和硬件结构非常熟悉。
固件程序一般放入MCU中,当把设备连接到主机上(USB连接线插入插孔)时,上位机可以发现新设备,然后建立连接。
因此。
编写固件程序的一个最主要的目的就时让Windows可以检测和识别设备。
2 PDIUSBD12芯片特点PDIUSBD12是一个性能优化的USB器件,通常用于基于微控制器的系统,并通过高速通用并行接口与微控制器进行通信,而且支持本地DMA传输。
该器件采用模块化的方法实现一个USB接口,允许在众多可用的微控制器中选择最合适的作为系统微控制器,允许使用现存的体系结构使固件投资减到最小。
这种灵活性减少了开发时间、风险和成本。
该器件使开发成本低且高效的USB外围设备的一种有效途径。
PDIUSDB12完全符合USB1.1规范,也能适应大多数设备类规范的设计,如成像类、大容量存储类、通信类、打印类和人工输入设备等。
因此,PDIUSBD12非常适合做很多外围设备,如打印机、扫描仪、外部大容量存储器(Zip驱动器)和数码相机等。
现在很多用SCSI实现的很多设备如果用USB来实现可以直接降低成本。
PDIUSBD12还集成了SoftConnect、GoodLink、可编程时钟输出、低频晶振和终端电阻等特性。
所有这些特性都能在系统实现时节省成本,同时在外围设备上很容易实现更高级的USB功能。
3 PDIUSBD12固件程序的编写USB设备启动流程如下:(1)USB设备接入USB口,发出连接USB命令;(2)主机发出读设备描述符两次;(3)主机根据设备描述符——厂商ID、产品ID,启动相应设备驱动程序;(4)设备驱动程序初始化USB设备;①读设备描述符;②读配置描述符;③选择接口、端点(管道),确定传输方式。
USB固件程序由三部分组成:①初始化单片机和所有的外围电路(包括PDIUSBD12);②主循环部分,其任务是可以中断的;③中断服务程序,其任务是对时间敏感的,必须马上执行。
根据USB协议,任何传输都是由主机(Host)开始的。
单片机作它的前台工作,等待中断。
主机首先要发令牌包给USB设备(这里是PDIUSBD12),PDIUSBD12接收到令牌包后就给单片机发中断。
单片机进入中断服务程序,首先读PDIUSBD12的中断寄存器,判断USB令牌包的类型,然后执行相应的操作。
在USB单片机程序中,要完成对各种令牌包的响应,其中比较难处理的是SETUP包,主要是端口0的编程。
单片机与PDIUSBD12的通信主要是靠单片机给PDIUSBD12发命令和数据来实现的。
PDIUSBD12的命令字分为三种:初始化命令字、数据流命令字和通用命令字。
PDIUSBD12数据手册给出了各种命令的代码和地址。
单片机先给PDIUSBD12的命令地址发命令,根据不同命令的要求再发送或读出不同的数据。
因此,可以将每种命令做成函数,用函数实现各个命令,以后直接调用函数即可。
下面的程序是处理主机的标准控制请求的一个模板:unsigned char ENDPOINT_A0_FIFO[8];//判断输入的是SETUP请求,并将其读入缓冲区ENDPOINT_A0_FIFO…if((ENDPOINT_A0_FIFO[0] & 0b011000000)==0x00){if(ENDPOINT_A0_FIFO[1]<=0C){(*StandardFunctionTable[ENDPOINT_A0_FIFO[1]])();return;}}…const void (*StandardFunctionTable[])(void)={GetSatus,ClearFeature,USB_Reserved,SetFeature,USB_Reserved,SetAddress,GetDescriptor,SetDescriptor,GetConfiguration,SetConfiguration,GetInterface,SetInterface,SynchFrame};USB设备在正常使用以前,必须由主机配置设备。
主机一般会从USB设备获取配置信息后再确定此设备有哪些功能。
作为配置操作的一部分,主机会设备设备的配置值,如果必要的话会选择合适的接口备选设备。
其初始化函数为:void D12_int(){ XmtBuff.pNum=16;D12_COMMAND=0xf4;//读中断寄存器ist=D12_DATA;ist=D12_DATA;if(ist & 0x01) //ENDP0_OUT{XmtBuff.out=0;XmtBuff.in=1;D12_COMMAND=0x40; //读OUT最后状态ist=D12_DATA;if(ist & 0x20)//收到SETUP包{ Setup_read();Setup_control();}else{ Setup_read();}}else if(ist & 0x02)//ENDP0_IN{ XmtBuff.in=1;D12_COMMAND=0x41;//读in最后状态ist=D12_DATA;USB_submit();}else if(ist & 0x04)//ENDP1_OUT{ XmtBuff.out=2;XmtBuff.in=3;D12_COMMAND=0x42;//读out最后状态ist=D12_DATA;read_out();}else if(ist & 0x08)//ENDP1_IN{ XmtBuff.in=3;D12_COMMAND=0x43;//读in最后状态ist=D12_DATA;XmtBuff.b[0]=5;XmtBuff.wrLength=1;XmtBuff.p=XmtBuff.b;USB_submit();}……在发出连接USB命令后,主机先读取设备描述符,然后发出设置USB地址SETUP包,设置USB地址后,进行主机客户驱动与设备初始化。
其余端点(ENDPOINT)依此类推。
在其头文件里需定义USB规范中的各种描述符格式,包括设备描述表、配置描述表、接口描述表、端点描述表、字符串描述表以及描述表类型。
这样,在发送配置[,接口(1),端点(1),接口(2),端点(2),…,类,厂商等]联合描述表时,主机USBD可以根据描述类型标识区分各种分描述表。
下面是固件程序的主循环部分:#include<reg51.h>//指向外部D12访问地址#define D12_COMMAND(*(unsigned char xdata *)0xff01)#define D12_DATA (*(unsigned char xdata *)0x7f02)extern void D12_int();sbit D12_suspend=P1^0;sbit D12_int_n=P1^1;sbit D12_eot_n=P1^2;sbit D12_DMAck_n=P1^3;sbit D12_DMAreq=P1^4;void main(void){unsigned char ist;P1=0xff;D12_COMMAND=0xf3;D12_DATA=0x06;//设置模式0D12_DATA=0x03;//初始化频率12MHzD12_COMMAND=0xd0;D12_DATA=0x80;//设置地址0使能D12_COMMAND=0xf3;//连接主机D12_DATA=0x16;while(1){ if(!D12_int_n){D12_int();}}}在编写USB的固件程序时,需要注意:①单片机的中断应设置为电平触发;中断后一定要读上次传输状态寄存器(命令40~45H),以清除中断寄存器中的中断标志。
这样,PDIUSBD12的中断输出才能变回高电平,这一点非常重要。
②在接收到Setup包后,一定要调用D8命令重新使能端口0。
③在向IN端写完数据后,一定调用命令FAH,指明缓冲区中的数据有效,可以发送到主机。
④读写数据后,一定调用命令F2H,以保证可以接收新的包。
⑤可以通过调用命令FDH,检查PDIUSBD12是否工作。
该命令要读两个字节数据。
固件程序的编程是整个USB外设开发中非常重要的一环,它直接影响到设计开发的产品的数据传输速度。
例如,采用不同的传输类型、设置不同的分组大小、是否采用DMA方式、传输缓冲区的大小等都会使得传输速率发生很大的变化。
还有在高速情况下的超时处理等,也包含了很多的内容。
总之,在USB技术应用越来越广泛的今天,只有掌握了固件程序的编写,才可能开发出一个好的USB产品。
USB接口芯片PDIUSBD12引脚图,引脚功能及命令表PDIUSBD12的引脚排列如图1所示,功能如下:VCC:接 5V电源;GND:接地;如要使器件工作在3.3V,则VCC、Vout3.3都为3.3V。
DATA〈0〉~DATA〈7〉:双向数据总线。
ALE:地址锁存使能。
在多路地址数据总线中,下降沿关闭地址锁存;在单地址/数据总线配置中接地。
CSN:片选端,低电平有效。