This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

TMS570LS0432 SPI communication between SPI2 and SPI3

Other Parts Discussed in Thread: HALCOGEN, TMS570LS0432

 Hello,

I'm using TMS570LS0432, Halcogen 03.05.02 and CCS 5.4.0.00091.

So I want to get communication between SPI2 and SPI3 ports (didn't chose to use loopback because from brief explanation in datasheet TMS570LS04x I didn't comprehend how to.. and video example for MibSPI didn't work because of DMA (the video is for RM48x anyways)).

First of all, I did wiring  which is fairly easy (SIMO_port3-SIMO_port2, SOMI_port3-SOMI_port2, CLK_port3-CLK_port2, CS_port3-CS_port2). Checked output line with the scope (SIMO, CS, CLK) just with send function in master mode- signal OK.

But receive line seems to get stuck at line " while((spi->FLG & 0x00000100U) != 0x00000100U)   {   } /* Wait */ "  of  "spiReceiveData" function. So It doesn't receive "RXINTFLG".

 

My code:

 #include "spi.h"

#define length 15

uint16 RXbuf[length]={0}, TXbuf[length]={0}, priimti[length];


spiDAT1_t structure;

spiDAT1_t *pointer;

void main (void){

uint32 indikatorius=0,indikatorius1=0;

pointer=&structure;

_enable_IRQ();
spiInit();

for(i=0;i<length;i++)

{ TXbuf[i]=15-i; }

while(1)

{

indikatorius=spiTransmitData(spiREG2, pointer, length, TXbuf);

indikatorius1=spiReceiveData(spiREG3, pointer, length, RXbuf);

}

}

1. Could someone please show me how to make this communication work (any working code would be appreciated)? Because there are functions, which repeat themselves (and I get confused at this point):

uint32 spiTransmitData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff);

void spiSendData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff);

uint32 spiTransmitAndReceiveData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff, uint16 * destbuff);

void spiSendAndGetData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff, uint16 * destbuff);

 

2. In function "spiTransmitData" what does second member stand for ("pointer"). I inserted it just to make things work but didn't understand meaning of this member.

3. A link, to using loopback function (or explanation) would be apreciated.

 

Regards,

