SPI Receive Clocking on E128

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

SPI Receive Clocking on E128

2,555 次查看
EagleBeak
Contributor I
From looking at legacy code, it appears that to generate the SPI clock for the master to receive data from the slave, you must place a byte in the data register, which makes sense because the data coming from the slave comes in on a different pin.
 
The SPI guide under CPHA = 0 Transfer Format says:
 
"Data that was previously in the master SPI Data Register should now be in the slave data register and the data that was in the slave data register should be in the master."
 
So for an SPI slave device that takes a two byte command and returns two bytes,  one would:
 
1. Transfer command byte 1
2. Transfer command byte 2
3. Write a dummy value into the data register to clock in the response from the slave
4. Retrieve the value in the data register, which is the byte from the slave.
5. Repeat steps 3. & 4.
 
Is this correct?
 
Thanks,
Eagle Beak
标签 (1)
0 项奖励
5 回复数

598 次查看
Alban
Senior Contributor II
Eagle Beak,
I agree fully as long as you cable all the wires.
In single wire mode (connecting MISO/MOSI together with pull-up) the "dummy" data must be 0xFF not to interfere with the incoming data on the wired-or bus.
 
Alban.
0 项奖励

598 次查看
EagleBeak
Contributor I
Alban,
 
Makes sense about the dummy data being 0xFF. The legacy code I was using just placed whatever happened to be in the A register into the SPIDR but we do have both wires hooked up. I think it would be good to send 0xFF anyway to prevent any possible problems from the slave device and it makes measuring it on the scope less confusing.
 
Thanks!
 
Eagle Beak
0 项奖励

598 次查看
bigmac
Specialist III
Hello Eagle Beak,
 
Yes, that would seem basically correct.  What is the SPI slave device you are using?
 
Regards,
Mac
 
0 项奖励

598 次查看
EagleBeak
Contributor I
Mac,
 
The slave device is an X9111, a programmable resistor used as a gain pot on an op-amp circuit.
 
Eagle Beak
0 项奖励

598 次查看
bigmac
Specialist III
Hello Eagle Beak,
 
The correct setup for the X9111 would appear to be CPHA = 0 and CPOL = 0.  You could also use the single data line (MIMO)mode, as Alban suggested, if to your advantage.
 
Regards,
Mac
 
0 项奖励