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 launchpad SPI clock signal

Other Parts Discussed in Thread: MSP430F5529, LMP91200

I am trying to use the MSP430F5529 launchpad to interface with the LMP91200 using the code included with the LMP91200. But I am not getting communication between the devices and the code goes into an error to blink LED continuously. When I put a scope probe on the UCA0CLK pin (P2.7) there is no clock signal (it remains high at 3.3V). If I step through the program, P2.7 goes from low to high when the TI_LMP91200_SPISetup function finishes. Why is there no clock signal? And what can I do to fix it?

 
#include <stdint.h>
#include <msp430f5529.h>
#include "TI_LMP91200.h"
#include "TI_LMP91200_register_settings.h"
#include "TI_MSP430.h"
#include "TI_MSP430_hardware_board.h"
#include "TI_MSP430_spi.h"
#include "TI_MSP430_spi_USCIA0.h"

void ADC12_Init(void);                                                         // To init MSP430F5528 ADC12 & Start Conversion

#define TI_LMP91200_VOUT_ADC12_PxSEL      P6SEL                                // ADC12 A6 channel on P6.6 (MSP430F5528)
#define TI_LMP91200_VOUT_ADC12_PIN        BIT6

#define NUM_OF_RESULTS      8                                                  // Number of temp sensor samples to take
#define SCALE_FACTOR        3                                                  // For averaging converted samples
#define PT_RES_NOMINAL      100                                                // 100ohms at 0degC
#define ADC12_RATIO         0.6105                                             // 2500/4095 (2.5V reference & 12bit converter)
#define ADC14_RATIO         0.15259                                            // 2500/16384(2500mV ref & 14bit converter w/ 2's comp o/p)
#define PT_TC               0.3850                                             // PT_TC is ohms/degC
#define PGA_GAIN            10                                                 // Gain of 10
#define I_VALUE             1                                                  // 1mA
#define R_REF               100                                                // 100ohm reference resistor
//******************************************************************************

void main(void)
{
  uint16_t reg_write_data, reg_read_data;

  WDTCTL = WDTPW+WDTHOLD;                                                      // Stop WDT

  TI_LMP91200_LED_PxOUT |= TI_LMP91200_LED_PIN;                                // Set LED ON
  TI_LMP91200_LED_PxDIR |= TI_LMP91200_LED_PIN;                                // Set pin direction is output
  //P2SEL=BIT2;					//test SMCLK signal
  //P2DIR=BIT2;

  TI_LMP91200_SPISetup();													   // Initilaize MSP430 SPI Block

  reg_write_data = TI_LMP91200_CONFIG_REG_RTD_VALUE;                           // value to write (Temp Measurement, RTD, 1mA, PGA=10, VOCM=GND)
  reg_read_data = TI_LMP91200_SPIWriteReg(reg_write_data);                     // Write again to read config register
  reg_read_data = TI_LMP91200_SPIWriteReg(reg_write_data);                     // Write again to read config register

  // test if write/read values match
  if (reg_write_data != reg_read_data)
  {
   while (1)                                                                   // error: blink LED continuously
   {
     __delay_cycles(250000);
     TI_LMP91200_LED_PxOUT ^= TI_LMP91200_LED_PIN;
   }
  }

  TI_LMP91200_SPIWriteReg(TI_LMP91200_CONFIG_REG_RTD_VALUE);                  // Measure RTD
  ADC12_Init();                                                                // Initialize MSP430F5528 ADC12 & Start Conversion

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

}

//*************************************************************************************************************

#include <stdint.h>
#include "TI_LMP91200.h"
#include "TI_MSP430.h"
#include "TI_MSP430_hardware_board.h"
#include "TI_MSP430_spi.h"

//******************************************************************************
// Support for 552x USCI_A0

//******************************************************************************
#if TI_LMP91200_SER_INTF == TI_LMP91200_SER_INTF_USCIA0_5xx

//------------------------------------------------------------------------------
//  void TI_LMP91200_SPISetup(void)
//
//  DESCRIPTION:
//  Configures the assigned interface to function as a SPI port and
//  initializes it.
//------------------------------------------------------------------------------
void TI_LMP91200_SPISetup(void) {

 TI_LMP91200_CSn_PxOUT |= TI_LMP91200_CSn_PIN;
 TI_LMP91200_CSn_PxDIR |= TI_LMP91200_CSn_PIN;                 // /CS disable

 UCA0CTL1 |= UCSWRST;                       // **Disable USCI state machine**
 UCA0CTL0 |= UCMST + UCCKPL + UCMSB + UCSYNC;      // 3-pin, 8-bit SPI master
 UCA0CTL1 |= UCSSEL_2;                                               // SMCLK
 UCA0BR0 = 0x04;                                                    // UCLK/4
 UCA0BR1 = 0;
 UCA0MCTL = 0;

 TI_LMP91200_SPI_USCIA0_SIMO_PxSEL |= TI_LMP91200_SPI_USCIA0_SIMO; // SPI option select
 TI_LMP91200_SPI_USCIA0_SOMI_PxSEL |= TI_LMP91200_SPI_USCIA0_SOMI;
 TI_LMP91200_SPI_USCIA0_UCLK_PxSEL |= TI_LMP91200_SPI_USCIA0_UCLK;

 TI_LMP91200_SPI_USCIA0_SIMO_PxDIR |= TI_LMP91200_SPI_USCIA0_SIMO; // SPI TXD out direction
 TI_LMP91200_SPI_USCIA0_UCLK_PxDIR |= TI_LMP91200_SPI_USCIA0_UCLK;

 UCA0CTL1 &= ~UCSWRST;                   // **Initialize USCI state machine**

}

