Loading ...
Sorry, an error occurred while loading the content.

Urgent Help on ATMEGA 16 SPI Communication needed

Expand Messages
  • adnan_engineer88
    Hi, I`m trying to communicate one atmega 16(Master) with another atmega 16(Slave)using Interrupt Driven SPI.The problem is that the code for the Master side is
    Message 1 of 1 , Mar 2, 2010
    • 0 Attachment
      Hi,

      I`m trying to communicate one atmega 16(Master) with another atmega 16(Slave)using Interrupt Driven SPI.The problem is that the code for the Master side is working partially but the slave side isn`t working at all.
      Can any one help me these code.I`m posting both ends of the code.Please reply soon

      [code]

      Master Spi code

      #include<stdio.h>
      #include<io.h>
      #include<interrupt.h>

      #define SS PB4
      #define MOSI PB5
      #define MISO PB6
      #define SCK PB7

      void SPI_MasterInit(void);

      int main(void)
      {

      DDRA = 0xFF;
      sei();

      SPI_MasterInit();//initializinfg spi

      PORTB &= ~(1<<SS);

      SPDR = 0x33;

      for(;:
      {
      }

      return 1;
      }

      void SPI_MasterInit(void)
      {
      /* Set MOSI,SCK,SS output, all others input */
      DDRB |= (1<<MOSI) | (1<< SCK) | (1<<SS);
      /* Enable SPI, Master, set clock rate fck/4 */
      SPCR |= (1<<SPE) | (1<<MSTR) | (1<<SPIE);

      }

      ISR(SPI_STC_vect)

      {
      //SPI_output_data=SPDR; // read out new data received
      SPDR = 0x33; // load new data to start SPI transmission

      }

      Slave Spi code

      #include<stdio.h>
      #include<io.h>
      #include<interrupt.h>

      #define SS PB4
      #define MOSI PB5
      #define MISO PB6
      #define SCK PB7

      void SPI_SlaveInit(void);

      int main(void)
      {

      DDRA = 0xFF;

      PORTB=0xB0; // pull up on MOSI,SCK,SS

      SREG |= 0x80;

      //sei();

      SPI_SlaveInit();//initializinfg spi

      for(;;
      {
      }

      return 1;

      }

      void SPI_SlaveInit(void)
      {

      /* Enable SPI, Master, set clock rate fck/4 */
      SPCR |= (1<<SPE) | (1<<SPIE);
      }

      ISR(SPI_STC_vect)

      {
      //SPI_output_data=SPDR; // read out new data received
      PORTA = SPDR ;

      }
    Your message has been successfully submitted and would be delivered to recipients shortly.