Hi all, We are stuck here with the spi problem. We have with us two AT89C51ED2 boards. We trying some small experimentation on the SPI before we start our actual work. The board have a 40MHz crystal.
We want to use one board as MASTER and other as the SLAVE. Problem is when we transmit something from the MASTER we are not able to read the same value from the slave ISR. I have put below the excerpt of both the master and slave code. could anyone shed some light please.....? Connections done are as follows....
MOSI of master to MOSI of Slave MISO of master to MISO of Slave SCLK of master to SCLK of slave SS of master to VCC SS of slave to P1_0
Please note that we make the P1_0 low when we write something to the SPDAT and Make it high again when the SPIF in the Master is set ie after transmission is done.
The master init is as follows SPCON |= 0x10; /* Master mode */ SPCON |= 0x20; /* set SSDIS bit */ SPCON |= 0x01; /* Fclck / 4 */ IEN1 |= 0x04; /* enable spi interrupt */ SPCON |= 0x40; /* run spi */ P1 |= 0x01; /* Deselect the slave first */ EA=1; transmit_completed = 0; /* clear software transfert flag */
The master isr excerpt void it_SPI(void) interrupt 9 /* interrupt address is 0x004B */ { switch ( SPSTA ) /* read and clear spi status register */ { case 0x80: serial_data=SPDAT; /* read receive data */ transmit_completed=1;/* set software flag */ break; } }
The Slave init is as follows SPCON &= ~0x10; /* slave mode */ IEN1 |= 0x04; /* enable spi interrupt */ SPCON |= 0x40; /* spi run */ transmit_completed = 0; /* clear software transfert flag */ EA=1; /* enable interrupts */
The slave ISR excerpt
void it_SPI(void) interrupt 9 /* interrupt address is 0x004B */ { switch ( SPSTA ) /* read and clear spi status register */ { case 0x80: serial_data=SPDAT; /* read receive data */ transmit_completed=1;/* set software flag */ break; } }
Thanks and regards pachu