Sir, I am learning SPI interfacing. I am using P89V51RD2FA microcontroller. And I have to interface it with a device using SPI interface but the problem is that I don't know what to do when I have to obtain data more than one byte.
Like in my case I need 3 bytes of data from the device. So after the usual write commands(giving command to read and the register to be read) and all, I am supposed to send some dummy byte which will be 0s. I wish to know that will the device return me three bytes just by one dummy byte or I need to send one dummy byte for each byte to be received.
SPI is always dual-direction (even if the data in one direction is sometimes ignored) so if the master expects to receive 24 bits of data from the slave, then it must send out 24 bits to generate all the clocking for the 24 bits sent in the other direction.
Some implementations may provide a "read-only" SPI function which provides the clocks without you having to specifically supply some "dummy" data to write.
You have to check the Documentation for the specific device that you're using
That's a pretty common chip, and a very common interface.
Have you searched for examples?
What peripheral, specifically, are you trying to use? Again, have you searched for examples?
"send some dummy byte which will be 0s"
If you send any dummy bytes, 0xFF is more likely to be appropriate...
thanks for ur posts...
I wish to interface the microcontroller with ADE7753(which is a energy metering chip) . Yes I checked the examples but generally all examples are for single byte. I am not able to find any example for more than one byte...
"And sending 0xFF will be better" Can u tell the reason behind this?? It will make the concept more clear.
I didn't actually say that; what I said was,
"0xFF is more likely to be appropriate"
The reason being that the idle state is usually high - so sending FF is effectively doing nothing!
okkk...I get it because of the shift registers present... Also one more thing how am I supposed to send these 24 bits????...3 dummy bytes one after the other ???
It is still not clear to me..please help.
okk...thanks for ur reply
Really?!
Just googling "ADE7753 SPI" gave this:
www.avrfreaks.net/index.php
great thanks seriously I never got that result... thanks again
Sir, the code is not completely correct. Also there is some confusion it will be simpler if u could tell me how to send three bytes.
According to me since SPI is duplex there should be no problem if I do in the following way
like sending word dummy byte data obtained 1st byte dummy byte data obtained second byte dummy byte data obtained 3rd byte
each dummy byte I send will return me a byte of data due to shift registers present. Is it the correct way???? For doing this I will be making use of interrupt signal.
Please look at the above problem and help me.Still one aspect is not clear to me.
"Still one aspect is not clear to me." And you didn't think about writing out exactly what aspect that would be? We have to guess?
Now we are back 3 days. Haven't you tested the code?
Have you thought about the slave-select signal?
Have you configured your SPI to use correct mode, i.e. what phase of the clock to latch on, and if the bus should idle in high or low state?
What are you doing to figure out what goes wrong? Just requesting code from this forum, or are you looking at the signals? Remember that SPI is synchronous. Being the master side, you can slow down the communication so you can take a closer look at the signals.
I am soldering the hardware at present so really can't test it. But it will be ready in a day or two.
Yes I have thought about slave signal.Since I am also using an EEPROM also.So controlling them is important.
I have thought about the configurations but I am not sure with it..Since I can't test at present.
But this line is there in the datasheet and I am making use of this. "Data shifted in at falling edge and shifted out at the rising edge of the sclk." This is there for my peripheral device.
I don't want u to provide me the code I wish to develop it but I want u to help me develop the concept.
And yes I agree with ur last comment on slowing down the commn. to check it.
Please provide me some clarity on reading three bytes...