//------------------------------------------------------------------------------
//  uint16_t TI_LMP91200_SPIWriteReg(uint16_t value)
//
//  DESCRIPTION:
//  Writes "value" to configuration register. Returns the previous value
//  in the configuration register.
//------------------------------------------------------------------------------
uint16_t TI_LMP91200_SPIWriteReg(uint16_t value)
{
 uint16_t x = 0;
 uint8_t inst;

 TI_LMP91200_CSn_PxOUT &= ~TI_LMP91200_CSn_PIN;                 // /CS enable

 inst = value >> 8;                                  // Get msb data to send
 while (!(UCA0IFG & UCTXIFG))                        // Wait for TXBUF ready
 UCA0TXBUF = inst;                                  // Send msb

 while (UCA0STAT & UCBUSY)                          // Wait for TX complete
 x = UCA0RXBUF;                                     // Read previous msb

 inst = value & 0x00FF;                            // Get lsb data to send
 while (!(UCA0IFG & UCTXIFG))                      // Wait for TXBUF ready
 UCA0TXBUF = inst;                                 // Send lsb data value

 while (UCA0STAT & UCBUSY)                       // Wait for TX complete
 x = (x << 8) | UCA0RXBUF;                      // Read previous lsb & append

 TI_LMP91200_CSn_PxOUT |= TI_LMP91200_CSn_PIN;                 // /CS disable

 return x;                                  // return previous register value

}
//------------------------------------------------------------------------------
#endif

// SPI port definitions

// USCIA0 for F552x
#define TI_LMP91200_SPI_USCIA0_SIMO_PxSEL  P3SEL
#define TI_LMP91200_SPI_USCIA0_SOMI_PxSEL  P3SEL
#define TI_LMP91200_SPI_USCIA0_UCLK_PxSEL  P2SEL
#define TI_LMP91200_SPI_USCIA0_SIMO_PxDIR  P3DIR
#define TI_LMP91200_SPI_USCIA0_UCLK_PxDIR  P2DIR
#define TI_LMP91200_SPI_USCIA0_PxIN        P3IN
#define TI_LMP91200_SPI_USCIA0_SIMO        BIT3
#define TI_LMP91200_SPI_USCIA0_SOMI        BIT4
#define TI_LMP91200_SPI_USCIA0_UCLK        BIT7

// Chip Select Pin
#define TI_LMP91200_CSn_PxOUT                         P2OUT
#define TI_LMP91200_CSn_PxDIR                         P2DIR
#define TI_LMP91200_CSn_PIN                           BIT5

  • Well, I don't know what's wrong. The pin config seems to be correct, the code should do what you expect. However, it is possible that the debugger stops the clocks while single-stepping. So maybe you don't see a SPI clock signal because there is no SMCLK (or rather - a slow one) during your debug operation.
    Do you observe any signal changes on the SOMI pin?

    BTW: i ti snot necessary to manually control the direction of the USCI pins - the USCI overrides the PxDIR signals anyway (see port pin schematics in the datasheet).

  • Thanks for the quick response. I don't see any signal changes on the SOMI pin and even if I dont use the debug operation to step through the program I don't get a clock signal on P2.7. One thing I did notice is that the program included with the LMP91200 has the TI_LMP91200_SPISetup function in a .c file, I changed this to a .h file because the files would not load onto the launchpad because of an error of .out file not found. Would this cause the results I am getting (changing from a .c to a .h file)? If so why and what is the difference between a .c file and a .h file?

  • Thanks for your help. I am now getting communication between devices. But I would still like to know what the difference is between a .c file and a .h file?

    Thank you

  • Timothy Claycomb1 said:
    But I would still like to know what the difference is between a .c file and a .h file?

    Physically, there is no difference. Both are plain text files containing C code.

    However, by convention, .c files contain executable code (function definitions, global variable definitions etc.) which is turned into code by the compiler. Each .c file should compile and should be compiled independently, producing a separate and stand-alone object file that is later linked together.

    .h files contain declarations which do not produce any code but are required for compiling the .c files.
    Usually, a .h file contains declarations for the functions and variables defined in the .c file of the same name. So if a .c file includes the .h file of another .c file, it tells the compiler which external functions and variables can be found in this other .c file and therefore called in the one that is currently compiled.

    But this is just a convention, not forced by anything, and unfortunately, some  coders (including some who write demo code) have adopted the habit of including multiple .c files into one 'master' file that is compiled in a block.

    Well, we know from Windows Word how this approach can generate epic fails.

**Attention** This is a public forum