ColdFire : "Two-way" communication using SPI

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

ColdFire : "Two-way" communication using SPI

1,203 Views
rizq
Contributor I

Hi all,

 

I am a college student working on my final project. Here, i need to do communication between microcontroller using SPI. The general step of the communication is as follows :

 

1. Master send command to slave

2. Slave interprets the command received from master. Then, it will do one of the following

    a. Do some tasks

    b. "Send" data to master (prepare data in SPI register, waiting to be shifted by master's dummy data)

3. Master shift the data from slave using dummy data (if it previously asks for data)

 

So far i only manage to do step 1. The main problem is, I cannot find the best scheme to be used by master when it waits for the slave to interprets the command. I have tried to do simple handshaking by pulling one port high when the slave has prepared the data, and while the port is still low, the master waits, does nothing. Using this scheme, i have managed to send data from slave to master, but the data i get is not the right data.

 

Can you give me some advice please?

 

Note : I use MCF51JM128 as master and Atmel ATmega16 as a slave

Labels (1)
0 Kudos
2 Replies

806 Views
timias
Contributor IV

With SPI, the master needs to provide clocks to the slave in order for it to shift out the data. Just a guess you are sending 8 bits and expecting to receive 8 bits back, you should make your frame size 16 bits (it is a register setting typically), then when you send out the data the response will be automatically shifted into the receive buffer. Of course this is dependant on the slaves specification, some require the address to be shifted with a one bit pause before the part starts shifting back, others do it right away. Make sure you format your outgoing address correctly, or the part will just ignore it.

 

I am using MQX for my SPI interface on a MCF41JE256, but I gather you don't have time to port that over for your application.

 

Hope this helps

0 Kudos

806 Views
Superdiode
Contributor II

It's a simple idea.
For example, in communications with SD card, Master sends read command to the SD (with address).
1 millisecond later, sending a 0xFF (dummy byte), and the SD can answer two things:
- If the SD does not have any data, send 0xFF (bus idle). We have to wait a millisecond more and try again. This cycle can be repeated "x" times until we take for failed communication.
- If the SD and the data are sent 0xFE. The following dummy byte sends the first byte requested.

Is an example of how you can.

A greeting.

0 Kudos