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/MSP432P401R: Sending a data command by SPI

Part Number: MSP432P401R

Tool/software: Code Composer Studio

Hello, 

I have to make a communication through SPI, and I have made a function to send some commands to the SPI. After make some test's and putting some breakpoints in some points of the code I verified the code stop's after sent the data to TXBUF. After that I have put a "while"  condition to prevent the program take some other tasks while the TX buffer is not empty. Below i share the function code, in hope to get some help.

Thanks in advance

/*ADS1292R SPI COMMAND DATA*/
void ads1292R_SPI_CMD_DATA(uint8_t data){
    
    unsigned char  delayVar;

    TxData = data;
    ads1292R_CS_LOW();                   /*ADS1292R CS LOW PIN*/
    delayADS1292R(2);                    /*SMALL DELAY TO SETTLE*/
    ads1292R_CS_HIGH();                  /*ADS1292R CS HIGH PIN*/
    ads1292R_CS_LOW();                   /*ADS1292R CS LOW PIN*/

    EUSCI_B0->TXBUF = data;              /*SEND THE DATA SITTING AT THE POINTER DATA TO TX BUFFER*/
    while (EUSCI_B0->STATW & EUSCI_B_STATW_BBUSY);
   

    delayVar = EUSCI_B0->RXBUF;

    delayADS1292R(2);                   /*SMALL DELAY TO SETTLE*/
}

  • Hello armandoferr,

    The eUSCI peripheral has a single byte transmit buffer which when loaded is automatically moved (1 clock cycle) into the shift register. The transmit IFG is cleared when data is loaded into the buffer and set once the data is moved to the shift register. The transmit IFG does not mean that the data has been transmitted. Also, the eUSCI will not generate a clock unless there is data in the shift register, therefor, in order to receive data you must load a 'dummy' byte into the transmit buffer. The RXIFG will indicate that the dummy byte was sent and that the receive data is ready.

    Please refer to the technical reference manual for a more detailed description. www.ti.com/.../slau356h.pdf

    Regards,
    Chris
  • Thank you Chris Sterzik ,
    So, I have understood that I need to substitute on the code line the sintax " while (EUSCI_B0->STATW & EUSCI_B_STATW_BBUSY)", for,
    "while(!(EUSCI_B0->IFG & EUSCI_B_IFG_RXIFG));" this way i can confirm, if the "IFG" is empty or not and if the dummy byte was sent or not .
    Is this correct?
  • Your original code was almost right:
    > while (EUSCI_B0->STATW & EUSCI_B_STATW_BBUSY);
    This is checking the I2C busy bit, not the SPI/UART busy bit, so it wasn't waiting at all. (No, I don't know why there are two of them.) Try:
    > while (EUSCI_B0->STATW & EUSCI_A_STATW_BUSY);

    Your RXIFG check will also work.

    Keep in mind that the byte you're sending isn't used by the ADS1292R [Ref data sheet (SBAS502B) Figure 34].

**Attention** This is a public forum