C8051F340 USB设备数据传输硅实验室IDE

问题描述:

我正在尝试编写C8051F340的设备代码以通过USB从主机(PC)获取数据。我从硅实验室的一些例子,代码看起来象下面这样:C8051F340 USB设备数据传输硅实验室IDE

void Receive_File(void) 
{ 
    ReadStageLength = ((BytesToRead - BytesRead) > MAX_BLOCK_SIZE_READ)? MAX_BLOCK_SIZE_READ:(BytesToRead - BytesRead); 

    BytesRead += Block_Read((U8*)(&TempStorage[BlockIndex]), ReadStageLength); // Read Block 

    BlockIndex++; 
    // If device has received as many bytes as fit on one FLASH page, disable interrupts, 
    // write page to flash, reset packet index, enable interrupts 
    // Send handshake packet 0xFF to host after FLASH write 
    if ((BlockIndex == (BLOCKS_PR_PAGE)) || (BytesRead == BytesToRead)) 
{ 
    Page_Erase((U8*)(PageIndices[PageIndex])); 
    Page_Write((U8*)(PageIndices[PageIndex])); 
    PageIndex++; 
    Led1 = !Led1; 
    BlockIndex = 0; 
    Buffer[0] = 0xFF; 
    Block_Write(Buffer, 1);   // Send handshake Acknowledge to host 
} 

// Go to Idle state if last packet has been received 
if (BytesRead == BytesToRead) {M_State = ST_IDLE_DEV; Led1 = 0;} 
} 

// Startup code for SDCC to disablt WDT before initializing variables so that 
// a reset does not occur 
#if defined SDCC 
void _sdcc_external_startup (void) 
{ 
PCA0MD &= ~0x40;     // Disable Watchdog timer 
} 
#endif 

我有一些问题要问: 1.凡数据去?缓冲区[0]? 2.如果我从主机获得十六进制值传输,我可以只读Buffer [0]来获取它? 抱歉,我是一个新手。 谢谢。存储在阵列TempStorage 您使用Buufer

你的接收到的数据[0](返回0xFF),用于将数据发送到主机