X-Git-Url: http://git.linex4red.de/pub/USBasp.git/blobdiff_plain/c5038f1bf44aea75f1ae1ed035cb7d523ccfdacb..3ffa7543a05761a0c69144c9b66196b08d8f1249:/Demos/Device/LowLevel/USBtoSerial/USBtoSerial.c?ds=sidebyside diff --git a/Demos/Device/LowLevel/USBtoSerial/USBtoSerial.c b/Demos/Device/LowLevel/USBtoSerial/USBtoSerial.c index bb1b4da2d..92449a67d 100644 --- a/Demos/Device/LowLevel/USBtoSerial/USBtoSerial.c +++ b/Demos/Device/LowLevel/USBtoSerial/USBtoSerial.c @@ -81,9 +81,9 @@ void SetupHardware(void) clock_prescale_set(clock_div_1); /* Hardware Initialization */ + Serial_Init(9600, false); LEDs_Init(); - ReconfigureUSART(); - USB_Init(); + USB_Init(); } /** Event handler for the USB_Connect event. This indicates that the device is enumerating via the status LEDs and @@ -263,11 +263,7 @@ void CDC_Task(void) if ((Tx_Buffer.Elements) && LineEncoding.BaudRateBPS) { /* Wait until Serial Tx Endpoint Ready for Read/Write */ - while (!(Endpoint_IsReadWriteAllowed())) - { - if (USB_DeviceState == DEVICE_STATE_Unattached) - return; - } + Endpoint_WaitUntilReady(); /* Write the bytes from the buffer to the endpoint while space is available */ while (Tx_Buffer.Elements && Endpoint_IsReadWriteAllowed()) @@ -287,11 +283,7 @@ void CDC_Task(void) if (IsFull && !(Tx_Buffer.Elements)) { /* Wait until Serial Tx Endpoint Ready for Read/Write */ - while (!(Endpoint_IsReadWriteAllowed())) - { - if (USB_DeviceState == DEVICE_STATE_Unattached) - return; - } + Endpoint_WaitUntilReady(); /* Send an empty packet to terminate the transfer */ Endpoint_ClearIN(); @@ -304,9 +296,11 @@ void CDC_Task(void) */ ISR(USART1_RX_vect, ISR_BLOCK) { + uint8_t ReceivedByte = UDR1; + /* Only store received characters if the USB interface is connected */ - if ((USB_DeviceState != DEVICE_STATE_Configured) && LineEncoding.BaudRateBPS) - Buffer_StoreElement(&Tx_Buffer, UDR1); + if ((USB_DeviceState == DEVICE_STATE_Configured) && LineEncoding.BaudRateBPS) + Buffer_StoreElement(&Tx_Buffer, ReceivedByte); } /** Reconfigures the USART to match the current serial port settings issued by the host as closely as possible. */