I trying to view ADC value in PC by using USB data transfer method.
I need guide lines to implement.
guide lines line:
- function type
- how to move adc value in usbbuffer
- who to place the adc value in Tx buffer
- amount of transfer is 256 byte
usb bulk example is working, but i don't know to read the adc value instead of Echo.
Here by i attached my usb echo program.
#include <stdbool.h>
#include <stdint.h>
#include "inc/hw_ints.h"
#include "inc/hw_memmap.h"
#include "inc/hw_types.h"
#include "driverlib/debug.h"
#include "driverlib/fpu.h"
#include "driverlib/gpio.h"
#include "driverlib/interrupt.h"
#include "driverlib/pin_map.h"
#include "driverlib/sysctl.h"
#include "driverlib/systick.h"
#include "driverlib/timer.h"
#include "driverlib/rom.h"
#include "usblib/usblib.h"
#include "usblib/usb-ids.h"
#include "usblib/device/usbdevice.h"
#include "usblib/device/usbdbulk.h"
#include "utils/ustdlib.h"
#include "usb_bulk_structs.h"
#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)
{
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)
{
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)
{
ROM_SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_OSC_MAIN | SYSCTL_XTAL_16MHZ);
ROM_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
ROM_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);
}