SUB-20 Slave Mode

All about Sub-20 Multi Interface USB Adapter USB to I2C, SPI, GPIO, RS232, RS485, Ir, LCD

Moderator: serg

xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Re: SUB-20 Slave Mode

Post by xol »

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?

acalogirou
Posts: 11
Joined: Wed Jul 07, 2010 4:06 pm

Re: SUB-20 Slave Mode

Post by acalogirou »

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:

SPI Send

Code: Select all

//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;
SPI Receive

Code: Select all

//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
FIFO
  • SPI: Ticked
    Timeout: 100
    Read Byte Count: 2
    Data(hex): 10, 20
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.

Cheers in advance.

xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Re: SUB-20 Slave Mode

Post by xol »

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?

acalogirou
Posts: 11
Joined: Wed Jul 07, 2010 4:06 pm

Re: SUB-20 Slave Mode

Post by acalogirou »

Hi,

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:

DSP Setup:

Code: Select all

//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.

Any ideas? Thanks.

xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Re: SUB-20 Slave Mode

Post by xol »

Hi,
Values should not be separated by comas.

Also tell me the CLK rate from DSP master.

acalogirou
Posts: 11
Joined: Wed Jul 07, 2010 4:06 pm

Re: SUB-20 Slave Mode

Post by acalogirou »

I have tried it without the commas and the same thing happens.

The clock speed on the DSP master is 588,235Hz.

xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Re: SUB-20 Slave Mode

Post by xol »

Hi,
In this case I would like to see oscilloscope trace.

Also just to make sure.
Try to disconnect SUB-20 and connect MISO to GND.
What values do you read in DSP in this case?

acalogirou
Posts: 11
Joined: Wed Jul 07, 2010 4:06 pm

Re: SUB-20 Slave Mode

Post by acalogirou »

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).

The first image is CLK and MISO.
Image

The second image is CLK and MOSI.
Image

The third image is CLK and SS0.
Image

xol
Site Admin
Posts: 241
Joined: Sat Aug 29, 2009 8:04 am

Re: SUB-20 Slave Mode

Post by xol »

HI, On the CLK, MISO I can see values 0x40 and 0x09.
I looked again at your setup sequence:
FIFO

SPI: Ticked
Timeout: 100
Read Byte Count: 2
Data(hex): 10, 20 (should these values be seperated by commas?)
I see no click on Write after Data filled. Without Write data will not be sent to FIFO

acalogirou
Posts: 11
Joined: Wed Jul 07, 2010 4:06 pm

Re: SUB-20 Slave Mode

Post by acalogirou »

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.

Image

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
Cheers

Post Reply