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

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);
}
}

  • Hello Ragunathan,

    Did you search the forum for the same. There is a similar thread for ADC and USB in the last 2 months

    Regards
    Amit
  • Ragunathan P said:
    I need [to] read and send to instantaneous ADC to usb.

    Your "intent" signaled by, "instantaneous" may require (some) definition.

    And - does not your use of the function, "ADCHardwareOversampleConfigure(ADC0_BASE, 64); impede your desire for, "instantaneous" ADC reads?  (i.e. your ADC result is "held hostage" until 64 conversions have been completed.  Hardware Oversample improves measurement accuracy - but greatly slows your (effective) conversion rate.)

    You generate only a single ADC conversion - suspect that the, "8 conversion sequence - performed back to back" better meets your desire.  (although still fails to qualify as, "instantaneous!")

    Devil - as always - "in the details" - and their uncovering & optimization is rarely done in an instant...

  • hello cb1

    thanks for your reply.

    i need just transfer data or array in usb. 

    can u help me how to configure how to transfer data (print)

  • Originally you sought, "instantaneous" transfer - and then employed a 64 ADC hardware averaging configuration.

    You've not resolved that to the forum's satisfaction - and vendor's Amit has given you a recent, focused tip.

    Does it make sense then (now) to dig deeper - when identified weaknesses in your approach sit unresolved?  (or unacknowledged, here...)

  • hello cb1 thank for your reply.

    completed adc transfer configuration by using uart. my only problem is to configure usb and use it for any kind of application like adc, array value. the usb bulk example api is not working with other kind of application. vendor amit gave some link that contain only information regarding uart configurations. that not at all useful for my usb project.

  • thank you amit
    i referred last 2 month . but not got useful information.
    usb bulk example api is not supporting other kind of applications.

    i need separate api to view the usb output. (for like uart we using terminal.exe and terra term)
  • (Still) unresolved is your expressed desire for "instantaneous" which conflicts greatly w/64 loop HW oversampling.   Words have meaning - always unwise to create an (unresolvable) conflict - via a poorly considered, "specification."  

    USB is not simple, nor quickly mastered, and most always will prove a challenge.

    You report "success" via UART - cannot you "escape" the technical complexity of USB by obtaining a, "USB to UART" converter? (FTDI is one low-cost vendor)  This may even be purchased "embedded" w/in a cable - and then allows your PC to receive your UART driven data w/minimum, "blood, sweat, tears" on your (and your forum helpers') part.

    There are hundreds of USB-based posts here - and multiple USB examples (which require some search effort, from you) but your use of USB to UART chip/cable seems fastest/easiest "solution."   Although still FAILS to meet your "instantaneous" objective...

  • hello cb1 thanks for your response and your advice.
    i got some useful information form forum thanks for community members and TI employees.
    my actual project is getting instance of data from ssi and view the result in pc trough the usb device port.(i got received ssi values in uart now trying with usb) then to plot the usb device port values in GUI. if you have any ideas share with me this information will helpful to complete my project work soon.

    thanks :-)
    -ccs
    -Ragu

  • Your target is both "moving" and "expanding." Does that allow proper focus? (by you - or hapless helpers?)

    You remain "silent" as regards to your satisfying your objective (quickly, far more easily) thru use of FTDI's long proven, UART -> USB solution. That method frees you to move to the next portion of your expanded project - USB mastery no longer holds you hostage.

    Our small firms thinks/lives/breathes KISS. Too many "balls in the air" prove hard to manage. (for circus performer as well as for MCU project engineer...)
  • Hello Ragunathan,

    My elementary question comes to USB bulk device example. Just because it does not meet the requirement 100% and requires you to invest effort, time does not mean it is not useful. I have known quite a few engineering students who have used the example to do similar data transfer plug-n-play. In my most humble opinion please take this post of mime as an "inspiration" to gain expertise in some aspect of the project you intend to develop.

    Regards
    Amit
  • Amit Ashara said:
    gain expertise in some aspect of the project you intend to develop.  

    Or - as some have long urged - employ "KISS!"   Too broad a focus - too many (often competing) objectives - is not the best path to success.   (and is certain to never qualify under your earlier demand for, "instantaneous!")

  • hello cb1_mobile

    yeah i accepting your point(too many objectives-is not the best path to success). but all are not a expert or guru in this field. my objective is to ssi+usb+pc data transfer- i am not an guru like you to do it from the beginning  itself. so i started with the basic adc+usb communication. is it wrong?

  • Hello Raghunathan,

    As not so long ago fellow student, I would be taken aback if during the final closure of my papers, I am told that there is 1 more task to be answered. Guru or Not, no one will have the time to do so. Do remember that the levels are only indicative, and a lot of posters still continue to amaze me with what they do, prodigy or not.

    Regards
    Amit