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.

Problem of using simpleUsbBackchannel on MSP430F5529 LaunchPad

Other Parts Discussed in Thread: MSP-EXP430F5529LP, MSP430WARE, MSP430F5529

Hi,

I've used CCS to download simpleUsbBackchannel (in MSP430Ware) on my MSP-EXP430F5529LP. It runs fine.

Now I want to change the UART port from USCI_A1 module to USCI_A0. So I need to do these change if soruce code:

  1. All "UCA1_x" change to "UCA0_x" in BCUart.h and BCUart.c.
  2. P4.4 (TXD) and P4.5 (RXD) change to P3.3 and P3.4 in BCUart.c, respectively.
  3. P6.7 (RTS) and P1.7 (CTS) change to P2.6 and P2.3, respectively.

But I can not find the P6.7 and P1.7 in these (main.c, BCUart.h and BCUart.c.) files. Where can I find them?

  • As the picture below (or you can find in SLAU533B p.44), where the definition of P6.7 and P1.7 as RTS and CTS, respectively?

  • 'hardwired' means, they are physically connected to the MSP pins. There is no way to change a physical wiring by software definitions.
    You can change the library code to use USCIA0 and any I/O pin you like, but then it won't be able to physically communicate using the backchannel UART feature.
    If you just want to use USCIA0 for a standard serial connection (and provide the proper external hardware connected to the USCIA0 pins then), you should use your own code. Or one of the many UART demo samples.
  • Thanks for Jens-Michael.

    I forgot to described the hardware platform I used. I used Anaren B-Smart BoosterPack (named cc2541BP) on MSP430F5529 LaunchPad (named F5529LP. These to board communicated through UART (USCI_A0 on F5529LP side and USART_0 on cc2541BP side), I think it's another hardwired.

    I've changed RxD and TxD from P4,5 and P4.4 to P3.4 and P3.3, respectively. But I can not find the definition of RTS and CTS of P6.7 and P1.7, respectively. So I can not change RTS and CTS to P2.6 and P2.3, respectively.

  • Probably there is no definition. The library has been written to support the application UART, so likely everything is hardcoded internally, except those features that are application-dependent, like using hardware flow control or not, using larger or smaller buffer for preserving ram if the application needs it.
    Chances are that you'll have to dig through all the source code and look for references to P6.7 and P1.7
  • Kai-Jung Shih said:

    I've changed RxD and TxD from P4,5 and P4.4 to P3.4 and P3.3, respectively. But I can not find the definition of RTS and CTS of P6.7 and P1.7, respectively. So I can not change RTS and CTS to P2.6 and P2.3, respectively.

    BCUart.h states the following:


    // There is no hardware RTS/CTS handshaking in this example.  Your code must
    // remain responsive to incoming UART data, to avoid overruns.

  • Thanks for Jens-Michael and Joseph. You are right, there is no hardware RTS/CTS in this example. I was confused by the User Guide of MSP-EXP430F5529LP.

    Now I try rewire it from USCI_A1 to USCI_A0.

    Before I modified, I can find the F5529 simpleUsbBackchannel port in Device Manager.

    But when I modified the bcUartInit() in BCUart.c as shown in below,

    // Initializes the USCI_A0 module as a UART, using baudrate settings in
    // bcUart.h.  The baudrate is dependent on SMCLK speed.
    void bcUartInit(void)
    {
    /*
    	// Always use the step-by-step init procedure listed in the USCI chapter of
        // the F5xx Family User's Guide
        UCA0CTL1 |= UCSWRST;        // Put the USCI state machine in reset	//KJ:
        UCA0CTL1 |= UCSSEL__SMCLK;  // Use SMCLK as the bit clock	//KJ:
    
        // Set the baudrate
        UCA0BR0 = UCA0_BR0;	//KJ:
        UCA0BR1 = UCA0_BR1;	//KJ:
        UCA0MCTL = (UCA0_BRF << 4) | (UCA0_BRS << 1) | (UCA0_OS);	//KJ:
    
        P3SEL |= BIT3+BIT4;         // Configure these pins as TXD/RXD
    
        UCA0CTL1 &= ~UCSWRST;       // Take the USCI out of reset	//KJ:
        UCA0IE |= UCRXIE;           // Enable the RX interrupt.  Now, when bytes are	//KJ:
                                    // rcv'ed, the USCI_A1 vector will be generated.
    */
    	UCA0CTL1 |= UCSWRST;
    
    	P3SEL |= BIT4;	//KJ: EAP_RX_ENABLE();
    	P3SEL |= BIT3;	//KJ: EAP_TX_ENABLE();
    
    	P2DIR |= BIT6;	//KJ: EAP_RX_ACK_CONFIG();
    	P2OUT |= BIT6;	//KJ: EAP_RX_ACK_SET();
    
    	P2DIR &= ~BIT3;	//KJ: EAP_TX_ACK_CONFIG();
    	P2IES |= BIT3;
    	P2IFG &= ~BIT3;
    //	P2IE |= BIT3;
    
    	// suspend the MCM
    	P2OUT &= ~BIT6;	//KJ: EAP_RX_ACK_CLR();
    
    	UCA0CTL1 |= UCSWRST;                      // **Put state machine in reset**
    	UCA0CTL1 |= UCSSEL_2;                     // SMCLK
    	UCA0BR0 = 9;                              // 1048576Hz/115200
    	UCA0BR1 = 0;                              // 1048576Hz/115200
    	UCA0MCTL |= UCBRS_1 + UCBRF_0;            // Modulation UCBRSx=1, UCBRFx=0
    	UCA0CTL1 &= ~UCSWRST;                     // **Initialize USCI state machine**
    
    }
    

    The simpleUsbBackcnahhel port was disappeared, and another Unknown Device shown,

    I try many times and find the problem occurred by line 84 ( I marked it). Why this problem occurred and how can I fix it?

  • You changes have impact on enumeration process, and probably program execution is stopped somewhere. If USCI_A1 is replaced with USCI_A0 then your modification are not enough. I am not familiar with LP UART bridge code, but you must also update thing regarding A1/A0 interrupts, and DMA if DMA is used.

    If it s possible, it will be much easier to map TX/RX pins that you need on port 4, without replacing USCI_A1 with USCI_A0 in source code.

  • I'm a bit puzzled by the purpose of the whole thing.
    Normally, the "Backchannel UART" or "Application UART" is implemented in the ezFET. It routes serial data from the target MSP to the PC. The data flow is:
    target MSP->USCIA1->eZFET->USB->PC->MSP Application UART1 COM-device.
    It doesn't seem to make much sense if the library serves UART1 on one side and routing it through USB to the PC on the other side, except for a PC-to-PC loopback.
    Zrno Soli is right. Something in your code seems to make the code flow stop and prevents the device from enumerating.
    However, the line you highlighted is a simple port pin I/O transaction that cannot stall. But of course this signal change may cause the attached hardware to do something that may then cause an interrupt that isn't properly handled. Or something like that.
    Check what clearing EAX_RX_ACK makes your booster pack do, and whether the code can handle this at this point.
    What if you move this line behind your initialization of the UART (maybe the booster pack immediately starts sending while the UART is still being configured)?
  • Thanks Jens-Michael,

    I tried to explain what I want to do in this link:
    https://docs.google.com/presentation/d/107c42BHT3mdGaXwtOtUVhLBK8KjXC0mh2dGX_OVAbrc/
    If any unclear, please tell me.


    Thanks Zrno,

    You are right, the Interrupt let the LaunchPad stocked. I add an ISR and simpleUsbBackchannel appear again. I also move some RX/TX procedure from main.c to BCUart.c. But it does not work too.

    main.c

    /* --COPYRIGHT--,BSD
     * Copyright (c) 2012, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
    //******************************************************************************
    //   MSP430F5529LP:  simpleUsbBackchannel example
    //
    //   Description: 	Demonstrates simple sending over USB, as well as the F5529's
    //                  backchannel UART.
    //
    //   Texas Instruments Inc.
    //   August 2013
    //******************************************************************************
    
    // Basic MSP430 and driverLib #includes
    #include "msp430.h"
    #include "driverlib/MSP430F5xx_6xx/wdt_a.h"
    #include "driverlib/MSP430F5xx_6xx/ucs.h"
    #include "driverlib/MSP430F5xx_6xx/pmm.h"
    #include "driverlib/MSP430F5xx_6xx/sfr.h"
    
    // USB API #includes
    #include "USB_config/descriptors.h"
    #include "USB_API/USB_Common/device.h"
    #include "USB_API/USB_Common/types.h"
    #include "USB_API/USB_Common/usb.h"
    
    #include "USB_app/usbConstructs.h"
    
    // Application #includes
    #include "BCUart.h"           // Include the backchannel UART "library"
    #include "hal.h"              // Modify hal.h to select your hardware
    
    
    /* You have a choice between implementing this as a CDC USB device, or a HID-
     * Datapipe device.  With CDC, the USB device presents a COM port on the host;
     * you interact with it with a terminal application, like Hyperterminal or
     * Docklight.  With HID-Datapipe, you interact with it using the Java HID Demo
     * App available within the MSP430 USB Developers Package.
     *
     * By default, this app uses CDC.  The HID calls are included, but commented
     * out.
     *
     * See the F5529 LaunchPad User's Guide for simple instructions to convert
     * this demo to HID-Datapipe.  For deeper information on CDC and HID-Datapipe,
     * see the USB API Programmer's Guide in the USB Developers Package.
     */
    
    
    // Global variables
    WORD rxByteCount;                        // Momentarily stores the number of bytes received
    BYTE buf_bcuartToUsb[BC_RXBUF_SIZE];     // Same size as the UART's rcv buffer
    BYTE buf_usbToBcuart[128];               // This can be any size
    
    
    void main(void)
    {
    	WDTCTL = WDTPW + WDTHOLD;		// Halt the dog
    
        // MSP430 USB requires a Vcore setting of at least 2.  2 is high enough
    	// for 8MHz MCLK, below.
        PMM_setVCore(PMM_BASE, PMM_CORE_LEVEL_2);
    
        initPorts();           // Config all the GPIOS for low-power (output low)
        initClocks(1048576);	//KJ: initClocks(8000000);   // Config clocks. MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz
        bcUartInit();          // Init the back-channel UART
        USB_setup(TRUE,TRUE);  // Init USB; if a USB host (PC) is present, connect
        __enable_interrupt();  // Enable interrupts globally
    
        while(1)
        {
    /* KJ:
           // Look for rcv'ed bytes on the backchannel UART. If any, send over USB.
           rxByteCount = bcUartReceiveBytesInBuffer(buf_bcuartToUsb);
           if(rxByteCount)
           {
               cdcSendDataInBackground(buf_bcuartToUsb, rxByteCount, CDC0_INTFNUM, 1000);
               //hidSendDataInBackground(buf_bcuartToUsb, rxByteCount, HID0_INTFNUM, 1000);
           }
    
           // Look for received bytes over USB. If any, send over backchannel UART.
           rxByteCount = cdcReceiveDataInBuffer(buf_usbToBcuart, sizeof(buf_usbToBcuart), CDC0_INTFNUM);
           //rxByteCount = hidReceiveDataInBuffer(buf_usbToBcuart, sizeof(buf_usbToBcuart), HID0_INTFNUM);
           if(rxByteCount)
           {
               bcUartSend(buf_usbToBcuart, rxByteCount);
           }
    */
        }
    
    }
    

    BCUart.h

    /* --COPYRIGHT--,BSD
     * Copyright (c) 2012, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
     /*
     * BCUart.h
     *
     *  Created on: Aug 14, 2013
     *      Author: a0199742
     */
    
    #ifndef BCUART_H_
    #define BCUART_H_
    
    #include "stdint.h"
    
    
    /*****************************************************************************
     *** SET THESE CONSTANTS, TO CONFIGURE THE BACKCHANNEL UART LIBRARY **********
    
    1) Set the SMCLK speed and desired baudrate.
    
       The baudrate is determined by the UCA0BR0, UCA0BR1, and UCA0MCTL registers.
       UCA0MCTL has three relevant fields:  UCA0BRF, UCA0BRS, and UCOS16.  The
       settings below are for:
       SMCLK = 1048576Hz
       baudrate = 115200bps
    
       If you change the SMCLK speed, or want a different baudrate, you need to
       change these values.  An easy way to determine them is the calculator at
       the MSP430 wiki page:
    
    http://processors.wiki.ti.com/index.php/USCI_UART_Baud_Rate_Gen_Mode_Selection
    
       (If the link is somehow broken, the wiki page name is "USCI UART Baud Rate
       Gen Mode Selection", or try web-searching "msp430 usci calculator".
       Ultimately, the final reference is the UCS chapter of the F5xx Family User's
       Guide.) */
    
    #define UCA0_OS   0		// 1 = oversampling mode, 0 = low-freq mode
    #define UCA0_BR0  9		//KJ: 17	// Value of UCA0BR0 register
    #define UCA0_BR1  0		//KJ: 0		// Value of UCA0BR1 register
    #define UCA0_BRS  1		//KJ: 0		// Value of UCBRS field in UCA0MCTL register
    #define UCA0_BRF  0		//KJ: 6		// Value of UCBRF field in UCA0MCTL register
    
    
    // There is no hardware RTS/CTS handshaking in this example.  Your code must
    // remain responsive to incoming UART data, to avoid overruns.
    
    
    /*
    
    2) If needed, re-configure the library's characteristics:
    
    The size of the UART receive buffer.  Set smaller if RAM is in short supply.
    Set larger if larger data chunks are to be received, or if the application
    can't process incoming data very often   */
    #define BC_RXBUF_SIZE  (128)
    
    /* The threshold within bcUartRcvBuf at which main() will be awakened.  Must
    be less than BC_RXBUF_SIZE.  A value of '1' will alert main() whenever
    even a single byte is received.  If no wake is desired, set to
    BC_RXBUF_SIZE+1     */
    #define BC_RX_WAKE_THRESH  (1)
    
    // ****************************************************************************
    
    
    void bcUartInit(void);
    void bcUartSend(uint8_t* buf, uint8_t len);
    uint16_t bcUartReceiveBytesInBuffer(uint8_t* buf);
    
    #endif /* BCUART_H_ */
    

    BCUart.c

    /* --COPYRIGHT--,BSD
     * Copyright (c) 2012, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
     
    #include "msp430.h"
    #include "BCUart.h"
    
    #include "USB_config/descriptors.h"
    #include "USB_app/usbConstructs.h"
    
    extern WORD rxByteCount;                        // Momentarily stores the number of bytes received
    extern BYTE buf_bcuartToUsb[BC_RXBUF_SIZE];     // Same size as the UART's rcv buffer
    extern BYTE buf_usbToBcuart[128];               // This can be any size
    
    
    // Receive buffer for the UART.  Incoming bytes need a place to go immediately,
    // otherwise there might be an overrun when the next comes in.  The USCI ISR
    // puts them here.
    uint8_t  bcUartRcvBuf[BC_RXBUF_SIZE];
    
    // The index within bcUartRcvBuf, where the next byte will be written.
    uint16_t bcUartRcvBufIndex = 0;
    
    // Boolean flag indicating whether bcUartRcvBufIndex has reached the
    // threshold BC_RX_WAKE_THRESH.  0 = FALSE, 1 = TRUE
    uint8_t  bcUartRxThreshReached = 0;
    
    
    // Initializes the USCI_A0 module as a UART, using baudrate settings in
    // bcUart.h.  The baudrate is dependent on SMCLK speed.
    void bcUartInit(void)
    {
        // Always use the step-by-step init procedure listed in the USCI chapter of
        // the F5xx Family User's Guide
        UCA0CTL1 |= UCSWRST;        // Put the USCI state machine in reset	//KJ:
        UCA0CTL1 |= UCSSEL__SMCLK;  // Use SMCLK as the bit clock	//KJ:
    
        // Set the baudrate
        UCA0BR0 = UCA0_BR0;	//KJ:
        UCA0BR1 = UCA0_BR1;	//KJ:
        UCA0MCTL = (UCA0_BRF << 4) | (UCA0_BRS << 1) | (UCA0_OS);	//KJ:
    
        P3SEL |= BIT3+BIT4;         // Configure these pins as TXD/RXD
    
        P2DIR |= BIT6;	//KJ: EAP_RX_ACK_CONFIG();
    	P2OUT |= BIT6;	//KJ: EAP_RX_ACK_SET();
    
    	P2DIR &= ~BIT3;	//KJ: EAP_TX_ACK_CONFIG();
    	P2IES |= BIT3;
    	P2IFG &= ~BIT3;
    	P2IE |= BIT3;
    
    	// suspend the MCM
    	P2OUT &= ~BIT6;	//KJ: EAP_RX_ACK_CLR();
    
        UCA0CTL1 &= ~UCSWRST;       // Take the USCI out of reset	//KJ:
        UCA0IE |= UCRXIE;           // Enable the RX interrupt.  Now, when bytes are	//KJ:
                                    // rcv'ed, the USCI_A1 vector will be generated.
    }
    
    
    // Sends 'len' bytes, starting at 'buf'
    void bcUartSend(uint8_t * buf, uint8_t len)
    {
        uint8_t i = 0;
    
        // Write each byte in buf to USCI TX buffer, which sends it out
        while (i < len)
        {
            UCA0TXBUF = *(buf+(i++));	//KJ:
    
            // Wait until each bit has been clocked out...
            while(!(UCTXIFG==(UCTXIFG & UCA0IFG))&&((UCA0STAT & UCBUSY)==UCBUSY));	//KJ:
        }
    }
    
    
    // Copies into 'buf' whatever bytes have been received on the UART since the
    // last fetch.  Returns the number of bytes copied.
    uint16_t bcUartReceiveBytesInBuffer(uint8_t* buf)
    {
        uint16_t i, count;
    
        // Hold off ints for incoming data during the copy
        UCA0IE &= ~UCRXIE;	//KJ:
    
        for(i=0; i<bcUartRcvBufIndex; i++)
        {
            buf[i] = bcUartRcvBuf[i];
        }
    
        count = bcUartRcvBufIndex;
        bcUartRcvBufIndex = 0;     // Move index back to the beginning of the buffer
        bcUartRxThreshReached = 0;
    
        // Restore USCI interrupts, to resume receiving data.
        UCA0IE |= UCRXIE;	//KJ:
    
        return count;
    }
    
    
    
    // The USCI_A0 receive interrupt service routine (ISR).  Executes every time a
    // byte is received on the back-channel UART.
    #pragma vector=USCI_A0_VECTOR	//KJ:
    __interrupt void bcUartISR(void)
    {
        bcUartRcvBuf[bcUartRcvBufIndex++] = UCA0RXBUF;  // Fetch the byte, store	//KJ:
                                                        // it in the buffer.
    
        P2OUT &= ~BIT6;	//KJ: EAP_RX_ACK_CLR();
        P2OUT |= BIT6;	//KJ: EAP_RX_ACK_SET();
    
        // Wake main, to fetch data from the buffer.
        if(bcUartRcvBufIndex >= BC_RX_WAKE_THRESH)
        {
            bcUartRxThreshReached = 1;
            __bic_SR_register_on_exit(LPM3_bits);       // Exit LPM0-3
        }
    }
    
    
    
    
    #pragma vector=PORT2_VECTOR	//KJ: EAP_TX_ACK_VECTOR
    __interrupt void txAckIsr(void)
    {
        if (P2IFG & BIT3)	//KJ: EAP_TX_ACK_TST()
        {
            // Look for received bytes over USB. If any, send over backchannel UART.
            rxByteCount = cdcReceiveDataInBuffer(buf_usbToBcuart, sizeof(buf_usbToBcuart), CDC0_INTFNUM);
            //rxByteCount = hidReceiveDataInBuffer(buf_usbToBcuart, sizeof(buf_usbToBcuart), HID0_INTFNUM);
            if(rxByteCount)
            {
                bcUartSend(buf_usbToBcuart, rxByteCount);
            }
        }
        __bic_SR_register_on_exit(LPM3_bits);	//KJ: WAKEUP();
    }
    
    

  • Hi all,


    If I want to add flow control in simpleUsbBackchannel example, any sample code?

    I've try to mark the read/write in main.c:

    /* --COPYRIGHT--,BSD
     * Copyright (c) 2012, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
    //******************************************************************************
    //   MSP430F5529LP:  simpleUsbBackchannel example
    //
    //   Description: 	Demonstrates simple sending over USB, as well as the F5529's
    //                  backchannel UART.
    //
    //   Texas Instruments Inc.
    //   August 2013
    //******************************************************************************
    
    // Basic MSP430 and driverLib #includes
    #include "msp430.h"
    #include "driverlib/MSP430F5xx_6xx/wdt_a.h"
    #include "driverlib/MSP430F5xx_6xx/ucs.h"
    #include "driverlib/MSP430F5xx_6xx/pmm.h"
    #include "driverlib/MSP430F5xx_6xx/sfr.h"
    
    // USB API #includes
    #include "USB_config/descriptors.h"
    #include "USB_API/USB_Common/device.h"
    #include "USB_API/USB_Common/types.h"
    #include "USB_API/USB_Common/usb.h"
    
    #include "USB_app/usbConstructs.h"
    
    // Application #includes
    #include "BCUart.h"           // Include the backchannel UART "library"
    #include "hal.h"              // Modify hal.h to select your hardware
    
    
    /* You have a choice between implementing this as a CDC USB device, or a HID-
     * Datapipe device.  With CDC, the USB device presents a COM port on the host;
     * you interact with it with a terminal application, like Hyperterminal or
     * Docklight.  With HID-Datapipe, you interact with it using the Java HID Demo
     * App available within the MSP430 USB Developers Package.
     *
     * By default, this app uses CDC.  The HID calls are included, but commented
     * out.
     *
     * See the F5529 LaunchPad User's Guide for simple instructions to convert
     * this demo to HID-Datapipe.  For deeper information on CDC and HID-Datapipe,
     * see the USB API Programmer's Guide in the USB Developers Package.
     */
    
    
    // Global variables
    WORD rxByteCount;                        // Momentarily stores the number of bytes received
    BYTE buf_bcuartToUsb[BC_RXBUF_SIZE];     // Same size as the UART's rcv buffer
    BYTE buf_usbToBcuart[128];               // This can be any size
    
    
    void main(void)
    {
    	WDTCTL = WDTPW + WDTHOLD;		// Halt the dog
    
        // MSP430 USB requires a Vcore setting of at least 2.  2 is high enough
    	// for 8MHz MCLK, below.
        PMM_setVCore(PMM_BASE, PMM_CORE_LEVEL_2);
    
        initPorts();           // Config all the GPIOS for low-power (output low)
        initClocks(1048576);	//KJ: initClocks(8000000);   // Config clocks. MCLK=SMCLK=FLL=8MHz; ACLK=REFO=32kHz
        bcUartInit();          // Init the back-channel UART
        USB_setup(TRUE,TRUE);  // Init USB; if a USB host (PC) is present, connect
        __enable_interrupt();  // Enable interrupts globally
    
        while(1)
        {
    /*
           // Look for rcv'ed bytes on the backchannel UART. If any, send over USB.
           rxByteCount = bcUartReceiveBytesInBuffer(buf_bcuartToUsb);
           if(rxByteCount)
           {
               cdcSendDataInBackground(buf_bcuartToUsb, rxByteCount, CDC0_INTFNUM, 1000);
               //hidSendDataInBackground(buf_bcuartToUsb, rxByteCount, HID0_INTFNUM, 1000);
           }
    
           // Look for received bytes over USB. If any, send over backchannel UART.
           rxByteCount = cdcReceiveDataInBuffer(buf_usbToBcuart, sizeof(buf_usbToBcuart), CDC0_INTFNUM);
           //rxByteCount = hidReceiveDataInBuffer(buf_usbToBcuart, sizeof(buf_usbToBcuart), HID0_INTFNUM);
           if(rxByteCount)
           {
               bcUartSend(buf_usbToBcuart, rxByteCount);
           }
    */
        }
    }
    
    
    
    

    and I also add interrupt for CTS in BCUart.c:

    /* --COPYRIGHT--,BSD
     * Copyright (c) 2012, Texas Instruments Incorporated
     * All rights reserved.
     *
     * Redistribution and use in source and binary forms, with or without
     * modification, are permitted provided that the following conditions
     * are met:
     *
     * *  Redistributions of source code must retain the above copyright
     *    notice, this list of conditions and the following disclaimer.
     *
     * *  Redistributions in binary form must reproduce the above copyright
     *    notice, this list of conditions and the following disclaimer in the
     *    documentation and/or other materials provided with the distribution.
     *
     * *  Neither the name of Texas Instruments Incorporated nor the names of
     *    its contributors may be used to endorse or promote products derived
     *    from this software without specific prior written permission.
     *
     * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
     * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
     * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
     * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
     * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
     * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     * --/COPYRIGHT--*/
     
    #include "msp430.h"
    #include "BCUart.h"
    
    #include "USB_config/descriptors.h"
    #include "USB_app/usbConstructs.h"
    
    extern WORD rxByteCount;                        // Momentarily stores the number of bytes received
    extern BYTE buf_bcuartToUsb[BC_RXBUF_SIZE];     // Same size as the UART's rcv buffer
    extern BYTE buf_usbToBcuart[128];               // This can be any size
    
    
    // Receive buffer for the UART.  Incoming bytes need a place to go immediately,
    // otherwise there might be an overrun when the next comes in.  The USCI ISR
    // puts them here.
    uint8_t  bcUartRcvBuf[BC_RXBUF_SIZE];
    
    // The index within bcUartRcvBuf, where the next byte will be written.
    uint16_t bcUartRcvBufIndex = 0;
    
    // Boolean flag indicating whether bcUartRcvBufIndex has reached the
    // threshold BC_RX_WAKE_THRESH.  0 = FALSE, 1 = TRUE
    uint8_t  bcUartRxThreshReached = 0;
    
    
    // Initializes the USCI_A1 module as a UART, using baudrate settings in
    // bcUart.h.  The baudrate is dependent on SMCLK speed.
    void bcUartInit(void)
    {
        // Always use the step-by-step init procedure listed in the USCI chapter of
        // the F5xx Family User's Guide
        UCA1CTL1 |= UCSWRST;        // Put the USCI state machine in reset
        UCA1CTL1 |= UCSSEL__SMCLK;	// Use SMCLK as the bit clock
    
        // Set the baudrate
        UCA1BR0 = UCA1_BR0;
        UCA1BR1 = UCA1_BR1;
        UCA1MCTL = UCBRS_1 + UCBRF_0;
    
        P4SEL |= BIT4+BIT5;         // Configure these pins as TXD/RXD
    
        P6DIR |= BIT7;	//KJ: EAP_RX_ACK_CONFIG();
    	P6OUT |= BIT7;	//KJ: EAP_RX_ACK_SET();
    
    	P1DIR &= ~BIT7;	//KJ: EAP_TX_ACK_CONFIG();
    	P1IES |= BIT7;
    	P1IFG &= ~BIT7;
    	P1IE |= BIT7;
    
    	// suspend the MCM
    	P6OUT &= ~BIT7;	//KJ: EAP_RX_ACK_CLR();
    
        UCA1CTL1 &= ~UCSWRST;       // Take the USCI out of reset
        UCA1IE |= UCRXIE;           // Enable the RX interrupt.  Now, when bytes are
                                    // rcv'ed, the USCI_A1 vector will be generated.
    }
    
    
    // Sends 'len' bytes, starting at 'buf'
    void bcUartSend(uint8_t * buf, uint8_t len)
    {
        uint8_t i = 0;
    
        // Write each byte in buf to USCI TX buffer, which sends it out
        while (i < len)
        {
            UCA1TXBUF = *(buf+(i++));
    
            // Wait until each bit has been clocked out...
            while(!(UCTXIFG==(UCTXIFG & UCA1IFG))&&((UCA1STAT & UCBUSY)==UCBUSY));
        }
    }
    
    
    // Copies into 'buf' whatever bytes have been received on the UART since the
    // last fetch.  Returns the number of bytes copied.
    uint16_t bcUartReceiveBytesInBuffer(uint8_t* buf)
    {
        uint16_t i, count;
    
        // Hold off ints for incoming data during the copy
        UCA1IE &= ~UCRXIE;
    
        for(i=0; i<bcUartRcvBufIndex; i++)
        {
            buf[i] = bcUartRcvBuf[i];
        }
    
        count = bcUartRcvBufIndex;
        bcUartRcvBufIndex = 0;     // Move index back to the beginning of the buffer
        bcUartRxThreshReached = 0;
    
        // Restore USCI interrupts, to resume receiving data.
        UCA1IE |= UCRXIE;
    
        return count;
    }
    
    
    /*
    // The USCI_A1 receive interrupt service routine (ISR).  Executes every time a
    // byte is received on the back-channel UART.
    #pragma vector=USCI_A1_VECTOR
    __interrupt void bcUartISR(void)
    {
        bcUartRcvBuf[bcUartRcvBufIndex++] = UCA1RXBUF;  // Fetch the byte, store
                                                        // it in the buffer.
    
        // Wake main, to fetch data from the buffer.
        if(bcUartRcvBufIndex >= BC_RX_WAKE_THRESH)
        {
            bcUartRxThreshReached = 1;
            __bic_SR_register_on_exit(LPM3_bits);       // Exit LPM0-3
        }
    }
    */
    
    #pragma vector=PORT1_VECTOR	//KJ: EAP_TX_ACK_VECTOR
    __interrupt void bcCtsIsr(void)
    {
        if (P1IFG & BIT7)	//KJ: EAP_TX_ACK_TST()
        {
            // Look for received bytes over USB. If any, send over backchannel UART.
            rxByteCount = cdcReceiveDataInBuffer(buf_usbToBcuart, sizeof(buf_usbToBcuart), CDC0_INTFNUM);
            //rxByteCount = hidReceiveDataInBuffer(buf_usbToBcuart, sizeof(buf_usbToBcuart), HID0_INTFNUM);
            if(rxByteCount)
            {
                bcUartSend(buf_usbToBcuart, rxByteCount);
            }
        }
        __bic_SR_register_on_exit(LPM3_bits);	//KJ: WAKEUP();
    }
    
    

    Now I can send message from CDC to bcUART by using flow control, but can not send from bcUART to CDC.

    Can someone help me?

**Attention** This is a public forum