Right,
But if you want to send 2 bytes it has to be 2 not 1 like in your code:
Setup the Sub20 as slave as shown above with the new phase used
Create a byte array of size 2 (with values 10 and 20)
FIFO_Write(array, 1000, ref x) where x = 1
In any case I think we will need to see scope pictures to understand operation of your SPI master. Can you get it?
From doing some more playing around with the information i have i am able to send and receive one byte of information at a time between Master and Slave using the C# code or the SUB-20 tool(i am using the FIFO read and write in the sub tool) and the DSP.
As soon as i try and send or receive more than one byte however it does not work. All i receive either way Slave -> Master, Master -> Slave is just the first byte of information. The master device is a DSP which has been programmed in C and is programmed as follows:
//Pulls SS Pin low
EALLOW;
GpioDataRegs.GPACLEAR.bit.GPIO27 = 1
EDIS;
//Sends 2 bytes of data
spiXmit((0x01)<<8);
spiXmit((0x02)<<8);
//Pulls SS Pin high
EALLOW;
GpioDataRegs.GPASET.bit.GPIO27 = 1
EDIS;
//Pulls SS Pin low
EALLOW;
GpioDataRegs.GPACLEAR.bit.GPIO27 = 1
EDIS;
//Sends an 8 bit message via SCI. The reason for the 8 bit bit shift it to do with the fact that 16 bits can be shifted at a time so the message needs to move to the MSB before send by the DSP. The SPI is configured however so the DSP knows to send 8 bits on each spiXmit. The bytes are sent in order to clock through the message from the slave device
for (i = 0; i < 2; i++)
{
spiXmit((0x00)<<8);
}
//Waits for a message in the receive buffer and then stores it in an array.
for (i = 0; i<2; i++)
{
while(SpibRegs.SPIFFRX.bit.RXFFST == 0 {}
configReg[i] = ((SpibRegs.SPIRXBUF & 0x00FF)
}
//Pulls SS Pin high
EALLOW;
GpioDataRegs.GPASET.bit.GPIO27 = 1
EDIS;
The SUB-20 tool is configured:
SPI
Polarity: Rise
Phase: SmplSetup
Bit Order: MSB First
SCK: 8Hz
Enable: Ticked
Slave: Ticked
Byte Count: 2
SS Pin: SS0
SS Mode: SS_LO
The c# code is the same as i stated earlier however i have moved away from the c# till i could get it working with the SUB-20 tool first as i believed that would be simpler. If there is any more information required please do ask and i will do my best to provide it.
HI,
Lets start with DSP Master write --> SUB-20 slave reads.
After we make it work I think opposite direction will also work.
Now tell me
1. What clock frequency DSP SPI master works at?
2. Do follwoing
- Configure SUB-20 SPI
- Configure SUB-20 FIFO
- Run DSP SPI write (Tell me what bytes are written)
- Read SUB-20 FIFO
Now tell me what exactly do you get? How many bytes are read and what are the values?
3. Can you take the scope pictures of the SPI transfer?
I was going to do the test you asked for however i noticed a small error in the DSP code and when that was changed i can now send any number of messages from the DSP and receive them on the SUB-20 so that bit is sorted. I tried to do the same tests with the SUB-20 sending to the FIFO and the DSP receiving however the results have been rather weird. Setup is as follows:
//Pulls SS Pin low
EALLOW;
GpioDataRegs.GPACLEAR.bit.GPIO27 = 1
EDIS;
//Sends an 8 bit message via SCI. The reason for the 8 bit bit shift it to do with the fact that 16 bits can be shifted at a time so the message needs to move to the MSB before send by the DSP. The SPI is configured however so the DSP knows to send 8 bits on each spiXmit. The bytes are sent in order to clock through the message from the slave device
for (i = 0; i < 2; i++)
{
spiXmit((0x09)<<8);
}
//Waits for a message in the receive buffer and then stores it in an array.
for (i = 0; i<2; i++)
{
while(SpibRegs.SPIFFRX.bit.RXFFST == 0 {}
configReg[i] = ((SpibRegs.SPIRXBUF & 0x00FF)
}
//Pulls SS Pin high
EALLOW;
GpioDataRegs.GPASET.bit.GPIO27 = 1
EDIS;
SUB-20 is configured:
SPI
Polarity: Rise
Phase: SmplSetup
Bit Order: MSB First
SCK: 8Hz
Enable: Ticked
Slave: Ticked
Byte Count: 2
SS Pin: SS0
SS Mode: SS_LO
FIFO
SPI: Ticked
Timeout: 100
Read Byte Count: 2
Data(hex): 10, 20 (should these values be seperated by commas?)
I then run the code in the following order:
1) Click on "Write" on the SUB-20 app
2) Run the DSP software
The values i receive are as follows:
The first value is 10 so the first value i should have received (correct)
The second value is 9 which is the value the master sent in order to clock through the response
I have changed the values the DSP sends to clock through the response and if i do so the second value received is the value sent from the DSP.
I attached the MISO to GND and the values the master DSP received were 0.
Below are the ocilliscope traces. The messages sent by the Master DSP to clock through the data is 9 (in hex).
The messages put into the FIFO from the SUB-20 is 10 and 20 (in hex).
I do apologise i posted the wrong image of the CLK and MISO. Here is the correct one which is similar but this time the value is 0x10.
The 'Write' button was pressed on the Sub-20 app before the data was attempted to be read.
I then run the code in the following order:
1) Click on "Write" on the SUB-20 app
2) Run the DSP software
The values i receive are as follows:
The first value is 10 so the first value i should have received (correct)
The second value is 9 which is the value the master sent in order to clock through the response