CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Problem in Full Duplex SPI communication

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
gokulrred



Joined: 22 Nov 2011
Posts: 32
Location: puducherry

View user's profile Send private message Send e-mail

Problem in Full Duplex SPI communication
PostPosted: Wed May 30, 2012 12:43 am     Reply with quote

Hi all...

I am using the following for the project:
Two PIC18F4431.
Two motors with encoders

I tried to send and receive encoder position values between the PIC controllers through SPI.

I want to display both position values through both PIC.

I am able to send data from MASTER PIC to SLAVE PIC and display both values in SLAVE PIC.

I couldn't send data from SLAVE to MASTER and display values in MASTER.

Plz help me by providing codes for full duplex communication.
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Wed May 30, 2012 1:50 am     Reply with quote

With SPI (and I2C in most configurations) you cannot send from a slave to the master. The master must ask for the slave's data.

CAN would be a more appropriate bus for this as any device on the CAN bus can send its data whenever it wants. Other devices then listen to whatever messages they want to hear.

RF Developer
gokulrred



Joined: 22 Nov 2011
Posts: 32
Location: puducherry

View user's profile Send private message Send e-mail

PostPosted: Wed May 30, 2012 2:29 am     Reply with quote

RF_Developer:::::

thanks for ur quick response sir.......

but if i need to send a data from the slave side to the master side how to do???????


u said the master must ask slave's data...
how to do?

i desperately need it.... plz help me....
RF_Developer



Joined: 07 Feb 2011
Posts: 839

View user's profile Send private message

PostPosted: Wed May 30, 2012 6:30 am     Reply with quote

SPI is master-slave. All SPI transfers are controlled by the master. Slaves cannot send anything unless the master starts a transfer of data.

BUT in SPI data is sent in both directions at the same time. Its full-duplex in that sense. Its possible for the slave to send data to the master while the master to is sending to to the slave.

It is unusual for data to actually be transmitted in both directions at the same time, but it is possible. What usually happens is that the master sends some command in the first byte or few bytes, what then happens, either master sending data of slave sending back data, depends on what the command means.

Think about a very common use of SPI: for eeprom/flash memories. Commands are often single bytes meaning things like: read, write, read page, write page, erase page, write lock and so on. A write is done by sending the write command byte, then maybe two or three address bytes followed by one or more data bytes. A read is done by sendign a read command byte, a few address bytes then the slave sends back the data that's read.

Another example is a configurable ADC. The first byte is a command, maybe setting up a mode: acq time, number of bits, channel number etc. Then the master has to send a start conversion command. Then it polls the ADC to check it the conversion is finished; the slave sending back a status byte each time. Finally the master asks the slave for its data by sending a read command, to which the slave responds by sending its data.


So, data can be sent both ways, even in the same SPI sequence, but they must always be started and controlled by the master and the slave MUST be able to respond in a known time. This means that for a PIC slave, you probably have to implement the SPI slave using interrupts.

Take a look a the datasheets of a few SPI ICs: a memory, an ADC a DAC for example. See how they do it. Do something similar.

RF Developer.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group