This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

SPI Master Slave Communication

I am into a project where I need 2 establish communication between ADuc814(Master) and ADuc841(Slave). Master shud Receive data transmitted by Slave. I am unable to establish the comm. I feel there is no response 4rm slave as though master generates the clock and SS pin is low, slave does not response.
Is it necessary that both master and slave should operate in same CLOCK??
For Hardware connection, MOSI, MISO, SCLK and SS pins of Master and Slave are connected.
Foll is the code
Master Code

#include <ADUC814.H>
unsigned char Data[20]; //Store SPI Rx data in Memory
void Uart_Tx(unsigned char AsciData); //Serial Tx
sbit SS = 0xB5;
void main()
{
  char i;
  PLLCON = 0x00; //Core Clk = 16.6777MHz
 //////////baud 0f 4800////////
  RCAP2H = -1; RCAP2L = 0x92;
  TH2 = -1;    TL2 = 0x92;
  SCON = 0x50; T2CON = 0x34;
 //////////////////////////////

  CFG814 = 0x01; // Enable P3.5,6,7 for SPI
  SPICON = 0x37; // Master, CPOH=1,CPOL=0
  SS = 0; // Slave Select Enable
  for(i=0;i<20;i++)
  { SPIDAT = 0x00; // SPI Clock Generate
    while(!ISPI); ISPI = 0;
    Data[i] = (unsigned char)SPIDAT;
  }

 /////////Serial Tx SPI Data into UART//////////
  for(i=0;i<20;i++)
  { Uart_Tx(Data[i]); Uart_Tx('\n'); }
 /////////////////////////////////////////////
}

Slave Code, ADuC841

void main()
{ char i;
  SPICON = 0x24; // Slave, CPOH=1, CPOL=0
  for(i=0;i<20;i++)
  { SPIDAT = 0x38; /*Transmit Dummy Data, Asci of '8'
    while(!ISPI); ISPI = 0; }

}


Friendzzzz Please Help.........

Parents
  • I have properly connected Masters MOSI, MISO, SS and SCLK to corresponding lines of Slave. I have also checked the clock on scope. The master (ADuC814) generates clock properly as per the program logic. Even SS pin is low throughout. Bt still no communication happens btween them.
    I changed the slave to ADuC814(earlier ADuC841), and made master transmit the data 2 slave and slave does UART o/p. This works absolutely fine. Here both master and slave operated at same core clock 16.67MHz.Then I changed the slave core clk to 8.3 MHZ, keeping master at 16.67MHz. This time some blanks appeared in between the output (I chkd on HyperTerminal). Don't know why?? Got 2 figure it out. But still I got some output on HT.
    However with ADuC841 as slave and slave is made to transmit the data to master(ADuC814), though I am able to see the SCLK that master generates, the MISO line of slave remains high always. Always blanks get printed on HT. This is what I am not able to get it?? The slave core clock is 11.0592Mz and master operates at 16.67MHz.
    Could there be some synchronization problem like rising edge of master and slave might be different due to different core clock??

Reply
  • I have properly connected Masters MOSI, MISO, SS and SCLK to corresponding lines of Slave. I have also checked the clock on scope. The master (ADuC814) generates clock properly as per the program logic. Even SS pin is low throughout. Bt still no communication happens btween them.
    I changed the slave to ADuC814(earlier ADuC841), and made master transmit the data 2 slave and slave does UART o/p. This works absolutely fine. Here both master and slave operated at same core clock 16.67MHz.Then I changed the slave core clk to 8.3 MHZ, keeping master at 16.67MHz. This time some blanks appeared in between the output (I chkd on HyperTerminal). Don't know why?? Got 2 figure it out. But still I got some output on HT.
    However with ADuC841 as slave and slave is made to transmit the data to master(ADuC814), though I am able to see the SCLK that master generates, the MISO line of slave remains high always. Always blanks get printed on HT. This is what I am not able to get it?? The slave core clock is 11.0592Mz and master operates at 16.67MHz.
    Could there be some synchronization problem like rising edge of master and slave might be different due to different core clock??

Children
  • There shouldn't be a problem that master and slave has different processor clocks. However, the slave normally has a limit on the SPI clock speed, i.e. that the processor clock (or device clock) must be n times higher than the SPI clock signal, to make sure that the SPI slave logic runs at enough speed to be able to react. Some processor may require that the SPI slave logic runs at 12 times the SPI clock but this number can vary from processor to processor.

  • I changed the one slave to ADuC814(earlier ADuC841), and made master transmit the data 2 two slave

    how many slaves?

    that is important to know

    Erik

  • Although this might not be what your problem is, you might as well eliminate it as a potential source...

    You said "Even SS pin is low throughout" so does that mean it is always low like it is shown in your 'master' code?

    I recommend that you insert the SS appropriately between byte transfers. The data-sheet on the ADuC814 indicates that the SS line should be low 'during the byte communication.' (The implication being that it was and/or should return to high otherwise).

    If there is a timing issue, the SS line might be used to reset (or re-initialize) the internal state-machine associated with the bit-level transfers.

    #include <ADUC814.H>
    unsigned char Data[20]; //Store SPI Rx data in Memory
    void Uart_Tx(unsigned char AsciData); //Serial Tx
    sbit SS = 0xB5;
    void main()
    {
      char i;
      PLLCON = 0x00; //Core Clk = 16.6777MHz
     //////////baud 0f 4800////////
      RCAP2H = -1; RCAP2L = 0x92;
      TH2 = -1;    TL2 = 0x92;
      SCON = 0x50; T2CON = 0x34;
     //////////////////////////////
    
      CFG814 = 0x01; // Enable P3.5,6,7 for SPI
      SPICON = 0x37; // Master, CPOH=1,CPOL=0
      SS = 1; // Slave Select Disable // <===== Alter to 1
      for(i=0;i<20;i++)
      {
        SS = 0; // Slave Select Enable // <===== ADD
        SPIDAT = 0x00; // SPI Clock Generate
        while(!ISPI); ISPI = 0;
        SS = 1; // Slave Select Disable// <===== ADD
        Data[i] = (unsigned char)SPIDAT;
      }
    
     /////////Serial Tx SPI Data into UART//////////
      for(i=0;i<20;i++)
      { Uart_Tx(Data[i]); Uart_Tx('\n'); }
     /////////////////////////////////////////////
    }
    

  • BUT

    CodwArchitect for the NXP lpc chips (free from http://www.esacademy.com ) work just fine for the SILabs derivatives (after 5 minutes of work).

    Whether you want to/can use the code from CodeArchitect with your chips or not, have a look, it will give you some guidelines.

    Erik