Full duplex communication using SPI

Status
Not open for further replies.
This is first time I am using SPI to achieve full duplex communication between two Atmega 128.
Master has held controlled SS pin low while transmitting data and the pin is SET once data has been transmitted.
My Slave is receiving data transmitted by Master but Master is not receiving the data transmitted by Slave.
I also attach C code files of Master as well as Slave.
USART is initialized just to confirm whether data has been received or not.
I also attach simulation file(PROTEUS).
So please help me to overcome this problem.
 

Attachments

  • master.txt
    1.6 KB · Views: 497
  • slave.txt
    1.8 KB · Views: 449
I've not much experienxe with SPI too, but it is possible to late write Data into the SPDR when SS Port is low and transmission is in progress.

I would to try to make the transmission in 2 Steps.
In first step write the byte from master to slave.
In Master Routine wait a little bit to give slave a chance to write back his data to SPDR.
Then master can read the bytes from slave.

Another possible way can be to wait a little bit after set the port of !SS in master.
That give slave a chance to write into SPDR.

Another Question:
Do you use the MISO, MOSI, CLK, !SS Pins for transmission ?
Or an USART ?
 
no i used MISO MOSI AND !SS foe transmission
USART is used just to print received data
by the way i'm clear about your solution
how to achieve it through programming?
 
I think you compiler knows the command delay_ms(xx) or delay_us(xx).
In my compiler it is containend in the delay.h library.
So you can get defined delays in your program.
 
I have given delay of 5ms in Master programme to wait for slave to load data into SPDR. But still Master is not receiving data.
One more interesting thing is that,in my slave programme i have given the condition so that Slave will first check whether its !ss pin is held low or not and if it is low then only Slave will transmit/receive data as is required.
But if I remove the condition and call the function to transfer/receive data in Slave programme then Master receives data.
So can any guess now what could be the problem?
 
I've found that in the Datasheet of ATMEGA64 Controller at Page 165:
When i understand right, the Data must be in SPDR before the !SS line is low.
The sending Data must be written in the SPDR register before the incoming data is readed.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…