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: (TI_TDC720x_SPILongReadReg) SPI clock stay low

Part Number: TDC7200

Tool/software: Code Composer Studio

Hi there,

first of all my source code:

#include <msp430.h> 
#include <stdint.h>
#include <stdio.h>
/**
 * main.c
 */


uint32_t TIME[5];
void SPI_init(void);
int t,inter_stat;
void SPI_write_config1(uint8_t,uint8_t);
void SPI_write_config2(uint8_t,uint8_t);
void SPI_write_interrupt_mask(uint8_t,uint8_t);
uint8_t SPI_read_interrupt_status(uint8_t);         // ist unnötig kann auch im singlebyte gelesen werden und in der main so konfiguriert
uint8_t SPI_read_singlebyte(uint8_t);
uint32_t SPI_read_longbyte(uint8_t);

int main(void)

{
      uint32_t Time1_6;
      uint8_t i;

      WDTCTL = WDTPW | WDTHOLD;       // stop watchdog timer

      SPI_init();
      SPI_write_config1(0x40,0x03);         //write register adress 00h with commands
      SPI_write_config2(0x41,0x40);
      //inter_stat = SPI_read_interrupt_status(0x02);
      //SPI_write_interrupt_mask(0x43,0x00);
      Time1_6 = SPI_read_longbyte(0x90); // lesen der TIME 1_6 Register mit auto inc

    
     
      return 0;

}

uint32_t SPI_read_longbyte(uint8_t adress)
{
    uint32_t y = 0;
    uint32_t x = 0;

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

    while(!(UCB0IFG & UCTXIFG));     // wait for TXBUF
    UCB0TXBUF = adress;              // send adress für ...

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

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

    x |= (y << 16);

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

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

    x |= (y << 8);

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

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

    x |= y;

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

    P2OUT |= (BIT2);                 // Unselect Device

    return x;
}



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
}

uint8_t SPI_read_interrupt_status(uint8_t adress)
{
    uint8_t rcv;
    //uint8_t clear = 0x1F;          // Clear interrupt flags??
    P2OUT &= (~BIT2);                // Select Device

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

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

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

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

    P2OUT |= (BIT2);                 // Unselect Device

    return rcv;
}

void SPI_write_interrupt_mask(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)
{

// Enable PIN aktivieren für Register Zugriff//
P6DIR |=BIT5;                          // OUTput enable Pin for TDC7200
P6OUT |=BIT5;                          // Output HIGH enable Pin aktiv

// 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+UCCKPH+UCSYNC; // SPI Konfiguration (MasterMode;SynchroneMode;Clock_polarity;MSBfirstMode)

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


UCA0MCTL = 0;                         // No Modulation
UCB0CTL1 &= ~UCSWRST;                 // disable software reset
//UCB0IE |= UCRXIE;                   // Enable USCI_B0 RX interrupt
}

i try to read the TIME 1 register with the modified example function from TDC7200_basic_spi_rw: uint32_t TI_TDC720x_SPILongReadReg(uint8_t addr).

the result of this is that the clock stay low after each bit shift command:

after that i try to comment out the bit shift operations after each y buffer receive and all while(!(UCB0IFG & UCTXIFG)); loops. Now i get a what i want a 32 clk cycle whithout any breaks:

My Question is: Is it possible to read my TIME register and the other only read registers with this function and if its possible how i solve it?

and how can I use this function with the autoincrement bit?

thanks in advance 