I'm sorry for making such confusion, but maybe someone could help me, at least partially, to get started here.

 

 

  • Just forgot to mention explanation about interrupt would help as well.

  • Hi Vytautas,

    the SPI on Hercules device is full duplex.

    can you please try to have both transmit and receive issue for each SPI?

  •  Hi Henry,

    I don't know if I understood you correctly, but I connected master (PORT2) SIMO-SOMI pins together, else left unconnected. This worked for master (just used one function

    spiTransmitAndReceiveData ). But  when I tried same for slave (PORT3), nothing worked out, function got stuck in same place of the function as earlier ("while((spi->FLG & 0x00000100U) != 0x00000100U)   {   }/* Wait */"  ). Why does this happen I am not sure, possibly- since slave is configured to receive clock and not to issue it and I left this pin unconnected for now, same as with CS signal, the port doesn't receive necessary signals, no interrupt flag= get stuck.

    How to make both ports work simultaneously, because I haven't tried implementing things with interrups, but at one moment (in polling) processor can service only one port and if I understood correctly, while one port is sending the other is not responding and when time comes, for slave port to receive data- it doesn't receive a necessarry flag and waits in while.

  • Hi Vytautas,

    This is what i meant:

    SPI2 (master)   --> SPI3 (slave)

    SIMO              ->  SIMO

    SOMI              <-  SOMI

    CS                   -> CS  (see attachment).

    Then, on each SPI2 and each SPI3, you have to call TX and RX function for each SPI since each SPI is a full duplex.


    Hope this helps.

  •  Hi Henry,

    So to make things a bit more clearer, this is what I did with Halcogen:

    Pinmux- enable SPI2 and SPI3.

    TMS570LS0432->Driver enable: Enable SPI2 drivers, Enable SPI3 driver.

    SPI2->SPI2 Global: Master mode enable, Internal Clock enable (else not enabled here)

    SPI2->SPI2 Port: All pins are set to OUT except for SOMI.

    SPI3->SPI3 Global: All unchecked.

    SPI3->SPI3 Port: SOMI set to output, all others are in INPUT mode.

    These are all configurations I did with Halcogen (I did these from beginning).

     

    As I mentioned before, in Master mode I've managed to make SPI's work (separately), when same port output is connected to the input (SPI2 SIMO- SPI2 SOMI), same with SPI3. Conclusion- Master mode works.

    Now the part i don't understand (the CCS part) "Then, on each SPI2 and each SPI3, you have to call TX and RX function for each SPI since each SPI is a full duplex.". (could you clarify, how this looks in CCS code?).

     

    What I thought you mean (expression in code) (it was easy to try out, so I can say that it stops when starts excecute slave lines):

     while(1)   {   

    indikatorius=spiTransmitData(spiREG2, pointer, length, TXbuf);   

    indikatorius1=spiReceiveData(spiREG3, pointer, length, RXbuf1);   

     indikatorius2=spiTransmitData(spiREG3, pointer, length, RXbuf1);   

     indikatorius3=spiReceiveData(spiREG2, pointer, length, RXbuf2);  

     }

    Still don't know what second member ("pointer" in this case) is used for. 

    Whenever I call function to service Slave (SPI3), code gets stuck, because it doesn't receive some flag ( while((spi->FLG & 0x00000100U) != 0x00000100U)     {     } /* Wait */ ). As you probably noticed I'm repeating myself. So I think we miss a detail that you probably think is very simple and probably not worth mentioning.

     

    P.S. I'm not sure how the system works so here are few thoughts:

    1) (What I think) If you send data with Master, then you can not service slave at the same time. Slave is serviced with the next line (but practice shows that code doesn't receive required flag). Everything stops.

    2) (Friend of mine told) I need to control Master and the rest actions in slave are done automatically, so I need to call only master functions (practice shows that data is being transmitted but received data is always 0x0000...).

     

    Conclusions:

    I don't know how to make source code for Master, which sends data, and after a few iterations, it receives what was sent earlier. And I would really appreciate a brief source code (either in polling or interrupt method), that makes this miracle happen. (I don't want to be rude, but lines like "and then you call send receive functions, but this is the easy part so I won't get into details." annoys me.)

     

    Best wishes

     

     

     

     

  • Vytautas,

    uint32 spiTransmitData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff)

    As you can see here, the "pointer" that you mention about is the pointer pointing to the data configuration of the SPI DAT1.  

    Look into the function in C codes to see how it is used.

    SPI DAT1 register has data format select, CSNR, etc.

    At the end of spiTransmitData function (after writing to SPIDAT1), it will poll for SPI receive interrupt bit.

    Note that this wait for receive interrupt bit exists inside the spiTransmitData function.  

    Why? This is because of the full duplex nature of SPI.

    Note that SPI3 will be the slave.  

    So, you only need to initialize the SPIDAT1 that you want the slave to transmit back to master, but don't need to call a send function.

    The master sends the SPICLK + CS to the slave to make the slave transmitting to master as well as receiving data from master.

    Look into spiReceiveData function, you can see that it does the transmit (writing to 0x0 SPIDAT1) and then poll for receive interrupt bit.

    Again, this is the full duplex nature of SPI.  

    I hope this makes sense to you.

    Why are you trying to send SPI2 to SPI3 of the same device?  

    can you please let us know what you are trying to accomplish?

  •  Hello Henry,

     

    This last post was just what I needed.  As you are asking- "why I need this kind of operation mode"- just for testing and better understanding of whole SPI (because the board I possess, has two SPI's so I can try this out in hardware level with no additional expenses).

    To solve out the problem I just needed to put this line: (spiREG3->DAT1=spiREG3->BUF;)  before wait (polling) loop in spiTransmitAndReceiveData receive function.

    Now I receive data I sent, just one more thing.

    Why is it lagging by 2 iterations, because I send 15 words of data, first one is always 0xffff, second - 0x0, and then data which I sent in correct order, just missing two last members, but when I repeat sending those last two members are in the first positions and as well other members in correct order, just the last member is again n-2 member.

    I would guess that might occur because of data left in SPIDAT0 and SPIDAT1 buffers of slave, but how to make things to line up from 1st member to the last in my master receive buffer. (probably that would be sending some additional dummy data, but how to do this ).

     

    Anyway, thanks a lot Henry you were very helpful.

  • Hi Vytautas,

    I am glad this helps you so far.

    Regarding your lagging problem, i am not sure yet.

    I would expect something wrong in the way you call these SPI functions or the way you initialize your buffers to be sent to these SPI call function.

    Try smaller buffer size first (start from 1 element and increment up) to debug your codes. 

  • Hi again,

    Just wanted to ask would this be appropriate solution:

    MASTER(send data)->SLAVE(receives to SPIBUF) and at the same time copy received data to SPIDAT1->MASTER (receive data)   This is full duplex data transition mode.

     

    But, since before first send, there is some data left in slave (SPIDAT1 the sending buffer) I call "spiTransmitAndReceiveData" function to shift current data.

    So what I get- data I sent, is now in my receive buffer, but late by one send cycle.

    Question: Is is adequate, to make additional function "spiTransmitAndReceiveData" call, everytime I want to send data and moreover, do a for() cycle to rearange data to be in proper order (this consumes processor resources)? Or maybe there already are made up functions to avoid this mess.

     

    Regards.