AnsweredAssumed Answered

SPI slave communication

Question asked by tran.tom on Sep 21, 2011
Hi all,

I am working a project that has a SPI master on an OMAP-L138.  I had the four lines manually wired across from the OMAP-L138 to the STM8-S discovery board.  The connections are below:

OMAP SPI CS -> STM8 SPI NSS
OMAP SPI SCLK -> STM8 SPI CLK
OMAP SPI MOSI -> STM8 SPI MOSI
OMAP SPi MISO -> STM8 SPI MISO


This is my initialization function of the SPI as a slave.

 static void enable_spi_slave(void)
{
          SPI_DeInit();
          SPI_Init(SPI_FIRSTBIT_MSB, 
                   SPI_BAUDRATEPRESCALER_8, 
                   SPI_MODE_SLAVE, 
                   SPI_CLOCKPOLARITY_LOW, 
                   SPI_CLOCKPHASE_1EDGE,
                   SPI_DATADIRECTION_2LINES_FULLDUPLEX,
                   SPI_NSS_HARD,
                   0x07);
          SPI_Cmd(ENABLE);
}

 void main(void)
{
     u8 command;
     u8 *ptr;


     enable_spi_slave();

     while(1) {
          u8 i=0;

          //read_power_amp_status();
          //update_ready_status_for_arm();
          //while((GPIOE->IDR & 0x20) == 0x00);

          if(SPI_GetFlagStatus(SPI_FLAG_RXNE) == SET) {
          
               command = SPI_ReceiveData();
               
               switch(command) {
                    case PTT_POWER_AMP_GET_STATUS:
                    {
                         /*
                              Write the statuses back to the SPI master.
                         */
                         //for(i=0; i<27; i++) SPI_ReceiveData();
                         //SPI_ReceiveData();
                         bufptr = buffer;     
                         for(i=0; i<12; i++) {
                              
                              //while(SPI_GetFlagStatus(SPI_FLAG_TXE) != SET) 
                              while((GPIOE->IDR &0x20) == 0x00) 
                              {
                                   if((SPI->SR & SPI_FLAG_TXE) == SPI_FLAG_TXE) {
                                        SPI->DR = (u8)0x0d;
                                        SPI->DR = (u8)buffer[i];

                                        //SPI_SendData(buffer[i]);
                                        //bufptr++;
                                   }
                    
                              }
                              //SPI_ReceiveData();
                         }
          
                         //SPI_SendData(0x00);
                         SPI_ReceiveData();
                    }
                    break;
                    
                    default:
                    {
                         while((GPIOE->IDR &0x20) == 00) ;
                         SPI_ReceiveData();
                    }
                    break;
                    
               }
          }
          
     
          //delay(50);
  }     

}



Basically, on the OMAP side I send over 0x1 followed by 12 zeros.  I can see that the 0x1 came over the wire on MOSI, which is my command (PTT_POWER_AMP_GET_STATUS).  I want to write back 12 bytes and that is main problem.  I constantly received 0x3a or 0x38.  What i sent back is 0xd 0xe 0xa 0xd repeated 3 times.  And on the scope, the signal for MISO is not what I expect.  Has anyone seen this problem using the SPI slave on the STM8 Discovery?

Any advice or comments is appreciated.

Thanks,
Tom



Outcomes