this is the program for usb echo program, this working correctly.
i need read and send to instantaneous ADC to usb.
both usb echo and adc program is attached below.
help me how to transmit instantaneous ADC value to USB
// program for usb echo (Tx = Rx)
#define SYSTICKS_PER_SECOND 100
#define SYSTICK_PERIOD_MS (1000 / SYSTICKS_PER_SECOND)
unsigned char DATA[22]={0x96,0xd0,0xe0,0x00,0xe5, 0x05,0xe5,0xe5,0xe5,0xe5, 0xe5,0x05,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
unsigned int i;
volatile uint32_t g_ui32SysTickCount = 0;
volatile uint32_t g_ui32TxCount = 0;
//volatile uint32_t g_ui32RxCount = 0;
// Flags used to pass commands from interrupt context to the main loop.
//*****************************************************************************
#define COMMAND_PACKET_RECEIVED 0x00000001
#define COMMAND_STATUS_UPDATE 0x00000002
volatile uint32_t g_ui32Flags = 0;
// Global flag indicating that a USB configuration has been set.
//*****************************************************************************
static volatile bool g_bUSBConfigured = false;
// Interrupt handler for the system tick counter.
//*****************************************************************************
void
SysTickIntHandler(void)
{
//
// Update our system tick counter.
//
g_ui32SysTickCount++;
}
static uint32_t
EchoNewDataToHost(tUSBDBulkDevice *psDevice, uint8_t *pui8Data,
uint32_t ui32NumBytes)
{
uint32_t ui32Loop, ui32Space, ui32Count;
uint32_t ui32ReadIndex;
uint32_t ui32WriteIndex;
tUSBRingBufObject sTxRing;
USBBufferInfoGet(&g_sTxBuffer, &sTxRing);
ui32Space = USBBufferSpaceAvailable(&g_sTxBuffer);
ui32Loop = (ui32Space < ui32NumBytes) ? ui32Space : ui32NumBytes;
ui32Count = ui32Loop;
// Set up to process the characters by directly accessing the USB buffers.
//
ui32ReadIndex = (uint32_t)(pui8Data - g_pui8USBRxBuffer);
ui32WriteIndex = sTxRing.ui32WriteIndex;
while(ui32Loop) // place the main impt to dispaly(receive) the char which we have sent
{
g_pui8USBTxBuffer[ui32WriteIndex] = g_pui8USBRxBuffer[ui32ReadIndex];
ui32WriteIndex++;
ui32WriteIndex = (ui32WriteIndex == BULK_BUFFER_SIZE) ? 0 : ui32WriteIndex;
ui32ReadIndex++;
ui32ReadIndex = (ui32ReadIndex == BULK_BUFFER_SIZE) ? 0 : ui32ReadIndex;
ui32Loop--;
}
USBBufferDataWritten(&g_sTxBuffer, ui32Count);// ui32ReadIndex is added by me
return(ui32Count);
}
uint32_t
TxHandler(void *pvCBData, uint32_t ui32Event, uint32_t ui32MsgValue,
void *pvMsgData)
{
if(ui32Event == USB_EVENT_TX_COMPLETE)
{
g_ui32TxCount += ui32MsgValue;
}
return(0);
}
uint32_t
RxHandler(void *pvCBData, uint32_t ui32Event,
uint32_t ui32MsgValue, void *pvMsgData)
{
switch(ui32Event)
{
case USB_EVENT_CONNECTED:
{
g_bUSBConfigured = true;
USBBufferFlush(&g_sTxBuffer);
USBBufferFlush(&g_sRxBuffer);
break;
}
case USB_EVENT_DISCONNECTED:
{
g_bUSBConfigured = false;
break;
}
case USB_EVENT_RX_AVAILABLE:
{
tUSBDBulkDevice *psDevice;
psDevice = (tUSBDBulkDevice *)pvCBData;
return(EchoNewDataToHost(psDevice, pvMsgData, ui32MsgValue));
}
case USB_EVENT_SUSPEND:
case USB_EVENT_RESUME:
{
break;
}
default:
{
break;
}
}
return(0);
}
int
main(void)
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinTypeUSBAnalog(GPIO_PORTD_BASE, GPIO_PIN_4 | GPIO_PIN_5);
USBBufferInit(&g_sTxBuffer);
USBBufferInit(&g_sRxBuffer);
// Set the USB stack mode to Device mode with VBUS monitoring.
USBStackModeSet(0, eUSBModeForceDevice, 0);
// Pass our device information to the USB library and place the device on the bus.
USBDBulkInit(0, &g_sBulkDevice);
}
// code for adc
int main(void)
{
uint32_t ui32ADC0Value[1];
SysCtlClockSet(SYSCTL_SYSDIV_5|SYSCTL_USE_PLL|SYSCTL_OSC_MAIN|SYSCTL_XTAL_16MHZ);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3);
ADCHardwareOversampleConfigure(ADC0_BASE, 64);
ADCSequenceConfigure(ADC0_BASE, 1, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE,1,3,ADC_CTL_CH0|ADC_CTL_IE|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, 1);
while(1)
{
ADCIntClear(ADC0_BASE, 1);
ADCProcessorTrigger(ADC0_BASE, 1);
while(!ADCIntStatus(ADC0_BASE, 1, false))
{
}
ADCSequenceDataGet(ADC0_BASE, 1, ui32ADC0Value);
}
}