CCS/MSP430L092: How can I read my sensor value?

Part Number: MSP430L092

Tool/software: Code Composer Studio

I have a code about msp430g2553 for ADC analog read but I want to make a project with msp430l092 so when I have tried to work with my code that is related with g2553, I got a problem. This code conflicts with l092. How can I create a code for reading analog sensor value (photodiode)? Can someone give me a code about it? Additionally, I realized that l092 doesn't have UART so I cannot see my sensor value on console terminal.

  • Hi,

    Have you checked out the examples in MSP430Ware? There are examples showing how to properly use the ADC on the MSP430L092. Regarding "seeing" the ADC results, you can use the debugger in CCS along with breakpoints to view the code at points of interest and see the value of variables. Please take a look at these examples and let me know if you need any more help.

    Best regards, 

    Caleb Overbay

  • In reply to Caleb Overbay:

    I investigated all example projects but I couldn't find my mcu family that is msp430l092.
    MSP430 Driver Library (MSP430F5xx_6xx Family)
    MSP430 Driver Library (MSP430FR57xx Family)
    MSP430 Driver Library (MSP430FR5xx_6xx Family)
    MSP430 Driver Library (MSP430i2xx Family)
    There are just application notes. I don't have any useful code or example projects
  • You can download code examples here. There are examples for the ADC included as well:

    • msp430x09x_apool_adc_01.c       APOOL_ADC, conversion without Error Compensation, Sample A0
    • msp430x09x_apool_adc_02.c       APOOL_ADC, conversion with Overdrive Compensation, Sample A0
    • msp430x09x_apool_adc_03.c       APOOL_ADC, conversion with Offset Compensation, Sample A0
    • msp430x09x_apool_adc_04.c       APOOL_ADC, Vcc Monitoring
    • msp430x09x_apool_adc_05.c       APOOL_ADC, Timer_A0 Triggered
    • msp430x09x_apool_adc_06.c       APOOL_ADC, Sampled Temperature and Convert to oC
    • msp430x09x_apool_adc_07.c       APOOL_ADC, Sample Multiple ADC Channels

    user4830858
    I realized that l092 doesn't have UART

    If you need the data to be outputted in a terminal program, you can try to write a timer based software UART - examples can be found in these code examples:

    • msp430g2xx2_ta_uart2400.c        Timer_A, Ultra-Low Pwr UART 2400 Echo, 32kHz ACLK
    • msp430g2xx2_ta_uart9600.c        Timer_A, Ultra-Low Pwr Full-duplex UART 9600, 32kHz ACLK

    Dennis


  • In reply to Dennis Eichmann:

    Thank you very much. The example code works for ADC very well. I want to see my sensor  value on terminal console. I used these code

    msp430g2xx2_ta_uart2400.c        Timer_A, Ultra-Low Pwr UART 2400 Echo, 32kHz ACLK

    msp430g2xx2_ta_uart9600.c        Timer_A, Ultra-Low Pwr Full-duplex UART 9600, 32kHz ACLK

    but they didn't work with msp430l092. I got some errors.

    Can you give me a suggestion to see my analog value from sensor?

  • In reply to user4830858:

    Well, yeah, you may not be able to use the example 1:1 - you will have to change some register names. Have a look into the user's guide and into the header file for the processor to see the right register names.


  • In reply to Dennis Eichmann:

    Thanks Dennis Eichmann for your reply. I will try to change registers according to my mcu registers but are you sure that it works with UART? I learnt that MSP430L092 doesn't have UART. I am confused a little bit.
  • In reply to user4830858:

    I never used the part you are using at the moment, but in general you can establish a UART connection based on the timer module. The examples I linked in are from a processor that does not have a UART as well (MSP430G2402). I don't know about the available clock sources for the MSP430L092 - I would have to look that up. What clock do you use? For UART, the clock accuracy is relatively important.


  • In reply to Dennis Eichmann:

    ACLK MCLK and SMCLK are clocks for msp430l092. After I took code from msp430g2xx2_ta_uart9600, I replaced registers that are suitable with msp430l092  but I didn't prepare clock code. I have checked my code on  terminal console. There are no any messages.


    * --/COPYRIGHT--*/
    //******************************************************************************
    // MSP430G2xx2 Demo - Timer_A, Ultra-Low Pwr UART 9600 Echo, 32kHz ACLK
    //
    // Description: Use Timer_A CCR0 hardware output modes and SCCI data latch
    // to implement UART function @ 9600 baud. Software does not directly read and
    // write to RX and TX pins, instead proper use of output modes and SCCI data
    // latch are demonstrated. Use of these hardware features eliminates ISR
    // latency effects as hardware insures that output and input bit latching and
    // timing are perfectly synchronised with Timer_A regardless of other
    // software activity. In the Mainloop the UART function readies the UART to
    // receive one character and waits in LPM3 with all activity interrupt driven.
    // After a character has been received, the UART receive function forces exit
    // from LPM3 in the Mainloop which configures the port pins (P1 & P2) based
    // on the value of the received byte (i.e., if BIT0 is set, turn on P1.0).

    // ACLK = TACLK = LFXT1 = 32768Hz, MCLK = SMCLK = default DCO
    // //* An external watch crystal is required on XIN XOUT for ACLK *//
    //
    // MSP430G2xx2
    // -----------------
    // /|\| XIN|-
    // | | | 32kHz
    // --|RST XOUT|-
    // | |
    // | CCI0B/TXD/P1.1|-------->
    // | | 9600 8N1
    // | CCI0A/RXD/P1.2|<--------
    //
    // D. Dang
    // Texas Instruments Inc.
    // December 2010
    // Built with CCS Version 4.2.0 and IAR Embedded Workbench Version: 5.10
    //******************************************************************************

    #include <msp430.h>

    //------------------------------------------------------------------------------
    // Hardware-related definitions
    //------------------------------------------------------------------------------
    #define UART_TXD 0x02 // TXD on P1.1 (Timer0_A.OUT0)
    #define UART_RXD 0x04 // RXD on P1.2 (Timer0_A.CCI1A)

    //------------------------------------------------------------------------------
    // Conditions for 9600 Baud SW UART, SMCLK = 1MHz
    //------------------------------------------------------------------------------
    #define UART_TBIT_DIV_2 (1000000 / (9600 * 2))
    #define UART_TBIT (1000000 / 9600)

    //------------------------------------------------------------------------------
    // Global variables used for full-duplex UART communication
    //------------------------------------------------------------------------------
    unsigned int txData; // UART internal variable for TX
    unsigned char rxBuffer; // Received UART character

    //------------------------------------------------------------------------------
    // Function prototypes
    //------------------------------------------------------------------------------
    void TimerA_UART_init(void);
    void TimerA_UART_tx(unsigned char byte);
    void TimerA_UART_print(char *string);

    //------------------------------------------------------------------------------
    // main()
    //------------------------------------------------------------------------------
    int main(void)
    {
    WDTCTL = WDTPW + WDTHOLD; // Stop watchdog timer

    /*
    if (CALBC1_1MHZ==0xFF) // If calibration constants erased
    {
    while(1); // do not load, trap CPU!!
    }

    */


    /*
    DCOCTL = 0; // Select lowest DCOx and MODx settings
    BCSCTL1 = CALBC1_1MHZ;
    DCOCTL = CALDCO_1MHZ;
    */


    /************************/
    /* Setup CCS */
    /* ACLK = CLKIN/1 */
    /* MCLK = CLKIN/1 */
    /* SMCLK = CLKIN/1 */
    /************************/
    CCSCTL0 = CCSKEY; // Unlock CCS

    while (SFRIFG1 & OFIFG) // Oscillator Flag(s)?
    {
    CCSCTL7 = 0; // Clear HF & LF OSC fault flags
    SFRIFG1 = 0; // Clear OFIFG
    }
    CCSCTL5 = DIVA_0 + DIVM_0 + DIVS_0; // Set the Dividers for ACLK, MCLK, and SMCLK to 1
    CCSCTL4 |= SELA_2 + SELM_2 + SELS_2; // Select CLKIN/XOSC as the source for ACLK, MCLK, and SMCLK
    CCSCTL0_H |= 0xFF; // Lock CCS
    /* Lock by writing to upper byte */

    while(1);


    P1OUT = 0x00; // Initialize all GPIO
    P1SEL0 = UART_TXD + UART_RXD; // Timer function for TXD/RXD pins
    P1DIR = 0xFF & ~UART_RXD; // Set all pins but RXD to output
    P2OUT = 0x00;
    P2SEL0 = 0x00;
    P2DIR = 0xFF;

    __enable_interrupt();

    TimerA_UART_init(); // Start Timer_A UART
    TimerA_UART_print("G2xx2 TimerA UART\r\n");
    TimerA_UART_print("READY.\r\n");

    for (;;)
    {
    // Wait for incoming character
    __bis_SR_register(LPM0_bits);

    // Update board outputs according to received byte
    if (rxBuffer & 0x01) P1OUT |= 0x01; else P1OUT &= ~0x01; // P1.0
    if (rxBuffer & 0x02) P1OUT |= 0x08; else P1OUT &= ~0x08; // P1.3
    if (rxBuffer & 0x04) P1OUT |= 0x10; else P1OUT &= ~0x10; // P1.4
    if (rxBuffer & 0x08) P1OUT |= 0x20; else P1OUT &= ~0x20; // P1.5
    if (rxBuffer & 0x10) P1OUT |= 0x40; else P1OUT &= ~0x40; // P1.6
    if (rxBuffer & 0x20) P1OUT |= 0x80; else P1OUT &= ~0x80; // P1.7
    if (rxBuffer & 0x40) P2OUT |= 0x40; else P2OUT &= ~0x40; // P2.6
    if (rxBuffer & 0x80) P2OUT |= 0x80; else P2OUT &= ~0x80; // P2.7

    // Echo received character
    TimerA_UART_tx(rxBuffer);
    }
    }
    //------------------------------------------------------------------------------
    // Function configures Timer_A for full-duplex UART operation
    //------------------------------------------------------------------------------
    void TimerA_UART_init(void)
    {
    TA0CCTL0 = OUT; // Set TXD Idle as Mark = '1'
    TA0CCTL1 = SCS + CM1 + CAP + CCIE; // Sync, Neg Edge, Capture, Int
    TA0CTL = TASSEL_2 + MC_2; // SMCLK, start in continuous mode
    }
    //------------------------------------------------------------------------------
    // Outputs one byte using the Timer_A UART
    //------------------------------------------------------------------------------
    void TimerA_UART_tx(unsigned char byte)
    {
    while (TA0CCTL0 & CCIE); // Ensure last char got TX'd
    TA0CCR0 = TA0R; // Current state of TA counter
    TA0CCR0 += UART_TBIT; // One bit time till first bit
    TA0CCTL0 = OUTMOD0 + CCIE; // Set TXD on EQU0, Int
    txData = byte; // Load global variable
    txData |= 0x100; // Add mark stop bit to TXData
    txData <<= 1; // Add space start bit
    }

    //------------------------------------------------------------------------------
    // Prints a string over using the Timer_A UART
    //------------------------------------------------------------------------------
    void TimerA_UART_print(char *string)
    {
    while (*string) {
    TimerA_UART_tx(*string++);
    }
    }
    //------------------------------------------------------------------------------
    // Timer_A UART - Transmit Interrupt Handler
    //------------------------------------------------------------------------------
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = TIMER0_A0_VECTOR
    __interrupt void Timer_A0_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(TIMER0_A0_VECTOR))) Timer_A0_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
    static unsigned char txBitCnt = 10;

    TA0CCR0 += UART_TBIT; // Add Offset to CCRx
    if (txBitCnt == 0) { // All bits TXed?
    TA0CCTL0 &= ~CCIE; // All bits TXed, disable interrupt
    txBitCnt = 10; // Re-load bit counter
    }
    else {
    if (txData & 0x01) {
    TA0CCTL0 &= ~OUTMOD2; // TX Mark '1'
    }
    else {
    TA0CCTL0 |= OUTMOD2; // TX Space '0'
    }
    txData >>= 1;
    txBitCnt--;
    }
    }
    //------------------------------------------------------------------------------
    // Timer_A UART - Receive Interrupt Handler
    //------------------------------------------------------------------------------
    #if defined(__TI_COMPILER_VERSION__) || defined(__IAR_SYSTEMS_ICC__)
    #pragma vector = TIMER0_A1_VECTOR
    __interrupt void Timer_A1_ISR(void)
    #elif defined(__GNUC__)
    void __attribute__ ((interrupt(TIMER0_A1_VECTOR))) Timer_A1_ISR (void)
    #else
    #error Compiler not supported!
    #endif
    {
    static unsigned char rxBitCnt = 8;
    static unsigned char rxData = 0;

    switch (__even_in_range(TA0IV, TA0IV_TAIFG)) { // Use calculated branching
    case TA0IV_TACCR1: // TACCR1 CCIFG - UART RX
    TA0CCR1 += UART_TBIT; // Add Offset to CCRx
    if (TA0CCTL1 & CAP) { // Capture mode = start bit edge
    TA0CCTL1 &= ~CAP; // Switch capture to compare mode
    TA0CCR1 += UART_TBIT_DIV_2; // Point CCRx to middle of D0
    }
    else {
    rxData >>= 1;
    if (TA0CCTL1 & SCCI) { // Get bit waiting in receive latch
    rxData |= 0x80;
    }
    rxBitCnt--;
    if (rxBitCnt == 0) { // All bits RXed?
    rxBuffer = rxData; // Store in global variable
    rxBitCnt = 8; // Re-load bit counter
    TA0CCTL1 |= CAP; // Switch compare to capture mode
    __bic_SR_register_on_exit(LPM0_bits); // Clear LPM0 bits from 0(SR)
    }
    }
    break;
    }
    }