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.

MSP430F5529 USB CDC connection

Other Parts Discussed in Thread: MSP430F5529

Hello all,

I'm currently working with CCSv5.4 on the MSP430F5529 Experimenter board. I'm am developing a code that will take ADC samples and transfer them through USB via CDC COM port to a host application.

I'm having trouble setting up the code to make the device recognized by the computer. I've been looking at example codes that work(C1-C6 in API CDC Examples), and am unable to distinguish the difference. Here's the basic setup of my code:

//USB Includes
#include "USB_API/USB_Common/device.h"
#include "USB_API/USB_Common/types.h"
#include "USB_config/descriptors.h"
#include "USB_API/USB_Common/usb.h"
#include "USB_API/USB_CDC_API/UsbCdc.h"
#include "usbConstructs.h"
#include "F5xx_F6xx_Core_Lib/HAL_UCS.h"
#include "F5xx_F6xx_Core_Lib/HAL_PMM.h"

...

...

VOID Init_Ports (VOID);
VOID Init_Clock (VOID);

int main(void)
{
//USB SETUP
USB_init();

USB_setEnabledEvents(
kUSB_VbusOnEvent + kUSB_VbusOffEvent + kUSB_receiveCompletedEvent
+ kUSB_dataReceivedEvent + kUSB_UsbSuspendEvent + kUSB_UsbResumeEvent +
kUSB_UsbResetEvent);
USB_connect();

if (USB_connectionInfo() & kUSB_vbusPresent){
USB_handleVbusOnEvent();
}

USB_connectionState();

...

...

Is there anything else I need to be including? I do have the USB Config folder, which contains descriptors.h,descriptors.c, UsbIsr.c, and 1CDC_descTool.inf.

Thanks in advance!

David

  • For me, easiest way will be to insert my ADC source code inside TI USB CDC example source code. Of course it can be done in opposite way, but than debugging will take some time. Try to check clock setup (Init_Clock() function) for USB in descriptors.h

    // MCLK frequency of MCU, in Hz
    // For running higher frequencies the Vcore voltage adjustment may required.
    // Please refer to Data Sheet of the MSP430 device you use
    #define USB_MCLK_FREQ 25000000   // MCLK frequency of MCU, in Hz
    #define USB_PLL_XT 2             // Defines which XT is used by the PLL (1=XT1, 2=XT2)
    #define USB_XT_FREQ USBPLL_SETCLK_24_0 // Indicates the freq of the crystal on the oscillator indicated by USB_PLL_XT
    #define USB_DISABLE_XT_SUSPEND 1 // If non-zero, then USB_suspend() will disable the oscillator
                                     // that is designated by USB_PLL_XT; if zero, USB_suspend won't
                                     // affect the oscillator

  • zrno soli,

    Thanks for your reply, and sorry to return so late. I've added my adc code to the usb example and can't find the problem, but it still is not recognized by the computer. I'm trying to get it recognized by a terminal as a COM port.

    I copied the C6_Example from the CDC example code in the TI Explorer then added my code. The example code IS able to connect to the terminal, but my code is not. 

    Here is my code... focus on the USB initialization.

    Green= exactly from Example code

    Yellow=my USB code

    //General device includes
    #include <msp430.h>
    #include "inc/hw_memmap.h"

    //USB Includes
    #include "USB_API/USB_Common/device.h"
    #include "USB_API/USB_Common/types.h"
    #include "USB_config/descriptors.h"
    #include "USB_API/USB_Common/usb.h"
    #include "USB_API/USB_CDC_API/UsbCdc.h"
    #include "usbConstructs.h"
    #include "F5xx_F6xx_Core_Lib/HAL_UCS.h"
    #include "F5xx_F6xx_Core_Lib/HAL_PMM.h"

    //ADC Includes
    #include <intrinsics.h>
    #include <string.h>
    #include "adc12_a.h"
    #include "ref.h"
    #include "wdt_a.h"
    #include "gpio.h"


    //This function is used to turn off the watchdog,
    //so it isn't triggered by the during the lengthy initialization
    //period of the USB buffers.
    int _system_pre_init(void)
    {
    WDTCTL = WDTPW | WDTHOLD;
    return 1;
    }

    //USB Buffers
    #define NUMBER_OF_ELEMENTS (512)
    #define BUFFER_TYPE (WORD)
    #define BUFFER_SIZE_BYTES (sizeof(BUFFER_TYPE)*NUMBER_OF_ELEMENTS)
    WORD databuffX[NUMBER_OF_ELEMENTS] = {0}; // Corresponds to 00
    WORD databuffY[NUMBER_OF_ELEMENTS] = {0}; // Corresponds to 01
    WORD databuffZ[NUMBER_OF_ELEMENTS] = {0}; // Corresponds to 10
    WORD databuffZZ[NUMBER_OF_ELEMENTS] = {0}; // Corresponds to 11

    //Index initialization. These are used to trigger USB transfers
    uint16_t Buffer_Index = 0x00;
    uint8_t Sequencer = 0x00;
    uint16_t USBTFlagBuf0 = 0x00;

    VOID Init_Ports (VOID);
    VOID Init_Clock (VOID);

    volatile BYTE bCDCDataReceived_event = FALSE; //Indicates data has been received without an open rcv operation

    int main(void)
    {
    Init_Ports(); //Init ports (do first ports because clocks do change ports)
    SetVCore(3);
    Init_Clock();
    //USB SETUP
    USB_init();

    USB_setEnabledEvents(
    kUSB_VbusOnEvent + kUSB_VbusOffEvent + kUSB_receiveCompletedEvent
    + kUSB_dataReceivedEvent + kUSB_UsbSuspendEvent + kUSB_UsbResumeEvent +
    kUSB_UsbResetEvent);

    if (USB_connectionInfo() & kUSB_vbusPresent){
    USB_handleVbusOnEvent();
    }

    USB_connect();
    //USB_connectionState();

    // SETUP CHANNEL SELECTION PINS
    // These are used to control which channel on the external
    // amplifier is selected as the input to the ADC. Initialized to 00
    GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN0);
    GPIO_setAsOutputPin(GPIO_PORT_P1,GPIO_PIN1);
    GPIO_setOutputLowOnPin(GPIO_PORT_P1,GPIO_PIN0);
    GPIO_setOutputLowOnPin(GPIO_PORT_P1,GPIO_PIN1);
    GPIO_setAsPeripheralModuleFunctionInputPin(GPIO_PORT_P6,GPIO_PIN6);

    // INITIALIZE REFERENCE VOLTAGE
    REF_setReferenceVoltage(REF_BASE, REF_VREF2_5V);
    REF_enableReferenceVoltage(REF_BASE);

    // INITIALIZE ADC12_A
    ADC12_A_init(ADC12_A_BASE,ADC12_A_SAMPLEHOLDSOURCE_SC,
    ADC12_A_CLOCKSOURCE_ADC12OSC,ADC12_A_CLOCKDIVIDER_1);

    ADC12_A_enable(ADC12_A_BASE);

    ADC12_A_setReferenceBufferSamplingRate(ADC12_A_BASE,ADC12_A_MAXSAMPLINGRATE_200KSPS);

    ADC12_A_setupSamplingTimer(ADC12_A_BASE,ADC12_A_CYCLEHOLD_4_CYCLES,
    ADC12_A_CYCLEHOLD_4_CYCLES,ADC12_A_MULTIPLESAMPLESENABLE);

    ADC12_A_memoryConfigure(ADC12_A_BASE,
    ADC12_A_MEMORY_0,
    ADC12_A_INPUT_A6, //I chose input A6 (P6.6) on the Experimenter board because it was easy to access for testing purposes
    ADC12_A_VREFPOS_INT,
    ADC12_A_VREFNEG_AVSS,
    ADC12_A_NOTENDOFSEQUENCE);


    ADC12_A_clearInterrupt(ADC12_A_BASE,ADC12IFG0);

    ADC12_A_enableInterrupt(ADC12_A_BASE,ADC12IE0);

    //USB Loop
    while(1)
    {

    //check if buffer is ready for USB transfer
    //Sends first half of buffer
    if(USBTFlagBuf0 == 0x01)
    {
    cdcSendDataInBackground(
    (BYTE*)databuffX,
    256,
    CDC0_INTFNUM,
    0);
    _delay_cycles(100000);
    USBTFlagBuf0 = 0x00;
    }
    //Sends second half of buffer
    if(USBTFlagBuf0 == 0x02)
    {
    cdcSendDataInBackground( // How to start at second half of buffer???
    (BYTE*)databuffX,
    256,
    CDC0_INTFNUM,
    0);
    _delay_cycles(100000);
    USBTFlagBuf0 = 0x00;
    }

    ADC12_A_startConversion(ADC12_A_BASE,
    ADC12_A_MEMORY_0,
    ADC12_A_REPEATED_SINGLECHANNEL);


    __bis_SR_register(LPM0_bits + GIE); // enter LPM0 with interrupt enable

    }

    }

    /*ISR for ADC Buffering*/
    #pragma vector = ADC12_VECTOR
    __interrupt void ADC12_A_ISR (void)
    {
    switch (__even_in_range(ADC12IV,34)){
    case 0: break; //Vector 0: No interrupt
    case 2: break; //Vector 2: ADC overflow
    case 4: break; //Vector 4: ADC timing overflow
    case 6: //Vector 6: ADC12IFG0


    switch (Sequencer){
    case 0x00:
    databuffX[Buffer_Index] = ADC12_A_getResults(ADC12_A_BASE,
    ADC12_A_MEMORY_0);
    GPIO_setOutputHighOnPin(GPIO_PORT_P1,GPIO_PIN0);
    ADC12_A_clearInterrupt(ADC12_A_BASE,
    ADC12IFG0);
    _bic_SR_register_on_exit(LPM0_bits + GIE);
    break; //case 0x00

    case 0x01:
    databuffY[Buffer_Index] = ADC12_A_getResults(ADC12_A_BASE,
    ADC12_A_MEMORY_0);
    GPIO_setOutputHighOnPin(GPIO_PORT_P1,GPIO_PIN1);
    ADC12_A_clearInterrupt(ADC12_A_BASE,
    ADC12IFG0);
    _bic_SR_register_on_exit(LPM0_bits + GIE);
    break; //case 0x01

    case 0x02:
    databuffZZ[Buffer_Index] = ADC12_A_getResults(ADC12_A_BASE,
    ADC12_A_MEMORY_0);
    GPIO_setOutputLowOnPin(GPIO_PORT_P1,GPIO_PIN0);
    ADC12_A_clearInterrupt(ADC12_A_BASE,
    ADC12IFG0);
    _bic_SR_register_on_exit(LPM0_bits + GIE);
    break; //Case 0x02

    case 0x03:
    databuffZ[Buffer_Index] = ADC12_A_getResults(ADC12_A_BASE,
    ADC12_A_MEMORY_0);
    GPIO_setOutputLowOnPin(GPIO_PORT_P1,GPIO_PIN1);
    ADC12_A_clearInterrupt(ADC12_A_BASE,
    ADC12IFG0);

    Buffer_Index++;
    if(Buffer_Index % 256 == 0)
    {
    USBTFlagBuf0 = 0x01; // After buffer fills halfway, send the filled half of the buffer through USB

    }
    if(Buffer_Index == 511)
    {
    USBTFlagBuf0 = 0x02;
    Buffer_Index = 0;
    }
    _bic_SR_register_on_exit(LPM0_bits + GIE);
    break; //case 0x03
    }
    Sequencer = (Sequencer + 1) & 0x03;
    break; // case 6;
    case 8: break; //Vector 8: ADC12IFG1
    case 10: break; //Vector 8: ADC12IFG2
    case 12: break; //Vector 8: ADC12IFG3
    case 14: break; //Vector 14: ADC12IFG4
    case 16: break; //Vector 16: ADC12IFG5
    case 18: break; //Vector 18: ADC12IFG6
    case 20: break; //Vector 20: ADC12IFG7
    case 22: break; //Vector 22: ADC12IFG8
    case 24: break; //Vector 24: ADC12IFG9
    case 26: break; //Vector 26: ADC12IFG10
    case 28: break; //Vector 28: ADC12IFG11
    case 30: break; //Vector 30: ADC12IFG12
    case 32: break; //Vector 32: ADC12IFG13
    case 34: break; //Vector 34: ADC12IFG14
    default: break;
    }
    }

    /*
    * ======== Init_Clock ========
    */
    VOID Init_Clock (VOID)
    {
    //Initialization of clock module
    if (USB_PLL_XT == 2){
    #if defined (__MSP430F552x) || defined (__MSP430F550x)
    P5SEL |= 0x0C; //enable XT2 pins for F5529
    #elif defined (__MSP430F563x_F663x)
    P7SEL |= 0x0C;
    #endif

    //use REFO for FLL and ACLK
    UCSCTL3 = (UCSCTL3 & ~(SELREF_7)) | (SELREF__REFOCLK);
    UCSCTL4 = (UCSCTL4 & ~(SELA_7)) | (SELA__REFOCLK);

    //MCLK will be driven by the FLL (not by XT2), referenced to the REFO
    Init_FLL_Settle(USB_MCLK_FREQ / 1000, USB_MCLK_FREQ / 32768); //Start the FLL, at the freq indicated by the config
    //constant USB_MCLK_FREQ
    XT2_Start(XT2DRIVE_0); //Start the "USB crystal"
    }
    else {
    #if defined (__MSP430F552x) || defined (__MSP430F550x)
    P5SEL |= 0x10; //enable XT1 pins
    #endif
    //Use the REFO oscillator to source the FLL and ACLK
    UCSCTL3 = SELREF__REFOCLK;
    UCSCTL4 = (UCSCTL4 & ~(SELA_7)) | (SELA__REFOCLK);

    //MCLK will be driven by the FLL (not by XT2), referenced to the REFO
    Init_FLL_Settle(USB_MCLK_FREQ / 1000, USB_MCLK_FREQ / 32768); //set FLL (DCOCLK)

    XT1_Start(XT1DRIVE_0); //Start the "USB crystal"
    }
    }

    /*
    * ======== Init_Ports ========
    */
    VOID Init_Ports (VOID)
    {
    //Initialization of ports (all unused pins as outputs with low-level
    P1OUT = 0x00;
    P1DIR = 0xFF;
    P2OUT = 0x00;
    P2DIR = 0xFF;
    P3OUT = 0x00;
    P3DIR = 0xFF;
    P4OUT = 0x00;
    P4DIR = 0xFF;
    P5OUT = 0x00;
    P5DIR = 0xFF;
    P6OUT = 0x00;
    P6DIR = 0xFF;
    P7OUT = 0x00;
    P7DIR = 0xFF;
    P8OUT = 0x00;
    P8DIR = 0xFF;
    #if defined (__MSP430F563x_F663x)
    P9OUT = 0x00;
    P9DIR = 0xFF;
    #endif
    }


    Thank you for any help you can give!

**Attention** This is a public forum