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.

CCS/TDC7200: Reading a register from TDC7200 whithout interrupts

Part Number: TDC7200

Tool/software: Code Composer Studio

Hi,

I try  to communicate with the TDC7200 and the MSP430 5529lp over SPI.

The Write operations are successfully but when i want to read the same Register which I wrote before whithout any Interrupt. 

I see on the Scope only the read adress +command.

Now my Question is it possible to read without interrupt? and where is my mistake?

I am a newbie^^ and I hope anyone can help me with this Problem

The Code:

#include <msp430.h> 
#include <stdint.h>

/**
 * main.c
 */
uint8_t read_val;
unsigned long rcv;
unsigned char data;
void SPI_init(void);

void SPI_write_config1(uint8_t,uint8_t);
void SPI_write_config2(uint8_t,uint8_t);
void SPI_write_config3(uint8_t,uint8_t);
uint8_t SPI_write_read_TIME(uint8_t);
int main(void)
{

      WDTCTL = WDTPW | WDTHOLD;       // stop watchdog timer

      SPI_init();
      SPI_write_config1(0x40,0x02);         //write register adress 00h with commands
      SPI_write_config2(0x41,0x40);
      SPI_write_config3(0x42,0x00);
      read_val=SPI_write_read_TIME(0x00);   // example: read register adress 00h 


}


void SPI_write_config1(uint8_t adress,uint8_t value)
{

    P2OUT &= (~BIT2);                // Select Device

    while(!(UCB0IFG & UCTXIFG));     // wait for TXBUF
    UCB0TXBUF = adress;              // send adress to register 00h

    while(!(UCB0IFG & UCTXIFG));     // wait for TXBUF
    UCB0TXBUF = value;               // write a command to register 00h

    while (UCB0STAT & UCBUSY);       // Wait for TX complete


    P2OUT |= (BIT2);                 // Unselect Device
}

void SPI_write_config2(uint8_t adress,uint8_t value)
{

    P2OUT &= (~BIT2);                // Select Device

    while(!(UCB0IFG & UCTXIFG));     // wait for TXBUF
    UCB0TXBUF = adress;              // send adress to register 01h

    while(!(UCB0IFG & UCTXIFG));     // wait for TXBUF
    UCB0TXBUF = value;               // write a command to register 01h

    while (UCB0STAT & UCBUSY);       // Wait for TX complete


    P2OUT |= (BIT2);                 // Unselect Device
}

void SPI_write_config3(uint8_t adress,uint8_t value)
{

    P2OUT &= (~BIT2);                // Select Device

    while(!(UCB0IFG & UCTXIFG));     // wait for TXBUF
    UCB0TXBUF = adress;              // send adress to register 01h

    while(!(UCB0IFG & UCTXIFG));     // wait for TXBUF
    UCB0TXBUF = value;               // write a command to register 01h

    while (UCB0STAT & UCBUSY);       // Wait for TX complete


    P2OUT |= (BIT2);                 // Unselect Device
}

void SPI_init(void)
{

// SPI Pins Auswählen//
P3SEL = BIT0 + BIT1 + BIT2;
P2DIR |= BIT2;                        // PIN2.2 set as Chipselect 
P2OUT |= BIT2;                        // PIN2.2 set the chipselect Pin high

// Konfiguration des SPI-Registers//
UCB0CTL1 |= UCSWRST;                 
UCB0CTL1 |= UCSSEL_2;                 

UCB0CTL0 = UCMST+UCMSB+UCCKPL+UCSYNC; // SPI Konfiguration (MasterMode;SynchroneMode;Clock_polarity;MSBfirstMode)

UCB0BR0 = 0x02;                       // Prescaler 
UCB0BR1 = 0;


UCA0MCTL = 0;                         // No Modulation
UCB0CTL1 &= ~UCSWRST;                 // disable software reset

}


uint8_t SPI_write_read_TIME(uint8_t adress)
{

    P2OUT &= (~BIT2);                // Select Device

    while(!(UCB0IFG & UCTXIFG));     // Wait for TXBUF ready
    UCB0TXBUF = adress;              // send ADRESSE + read command to the register

    while (!(UCB0IFG&UCTXIFG));      // Wait for TXBUF ready
     UCB0TXBUF = 0;                  // Dummy write to read data



    while(!(UCB0IFG&UCRXIFG));       // Wait for RXBUF ready
    rcv = UCB0RXBUF;

    P2OUT |= (BIT2);                 // Unselect Device
    return (rcv);
}



  • Hi Benjamin,

    This looks good, although there may be an issue with the SPI setup. On line 94 you set up UCCKPL, whereas in our examples we have UCCKPH instead. See below:

    void TI_TDC1000_SPISetup(void)
    {
      TI_TDC1000_CSn_PxOUT |= TI_TDC1000_CSn_PIN;
      TI_TDC1000_CSn_PxDIR |= TI_TDC1000_CSn_PIN;                                // /CS disable
    
      UCB0CTL1 |= UCSWRST;                                                         // **Disable USCI state machine**
      UCB0CTL0 |= UCMST+UCMSB+UCCKPH+UCSYNC;                                              // 3-pin, 8-bit SPI master 
      UCB0CTL1 |= UCSSEL__SMCLK;                                                    // choose SMCLK
    
      UCB0BR0 = 0x02;                                                              // UCLK/2 (should be 12MHz for 24MHz SMCLK)
      UCB0BR1 = 0;
      TI_TDC1000_SPI_USCIB0_PxSEL1 |= TI_TDC1000_SPI_USCIB0_SIMO
                                       | TI_TDC1000_SPI_USCIB0_SOMI;              
      TI_TDC1000_SPI_USCIB0_PxSEL2 |= TI_TDC1000_SPI_USCIB0_UCLK;
                                                                                   // SPI option select
      TI_TDC1000_SPI_USCIB0_PxDIR1 |= TI_TDC1000_SPI_USCIB0_SIMO;
      TI_TDC1000_SPI_USCIB0_PxDIR2 |= TI_TDC1000_SPI_USCIB0_UCLK;
                                                                                   // SPI TXD out direction
      
      UCB0CTL1 &= ~UCSWRST;                                                        // **Initialize USCI state machine**
    }

    This is from the SPI read/write example firmware included in the TDC1000-TDC7200EVM GUI download. I recommend downloading the GUI here: 

    The firmware and example code will be included in the installation directory of the GUI.

    That being said, the write and read functions you posted should work, so I believe the issue may be in the SPI initialization.

    Regards,

  • thanks for reply