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.

Information Logging

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

What we have:

MSP430F5529

MSP430G2

CCS (the latest version I believe) as the interfacing software

Problem:  We need to log information obtained from the ADC ideally into a text file.  

Methods used:  We have been trying to use UART to communicate through the USB to the computer host, but we have not been able to print it to a terminal, much less port the output to a text file.  We have modified the options to get printf() to work on the CCS console, which wasn't our end goal.

Overall Question:  Is there an easy (non-roundabout) way to doing this?  If so, how do we do it?  Example code?  If these models are insufficient or difficult to work with in relation to doing this, which MSP model would you suggest in performing this operation?  Is this a software issue, as in CCS drawbacks?  Any help, suggestions, and example code would be appreciated.  Thanks bunches. 

  • An easy way to output to a txt file?  It's not going to be that simple with only a UART connection.  Easiest solution would be sending characters over UART to a terminal and then copy/paste or save the terminal log into a text file.  Otherwise you need a GUI/software conversion program to accept the UART characters and write them into a pre-existing text file within a known location.  Sending strings over UART itself without using printf() is not too hard.  For example:

    unsigned int i = 0;
    const char string[] = {"ADC value: "}; //Strings being sent to the PC
    const int size = 10; //String size
    const char endlinestring[] = {"\n\r"}; //Command to end line
    const int endlinesize = 4;

    //Send the string
    for(i=0; i<=size; i++)
    {
    while(!(UCA0IFG&UCTXIFG));
    UCA0TXBUF = string[i];
    }

    //Sends the adc raw value, will have to be converted from ASCII to hex/dec here or on host side for meaningful data
    while(!(UCA0IFG&UCTXIFG));
    UCA0TXBUF = saved_adc_value;                                  //From ADC12MEMx conversion results

    //Start a new line for the next string
    for(i=0; i<=endlinesize; i++)
    {
    while(!(UCA0IFG&UCTXIFG));
    UCA0TXBUF = endlinestring[i];
    }

    Regards,

    Ryan

  • Thank you Ryan,

    However, with the above code, I am not getting anything. I am using putty and verified the baud rate and which COM port is correct. I am using serial communication, but it will not work. I understand what I need to do, and I have tried numerous examples, as well as taken a crack at it on my own. Besides UART, is there anything else you suggest for this? Can you also give me a more comprehensive example regarding this?
  • Let's cover our bases so we can figure out what is going on.  These instructions are for a MSP-EXP430F5529LP (F5529 LaunchPad) and will need to be changed depending on the device you are using:

    1. Download the MSP430F552x C Examples package and load MSP430F55xx_uscia0_uart_04.c (9600 UART Echo) to your device.

    2. Make sure that the RXD and TXD jumpers are correctly installed in the upright position.

    3. Confirm that your putty configuration is as shown (with your own COM port setting, of course).  Serial settings should already be correct but check to see that it's in the format of 8 data bits, 1 stop bit, and no parity.

    4. Open the COM port and type something into your keyboard.  The terminal should not have local echo turned on, so any characters that appear on the terminal are coming from your MSP430 device.

    Once you can confirm that you have communication working with this demo, it should be easier to ramp development of your own application.

    Regards,

    Ryan

  • Ryan,

    So I have performed this demo before, but I have not received anything from it.  The only thing that you proposed that I had not done earlier was putting the RXD and TXD jumpers in the upright position, thus connecting RXD to TXD (This should have been obvious to me before).  In the code presented, it cycles at the bold code I put up.  It runs through it all and just cycles in LPM.  It picks up noise (accidentally rubbing fingers across created jumbled garbage on terminal output), and when I paused the code to write directly to the TXD buffer, it erases it before resuming.  It there a way I can shove in input and get an output with this demo?  I really appreciate this Ryan.  

    #include <msp430.h>

    int main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop WDT
    P3SEL = BIT3+BIT4; // P3.4,5 = USCI_A0 TXD/RXD
    UCA0CTL1 |= UCSWRST; // **Put state machine in reset**
    UCA0CTL1 |= UCSSEL_2; // SMCLK
    UCA0BR0 = 6; // 1MHz 9600 (see User's Guide)
    UCA0BR1 = 0; // 1MHz 9600
    UCA0MCTL = UCBRS_0 + UCBRF_13 + UCOS16; // Modln UCBRSx=0, UCBRFx=0,
    // over sampling
    UCA0CTL1 &= ~UCSWRST; // **Initialize USCI state machine**
    UCA0IE |= UCRXIE; // Enable USCI_A0 RX interrupt

    __bis_SR_register(LPM0_bits + GIE); // Enter LPM0, interrupts enabled
    __no_operation(); // For debugger
    }

    // Echo back RXed character, confirm TX buffer is ready first
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector=USCI_A0_VECTOR
    __interrupt void USCI_A0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(USCI_A0_VECTOR))) USCI_A0_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
    switch(__even_in_range(UCA0IV,4))
    {
    case 0:break; // Vector 0 - no interrupt
    case 2: // Vector 2 - RXIFG
    while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
    UCA0TXBUF = UCA0RXBUF; // TX -> RXed character
    break;
    case 4:break; // Vector 4 - TXIFG
    default: break;
    }
    }

  • Rahim,

    If I'm understanding your message correctly, you're trying to pause the debugger and change the line UCA0TXBUF = UCA0RXBUF; to a desired value before continuing to run? If that's the case then you must understand that code cannot be changed or altered while within debugger mode, only run through and observed. Right now the code is set up to receive characters into UCA0RXBUF, in which an interrupt service routine occurs to send those same characters back out through UCA0TXBUF (hence an echo). If you want to change the value the UART sends you must exit debugger mode, change the value of UCA0TXBUF manually, and re-compile the code. An easy example: if I wanted this code to simply respond "Hi" each time something was pressed on the keyboard, I would put the following lines into case 2:

    while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
    UCA0TXBUF = 0x48; // ASCII character "H"
    while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
    UCA0TXBUF = 0x69; // ASCII character "i"
    while (!(UCA0IFG&UCTXIFG)); // USCI_A0 TX buffer ready?
    UCA0TXBUF = 0x0A; // ASCII new line command

    Regards,
    Ryan
  • Ryan,

    So what I have been doing was something learned in class awhile back.  Through the IDE, I was going in and changing the value in the TXD register.  That was not working.  I did what you suggested, but it still cycles on that piece.  How do I trigger the interrupt?  Keyboard presses is not working.  Neither are presses of the buttons on the microcontroller (I just tried it, but I know that the ISR's for the UART are triggered elsewhere.).

  • Rahim,

    This specific interrupt pertains to vector 2 of the USCIA0 ISR, which triggers when the RXIFG flag is set high.  This happens after a value is received from the sender and stored in UCA0RXBUF.

    Regards,

    Ryan

  • Ryan,

    So what do I need to do to trigger the flag?  I need to send something into the UCA0RXBUFFER?  What steps do I take to perform this action?

  • Flag triggers automatically when information is received by the other UART device, and by no means do you put something into UCA0RXBUFFER.
  • As you are using F55xx are you trying to use USB HID to send the data?
    Or you are trying to use UART backdoor of a Launchpad?

    To send a text string all the data have to be converted in ascii, and you need a receiver program that is getting the data and saving it
    Or maybe just copy and paste the screen? terterm is a terminal program that should do it.

    Send data with usci is simple, just write a byte to txbuff and away it goes. you get a IRQ when it's ready for a new byte in its buffered register.

  • USB.  The only thing it is connected is my desktop to my USB to my MSP.  

  • I am confused? There is minutia details that I am missing. What do I physically need to do to trigger the flag?
  • Ryan, I guess you have a general misunderstanding here. The buffer registers (all module registers) are actually port interfaces to independent circuitry. Thy are no classic variables, even if they appear to the CPU as such.
    Writing to or reading from them will not just put a value into a memory cell. I twill trigger immediate actions and has side effects. The Debugger only holds and controls the CPU. It does not 'freeze' the rest of the world. Not even most of the peripheral circuitry.
    It's like debugging a radio receiver and expecting the radio waves to stop coming in when you hit a breakpoint.

    The CCS console works (more or less) this way: there is an empty putchar and getchar function where you normally would place code to send/receive data through any kind of interface. Instead, CCS puts a breakpoint in there and when the function is called, it 'writes' the actual value into or reads it from the function parameters.
    So after all, the MSP is not doing anything (the values are fetched from or written to processor registers magically through JTAG) and no peripheral is used for the transfer at all. However, JTAG transfers need to be initiated by the host and cannot be triggered by the MSP
    (which doesn't know that some JTAG will halt the CPU and do something to the registers or memory).

    In your case, you'll need to write your own putchar function (which overrides the empty default) and implement code that writes the bytes generated by printf and sent to putchar then to TXBUF for transmission.
    Or you write your own getch() function and implement code that reads RXBUF if data has arrived (or zero if no new data has arrived since last call).
    Synchronization (not sending faster than the UART can send) is your job to implement.
    And of course, you'll need to establish a physical connection. Like using a MAX3232 on the UART RX/TX pins and connect the signals to a real COM port then.
    Some EXP boards provide an 'application UART' serial channel through its programming interface (has nothing to do with JTAG and debugging and provides an additional virtual COM port on the PC). In any case you'll have to write code that utilizes the MSP UART hardware.

**Attention** This is a public forum