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.

SPI , Chip slect not remian Active low for data duration

Other Parts Discussed in Thread: MSP430F5529

I am using MSP430F5529 controller , I am configuring MSP430 as single Master and using SPI interface for external one slave device.

- I observe that CLK,MOSI generating properly, for my application chip select (CS) is active low, and I am controlling this CS using one GPIO, state of this GPIO is controll based on status of TX buffer. I obsevrd that (Using Oscilloscope) this CS pin not remian active low for entire duration of 8 bit.Please check below code and please suggest what is wroung?

/* ensure previous data has sent */

adc_setup ( ) {

while (!SPI_getInterruptStatus(__MSP430_BASEADDRESS_USCI_B0__,SPI_TRANSMIT_INTERRUPT));

 /* Active low CS */

 output_low(P2OUT,ADC_CS);

 /* transmit 8 bit data  */

 SPI_transmitData(__MSP430_BASEADDRESS_USCI_B0__,cData);

 While (!SPI_getInterruptStatus(__MSP430_BASEADDRESS_USCI_B0__,SPI_TRANSMIT_INTERRUPT));

   /* disable serial interface ensure Chip select High */

 output_high(P2OUT,ADC_CS);

}

  • The USCI uses double-buffering. That means, TXBUF isn't the output shift register. (on USI, it is). If TXBUF is empty, it is possible (or rathe rlikely) that the output shift register still has some or even all 8 bits of the last byte unsent.

    If you want to know when the USCI is done with the transfer, you'll have to check the UCBUSY bit. Unfortunately, there is no interrupt for that.

    In your code, you clear CS when the last byte has moved from TXBUF to the output shift register (so TXBUF, but only TXBUF, is empty), not when the last byte has been sent.

  • Thanks, you correctly identified point.

    however I have just tried with  "while(SPI_isBusy(__MSP430_BASEADDRESS_USCI_B0__));" as below but observed same issue. Could you please check below code.

    /* ensure previous data has sent */

    while (!SPI_getInterruptStatus(__MSP430_BASEADDRESS_USCI_B0__,SPI_TRANSMIT_INTERRUPT));

    while(SPI_isBusy(__MSP430_BASEADDRESS_USCI_B0__));

    /* Active low CS */

     output_low(P2OUT,ADC_CS);

     /* transmit data */

     SPI_transmitData(__MSP430_BASEADDRESS_USCI_B0__,cData);

     while (!SPI_getInterruptStatus(__MSP430_BASEADDRESS_USCI_B0__,SPI_TRANSMIT_INTERRUPT));

     while(SPI_isBusy(__MSP430_BASEADDRESS_USCI_B0__));

       /* disable serial interface ensure Chip select High */

     output_high(P2OUT,ADC_CS);

  • I'm sorry, but i don't have the source codes for the high-level (library) functions you use. I don' thave CCS installed. (I use MSPGCC).
    So I cannot check in detail what's going on.

    Note that after the last clock pulse, some slaves still require some time before you may deactivate CS.
    YOu might want to add a small delay there.
    Or a big one, just for testing. :)

    Use __delay_cycles() instead of an empty for loop.

**Attention** This is a public forum