greets Ben

  • Hi Ben,

    Your code is basically identical to the TI_TDC7200_SPILongReadReg() fuction in the TDC1000-TDC7200EVM Firmware source code. Is the data you're reading correct, and the only issue is the down time for the SPI clock when shifting? In this case I would just suggest to continue using this code unless the transaction time is a concern.

    The actual EVM firmware also includes a function which implements the AutoIncrement called TI_TDC7200_SPIALLReadReg() copied here for reference:

    //------------------------------------------------------------------------------
    //  void TI_TDC7200_SPIAllReadReg(uint8_t *buffer)
    //
    //  DESCRIPTION:
    //  Special read function for reading all measurement result registers.
    //  Data read are deposited sequentially starting at address "buffer" 
    //------------------------------------------------------------------------------
    void TI_TDC7200_SPIAllReadReg(uint8_t *buffer)
    {
    
      uint8_t i, inst;
      
      TI_TDC7200_CSn_PxOUT &= ~TI_TDC7200_CSn_PIN;                                 // /CS enable
     
      // read mode and auto_inc on
      inst = 0x90;
      
      while (!(UCB0IFG&UCTXIFG));                                                  // Wait for TXBUF ready
      UCB0TXBUF = inst;                                                            // Send register address
      
     
      for(i=0; i<TDC7200_ALL_DATA_SIZE; i++)
      {
        while (!(UCB0IFG&UCTXIFG));                                                // Wait for TXBUF ready
        UCB0TXBUF = 0;                                                             // Dummy write so we can read data
        
       
        while (UCB0STAT & UCBUSY);                                                 // Wait for TX complete  
        *(buffer+i) = UCB0RXBUF;                                                   // Read register data    
      }
        
      TI_TDC7200_CSn_PxOUT |= TI_TDC7200_CSn_PIN;                                  // /CS disable
        
    }

  • Hi Scott,

    thanks for reply I try this example Function but i don't use the pointer *buffer in my readout. But this experiment was not really succesful.

    Because I read the RXBUF directly in an array i lost always the last byte from the Calibration2 register. the Array get the Values everytime after the next SPI read sequence.

    My first Question is why they dont read the RXBUF immediately in my array? 

    The second Question is: If i do not use the pointer like you, do i get a delay in my Function SPI_read_all. Because my application must run on the fastest way.   

    void SPI_init(void);
    void SPI_write_config1(uint8_t,uint8_t);
    void SPI_write_config2(uint8_t,uint8_t);
    uint8_t SPI_read_singlebyte(uint8_t);
    void SPI_readall_Reg(uint8_t);
    
    uint8_t data[40];
    
    int main(void)
    {
    
    uint8_t i;
    
          WDTCTL = WDTPW | WDTHOLD;             // stop watchdog timer
    
          SPI_init();
          SPI_write_config1(0x40,0x03);         //write register adress 00h with commands
          SPI_write_config2(0x41,0x40);
          SPI_readall_Reg(0x90);
    
          for (i = 0; i <= 40; i++)
          {
            printf("%x\n", data[i]);
          }
          printf("%x\n",data[39]);
          return 0;
    
    }
    
    void SPI_readall_Reg(uint8_t adress)
    {
    
    uint8_t i,a;
    
    
    P2OUT &= (~BIT2);                               // Select Device
    
    while (!(UCB0IFG&UCTXIFG));                                                     // Wait for TXBUF ready
      UCB0TXBUF = adress;
                                                                       
     
      for(i=0; i<39; i++)
       {
         while (!(UCB0IFG&UCTXIFG));                                                // Wait for TXBUF ready
         UCB0TXBUF = 0;                                                             // Dummy write so we can read data
    
         while(!(UCB0IFG&UCRXIFG));                 // Wait for RXBUF ready
         a = UCB0RXBUF;
    
         data[i] = a;
    
       }
    
    
    
      P2OUT |= (BIT2);                 // Unselect Device
    
    }

    thanks Ben

  • Part Number: TDC7200

    Tool/software: Code Composer Studio

    Hi there,

    I try this example Function but i don't use the pointer *buffer in my readout. But this experiment was not really succesful.

    Because I read the RXBUF directly in an array i lost always the last byte from the Calibration2 register. the Array get the Values everytime after the next SPI read sequence.

    My first Question is why they dont read the RXBUF immediately in my array?

    The second Question is: If i do not use the pointer like you, do i get a delay in my Function SPI_read_all? Because my application must run on the fastest way.   


    void SPI_init(void);
    
    void SPI_write_config1(uint8_t,uint8_t);
    
    void SPI_write_config2(uint8_t,uint8_t);
    
    uint8_t SPI_read_singlebyte(uint8_t);
    
    void SPI_readall_Reg(uint8_t);
    
    
    uint8_t data[40];
    
    
    int main(void)
    
    {
    
    
    uint8_t i;
    
    
          WDTCTL = WDTPW | WDTHOLD;             // stop watchdog timer
    
    
          SPI_init();
    
          SPI_write_config1(0x40,0x03);         //write register adress 00h with commands
    
          SPI_write_config2(0x41,0x40);
    
          SPI_readall_Reg(0x90);
    
    
          for (i = 0; i <= 40; i++)
    
          {
    
            printf("%x\n", data[i]);
    
          }
    
          printf("%x\n",data[39]);
    
          return 0;
    
    
    }
    
    
    void SPI_readall_Reg(uint8_t adress)
    
    {
    
    
    uint8_t i,a;
    
    
    
    P2OUT &= (~BIT2);                               // Select Device
    
    
    while (!(UCB0IFG&UCTXIFG));                                                     // Wait for TXBUF ready
    
      UCB0TXBUF = adress;
    
                                                                       
    
     
    
      for(i=0; i<39; i++)
    
       {
    
         while (!(UCB0IFG&UCTXIFG));                                                // Wait for TXBUF ready
    
         UCB0TXBUF = 0;                                                             // Dummy write so we can read data
    
    
         while(!(UCB0IFG&UCRXIFG));                 // Wait for RXBUF ready
    
         a = UCB0RXBUF;
    
    
         data[i] = a;
    
    
       }
    
    
    
    
      P2OUT |= (BIT2);                 // Unselect Device
    
    
    }

    greets Ben

  • void SPI_init(void);
    
    void SPI_write_config1(uint8_t,uint8_t);
    
    void SPI_write_config2(uint8_t,uint8_t);
    
    uint8_t SPI_read_singlebyte(uint8_t);
    
    void SPI_readall_Reg(uint8_t);
    
    
    uint8_t data[40];
    
    
    int main(void)
    
    {
    
    
    uint8_t i;
    
    
          WDTCTL = WDTPW | WDTHOLD;             // stop watchdog timer
    
    
          SPI_init();
    
          SPI_write_config1(0x40,0x03);         //write register adress 00h with commands
    
          SPI_write_config2(0x41,0x40);
    
          SPI_readall_Reg(0x90);
    
    
          for (i = 0; i <= 40; i++)
    
          {
    
            printf("%x\n", data[i]);
    
          }
    
          printf("%x\n",data[39]);
    
          return 0;
    
    
    }
    
    
    void SPI_readall_Reg(uint8_t adress)
    
    {
    
    
    uint8_t i,a;
    
    
    
    P2OUT &= (~BIT2);                               // Select Device
    
    
    while (!(UCB0IFG&UCTXIFG));                                                     // Wait for TXBUF ready
    
      UCB0TXBUF = adress;
    
                                                                       
    
     
    
      for(i=0; i<39; i++)
    
       {
    
         while (!(UCB0IFG&UCTXIFG));                                                // Wait for TXBUF ready
    
         UCB0TXBUF = 0;                                                             // Dummy write so we can read data
    
    
         while(!(UCB0IFG&UCRXIFG));                 // Wait for RXBUF ready
    
         a = UCB0RXBUF;
    
    
         data[i] = a;
    
    
       }
    
    
    
    
      P2OUT |= (BIT2);                 // Unselect Device
    
    
    }

  • now i test a function which read one register 32 bit (see code below).
    in uint32_t SPI_read_longbyte i have the same problem as the function SPI_readall_Reg.
    The last byte from the register get lost in the variable y but on the Oscilloscope i see the last received byte.
    why the last byte get lost in my functions??it is timing problem ??
    thanks for any reply.


    uint32_t SPI_read_longbyte(uint8_t adress)
    {
    uint64_t y= 0;

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

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

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

    while(!(UCB0IFG&UCRXIFG)); // Wait for RXBUF ready
    y = UCB0RXBUF;
    y |= (y << 16);

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

    while(!(UCB0IFG&UCRXIFG)); // Wait for RXBUF ready
    y = UCB0RXBUF;
    y |= (y << 8);

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

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

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

    P2OUT |= (BIT2); // Unselect Device
    printf("%x\n",y);
    return y;

    }

    greets ben l.