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.

Want to transfer ADC value via USB using tm4c123gh6pm in ccs.

I trying to view ADC value in PC by using USB data transfer method. 

I need guide lines to implement.

guide lines line:

  1.  function type
  2. how to move adc value in usbbuffer 
  3. who to place the adc value in Tx buffer
  4. 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);

}

  • Hello Raghunath

    You had already opened the post

    http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/393944

    And there was quite some advise on it from cb1 and myself. I have done half of your homework, expect that you do due diligence to the remaining half.

    http://e2e.ti.com/support/microcontrollers/tiva_arm/f/908/t/379512

    Regards
    Amit
  • Bravo Amit!   Poster's attempt to (avoid) necessary time/effort - dump each/every mundane detail upon you - must be (properly) resisted.

    Fact that post employs "disguise" to "squeeze more work from others" signals NO serious study/effort/experimentation - and should not be rewarded...