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.

MSP430FE427A SPI slave mode not fast enough

Other Parts Discussed in Thread: MSP430FE427A, AM1808

Hello

I am trying to get the MSP430FE427A working in slave mode at a speed of at least  2MHz.  I have been able to get it to work correctly to 500Khz but beyond that I am getting corrupt data.  The processor is running at 8 MHz.  Would anyone have an ideas on how to get this interface to work faster?  Basically, when I receive a command, I transfer the bytes from memory to TXBUF0.  There is no other processing involved.

Could this be an upper limit for this microcontroller in SPI slave mode?

  • Hello

    Here is some more information:

    The code:

    //------------------------------------------------------------------------------
    //      URX0_ISR    ; UART0 Receive Interrupt Routine
    //------------------------------------------------------------------------------
    #pragma vector=USART0RX_VECTOR
    __interrupt void URX0_ISR(void)
    {
    /********testing using GPIO********/
              P1OUT |= 0x01; /* set BIT 0 **/
              P1OUT |= 0x02;    /*set BIT 1 - for tx data back to AM1808*/
    /**********************************/
    if (RXBUF0 == 0x23)
    {
    /*********testing GPIO***********/
    P1OUT &= 0xFE; /* reset BIT 0 **/
    P1OUT &= 0xFD; /*reset BIT 1*/
    /*******************/

      send_test_string = 1;
      /* initialize to beginning of index */
      index_SPI_buf =0;
     
    }
    if (send_test_string == 1)
    {

      /* a dummy byte is defined as 0x00 anything else we will flag an error*/
      if (RXBUF0 == 0x00)
      {
       while ((U0IFG&UTXIFG0)==0);    // wait till TX buf empty
       
        /* transmit data */
        TXBUF0= test_string_buf[index_SPI_buf];
    /*****test GPIO*/
    P1OUT &= 0xFD; /* reset BIT1 */
    /**************/
        /* increment index */
        index_SPI_buf++;
        if (index_SPI_buf>3)
        {
           /* reset the send_voltage_rms flag*/
          send_test_string = 0;

          /* reset index */
          index_SPI_buf = -1;    
        }
      }
      else
      {
        /* send an error byte */
        TXBUF0=0x66;
      }
     
    }

     I observed on the scope and found that I am able to only go up to 250Khz before there is an overrun and the data becomes corrupted.

     

  • 250kHz SPI clock with 8MHz clock means that you have 256 CPU clock cycles for each byte. That's plenty. However, with higher baudrates, things are getting tight. The time overhead for entering and leaving an ISR is >11 MCLK cycles. Plus saving and restoring any registers that are used inside the ISR. Then the execution of your code, which does lots of things.

    For fast SPI slave operation, you must shrink the code during transfer to an absolute minimum. No waiting loops. On 4MHz baudrate, the waiting loop alone is almost longer than the transfer of a byte.
    Prepare the data to send in an array, so you only need to pick and place when the call comes. No fancy ifs and such. or on-the-fly calculation of what to send.

    Or (as e.g. the SD card does it) you expand the protocol:
    Master sends command byte and keeps polling. Slave sends nothing at first (master receives 0xff) and prepares the answer. Then a non-ff status byte follows, followed by additional data. This way, the slave has all the time it needs to interpret the command and prepare the answer, and still the master can use any clock speed without losses.
    This way, you can even set up a DMA and just start it when you're done collecting the data. The master will detect the first valid respone byte and then get its answer as fast as possible. I've done 8MHz SPI slave transfers this way.

**Attention** This is a public forum