This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS320F28377D: USB(Serial Mode) Communication, how to directly transmit the data of write buffer.

Part Number: TMS320F28377D


Tool/software:

In my case, follow as

uint32_t
RxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue,
          void *pvMsgData)
{
    uint32_t ui32Count;

    //
    // Which event are we being sent?
    //
    switch(ui32Event)
    {
        //
        // A new packet has been received.
        //
        case USB_EVENT_RX_AVAILABLE:
        {
            //
            // Feed some characters into the SCI TX FIFO and enable the
            // interrupt so we are told when there is more space.
            //
            int i;
            uint8_t tmpData;
            uint16_t flagSTX = 0;

            uint32_t ui32Count,ui32Read, dataSize;
            uint8_t ui8Char;

            dataSize = USBBufferDataAvailable((tUSBBuffer*)&g_sRxBuffer);

            //for(i = 0; i < 20; i++ )
            while(dataSize)
            {
                ui32Read = USBBufferRead((tUSBBuffer *)&g_sRxBuffer, &tmpData, 1);
                rxData[usbRxCnt] = tmpData;
                if(ui32Read)
                {
                    if(usbRxCnt == 0 || usbRxCnt == 1) {
                        if (usbRxCnt == 0 && rxData[usbRxCnt] == STX) {
                            usbRxCnt++;
                            flagSTX = 1;
                        } else if (flagSTX == 1 && rxData[usbRxCnt] == STX) {
                            usbRxCnt++;
                        }
                    } else {
                        usbRxCnt++;
                    }

                    if(usbRxCnt >= 4)
                    {
                        usbRxSize = ((rxData[2] + (rxData[3] << 8)) * 4) + 10;
                        if((usbRxCnt == usbRxSize) && ( rxData[usbRxSize-2] == ETX && rxData[usbRxSize-1] == ETX ) ) {
                            Parcing_UsbData(rxData, usbRxSize);
                            usbRxCnt = 0;
                            flagSTX = 0;
                        }
                    }
                    g_ui32SCIRxCount++;
                }
                else
                {
                    break;
                }
            }
            break;
        }

        //
        // We are being asked how much unprocessed data we have still to
        // process. We return 0 if the SCI is currently idle or 1 if it is
        // in the process of transmitting something. The actual number of
        // bytes in the SCI FIFO is not important here, merely whether or
        // not everything previously sent to us has been transmitted.
        //
        case USB_EVENT_DATA_REMAINING:
        {
            //
            // Get the number of bytes in the buffer and add 1 if some data
            // still has to clear the transmitter.
            //
            //ui32Count = SCI_isTransmitterBusy(SCIA_BASE) ? 1 : 0;
            //return(ui32Count);
        }

        //
        // We are being asked to provide a buffer into which the next packet
        // can be read. We do not support this mode of receiving data so let
        // the driver know by returning 0. The CDC driver should not be sending
        // this message but this is included just for illustration and
        // completeness.
        //
        case USB_EVENT_REQUEST_BUFFER:
        {
            return(0);
        }

        //
        // We don't expect to receive any other events.  Ignore any that show
        // up in a release build or hang in a debug build.
        //
        default:
#ifdef DEBUG
            while(1);
#else
            break;
#endif
    }

    return(0);
}

Parcing_UsbData(rxData, usbRxSize)
{
    if(rxData[3] == 0x01)
    {
        txData[0] = 0x7E;
        txData[1] = 0x7E;
        .....
        txData[14] = 0x81;
        txData[15] = 0x81;
        
        int i;
        for(i = 0; i < 16; i++)
        {
            while(USBBufferSpaceAvailable((tUSBBuffer *)&g_sTxBuffer) == 0) {}
            USBBufferWrite((tUSBBuffer *)&g_sTxBuffer, &txData[i], 1);
        }
    }
}

in PC, I transmit the data to the board, then board receviced the data correctly.

then, using Parcing_usbData(), the board transmit the return data.

USBWriteBuffer Function pushes the data to ring buffer. but not transmit the buffer data.

In PC, it has to send it twice in a row to receive data from the board.

1) Why not transmit the data in USBBufferWrite() immediately?

2) How can i transmit the data immediately?