SUB-20 Slave Mode

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

Moderator: serg

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

SUB-20 Slave Mode

Post by acalogirou »

Hi,

The hardware setup i am currently using is a SUB-20 in slave mode connected to a DSP board. The DSP is set up to run as an SPI master and the SUB-20 is running as an SPI slave. The software is being written using C#. Currently i am able to use the FIFO_Read function to receive a byte of information from the DSP. Depending on the byte received the SUB-20 then needs to return a certain amount of data. The master device is aware of the amount of data that should be received and has been programmed to clock this data through the SPI chain by sending dummy data. So far however i have not managed to get the DSP to receive the correct data back from the SUB-20. I am using the FIFO_Write function to send the data back however the values received are wrong. Has anyone else experienced any issues with running it in this way or know of any solutions. Cheers in advance.

Andy

serg
Posts: 143
Joined: Mon Aug 31, 2009 9:17 pm

Re: SUB-20 Slave Mode

Post by serg »

Hi Andy,
Could you try to use the subtool GUI app to reproduce the issue?
Regards

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

Re: SUB-20 Slave Mode

Post by xol »

Hi,
You should also to be sure about the sequence of the read/write(s).

The SPI slave (as well as master) is sending and receiving data simultaneously. I mean while the bit is shifted out from master via MOSI the MISO is shifted in. So if your master shifts out 1 byte at the same time in shifts in 1 byte.

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

Re: SUB-20 Slave Mode

Post by acalogirou »

Current set up i am trying after the advice above is as follows:

Sub Tool:
  • SPI Tab
    Enable is Ticked
    Slave is Ticked
    Polarity is Rise
    Phase is SmplSetup

    FIFO Tab
    SPI is ticked
    Timeout is 1000
    Read Byte Count is 1
I then type in a message to send e.g 5 and press write in the FIFO tab. When i then run the code on the DSP i receive the value sent, 5.

When i try the equivalent in C# however it does not work:

Code: Select all

Sub20 dev = new Sub20();
dev.Open();
dev.LDC_Write("\f");

dev.SPI_SetConfig(Sub20.SpiEnable | Sub20.SpiSlave | Sub20.SpiCpolRise | Sub20.SpiSetupSmpl);
dev.FIFO_SetConfig(Sub20.FifoSelectSpi);

byte[] output = new byte[1];
output[0] = 5;
int x = 0;

dev.FIFO_Write(output, 1000, ref x);
Using the C# code the DSP reads a value of 2.

Hope that all makes sense.

Andy

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

Re: SUB-20 Slave Mode

Post by xol »

You've missed phase:
Sub Tool:
Phase is SmplSetup
Code:
Sub20.SpiSetupSmpl

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

Re: SUB-20 Slave Mode

Post by acalogirou »

Phase has been included in the code snippet above and the list of values for the Sub-20 app.

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

Re: SUB-20 Slave Mode

Post by xol »

I mean you have different phase configurations in SUB Tool and in your program.

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

Re: SUB-20 Slave Mode

Post by acalogirou »

Thanks for pointing that one out. I am now able to send one byte of data to the DSP. The new issue i beleive is to do with how the SUB-20 clocks the data in its FIFO to the DSP.

The c# program i run first does the following:
  • 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
I then run the code on the dsp that does the following:
  • Pull the SS Pin Low
    Send two bytes of data via MOSI
    Read two values received via MISO
    PUll the SS Pin High
What happens however is that if i run this code i only get the first value the first time. i.e 10 and then if i run it again i get the second value i.e 20. I believe this is because the SUB-20 is using the transition of the SS pin from low to high in order to tell it to send each byte of data as there is no option for sz in the FIFO_Write function in C#. Is this actually the case? The same thing happens if i use the app.

Cheers

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

Re: SUB-20 Slave Mode

Post by xol »

Hi,
No, this is not the case. SUB-20 slave is active as long as SS is low.
I wonder, if you push 2 bytes into FIFO why x=1 ?

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

Re: SUB-20 Slave Mode

Post by acalogirou »

Ah i assume from your comment that the "ref Description" value (i.e what i call x) in the FIFO_Read and FIFO_Write functions should be the number of bytes being sent and received. Cheers

Post Reply