X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/9991321321d30ca9383d795ea7e796098c92045f..a94b1911645b1f14f80eb0f1612d33f83866d4a3:/Demos/USBtoSerial/USBtoSerial.c diff --git a/Demos/USBtoSerial/USBtoSerial.c b/Demos/USBtoSerial/USBtoSerial.c index 7c06007a3..c7c9e4b04 100644 --- a/Demos/USBtoSerial/USBtoSerial.c +++ b/Demos/USBtoSerial/USBtoSerial.c @@ -72,8 +72,8 @@ int main(void) MCUSR &= ~(1 << WDRF); wdt_disable(); - /* Disable Clock Division */ - SetSystemClockPrescaler(0); + /* Disable clock division */ + clock_prescale_set(clock_div_1); /* Hardware Initialization */ LEDs_Init(); @@ -116,6 +116,10 @@ EVENT_HANDLER(USB_Disconnect) /* Stop running CDC and USB management tasks */ Scheduler_SetTaskMode(CDC_Task, TASK_STOP); Scheduler_SetTaskMode(USB_USBTask, TASK_STOP); + + /* Reset Tx and Rx buffers, device disconnected */ + Buffer_Initialize(&Rx_Buffer); + Buffer_Initialize(&Tx_Buffer); /* Indicate USB not ready */ UpdateStatus(Status_USBNotReady); @@ -160,7 +164,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket) case REQ_GetLineEncoding: if (bmRequestType == (REQDIR_DEVICETOHOST | REQTYPE_CLASS | REQREC_INTERFACE)) { - /* Acknowedge the SETUP packet, ready for data transfer */ + /* Acknowledge the SETUP packet, ready for data transfer */ Endpoint_ClearSetupReceived(); /* Write the line coding data to the control endpoint */ @@ -174,7 +178,7 @@ EVENT_HANDLER(USB_UnhandledControlPacket) case REQ_SetLineEncoding: if (bmRequestType == (REQDIR_HOSTTODEVICE | REQTYPE_CLASS | REQREC_INTERFACE)) { - /* Acknowedge the SETUP packet, ready for data transfer */ + /* Acknowledge the SETUP packet, ready for data transfer */ Endpoint_ClearSetupReceived(); /* Read the line coding data in from the host into the global struct */ @@ -202,10 +206,11 @@ EVENT_HANDLER(USB_UnhandledControlPacket) // Do something with the given line states in wIndex #endif - /* Acknowedge the SETUP packet, ready for data transfer */ + /* Acknowledge the SETUP packet, ready for data transfer */ Endpoint_ClearSetupReceived(); - /* Send an empty packet to acknowedge the command */ + /* Acknowledge status stage */ + while (!(Endpoint_IsSetupINReady())); Endpoint_ClearSetupIN(); } @@ -322,8 +327,12 @@ ISR(USART1_TX_vect, ISR_BLOCK) */ ISR(USART1_RX_vect, ISR_BLOCK) { - /* Character received, store it into the buffer */ - Buffer_StoreElement(&Tx_Buffer, UDR1); + /* Only store received characters if the USB interface is connected */ + if (USB_IsConnected) + { + /* Character received, store it into the buffer */ + Buffer_StoreElement(&Tx_Buffer, UDR1); + } } /** Function to manage status updates to the user. This is done via LEDs on the given board, if available, but may be changed to