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.

TMS570LC4357: SPI COMMUNICATION

Part Number: TMS570LC4357
Other Parts Discussed in Thread: HALCOGEN

I Want  to  write  a  code  for  SPI  protocol   using  driver  function  uint32 spiTransmitData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * srcbuff);  uint32 spiReceiveData(spiBASE_t *spi, spiDAT1_t *dataconfig_t, uint32 blocksize, uint16 * destbuff);  just   explain  have  use  in  code  and  build  communication  , explain  the  logic  sir  code  i  will try  to  built 

regards

Jeeva

  

  • 5226.SPI.CODE.txt
    #include "HL_sys_common.h"
    
    
    #include "HL_spi.h"
    #include "HL_sci.h"
    
     void sciDisplayText(sciBASE_t *sci, uint16 *text, uint32 length);
    void spi_func(void);
    #define UART (sciREG1)
    #define SPI1 (spiREG1)
    #define SPI2 (spiREG3)
    #define TX_SIZE 5
        uint16 u16MasterTX_BUF[TX_SIZE] = {0x01,0x02,0x03,0x04,0x05};
       extern uint16  u16MasterRX_BUF[TX_SIZE] = {0};
        uint16 u16SlaveTX_BUF[TX_SIZE] = {0x06,0x07,0x08,0x09,0x0A};
       extern uint16  u16SlaveRX_BUF[TX_SIZE] = {0};
       extern  uint8  u8result1 = 0U;
       extern  uint8  u8result2 = 0U;
    void spi_func(void)
    {
    
        spiInit();
        sciInit();
          spiDAT1_t dataconfig1_t;
    
          dataconfig1_t.CS_HOLD = FALSE;
          dataconfig1_t.WDEL    = TRUE;
          dataconfig1_t.DFSEL   = SPI_FMT_1;
          dataconfig1_t.CSNR    = 0xFE;
    
            spiTransmitData(SPI1, &dataconfig1_t, BUF_SIZE, u16MasterTX_BUF);
    
           spiReceiveData(SPI1, &dataconfig1_t, BUF_SIZE, u16SlaveRX_BUF);
         u8result1 = SpiRxStatus(SPI1);
         u8result2 = SpiRxStatus(SPI2);
    
    }
    int main(void)
    {
    /* USER CODE BEGIN (3) */
        spi_func();
    
        while(1)
            {
              if(u8result1 == 2)
              {
                sciDisplayText(UART, u16MasterRX_BUF, 5U );
              }
              if(u8result2 == 2)
              {
                sciDisplayText(UART, u16SlaveRX_BUF, 5U ) ;
              }
            }
    }
    /* USE
    void sciDisplayText(sciBASE_t *sci, uint16 *text, uint32 length)
    {
        while (length--)
        {
            while ((UART->FLR & 0x4) == 4);
    
                sciSendByte(UART, *text++);
    }
    }

    this  code  i  have  written   spiTransmit data function  and  spi  receive data function  taken  spi.c  driver code sir  directly  iam calling the function from  register spiREG3 , will work  sir , please  tell me 

  • Hi Jeev,

    this  code  i  have  written   spiTransmit data function  and  spi  receive data function  taken  spi.c  driver code sir  directly  iam calling the function from  register spiREG3 , will work  sir , please  tell me 

    You should make sure to enable SPI3 driver in HALCoGen

    And also, you should make sure to configure the required parameters for SPI3

    And also, you should need to enable the pinmux for SPI3 pins

    Once you did those then calling transmit and receive functions with SPIREG3 will work.

    --
    Thanks & Regards,
    Jagadish.

  • thank  you  for  your  answer  but if  i  try  to  make  two  SPI  communication like  one SPI  as  master  and  other one  as  slave , using  same  function  its  possible sir , example SPI1  as master , SPI2  as  slave. in  halcogen CS  select  pin enable , using  Same  controller 

  • Hi,

    thank  you  for  your  answer  but if  i  try  to  make  two  SPI  communication like  one SPI  as  master  and  other one  as  slave , using  same  function  its  possible sir , example SPI1  as master , SPI2  as  slave. in  halcogen CS  select  pin enable , using  Same  controller 

    Yes, you can use the same function. You just need to change the register base address, for spiREG3 for SPI3 and spiREG1 for SPI1.

    But remember one more thing, in master side the data immediately start shifts after you are calling transmit function, however on slave side it will not transfer data immediately because slave requires clock from master. The slave will wait until master sends its data along with clock and then slave also parallelly sends data like full duplex communication.

    --
    Thanks & regards,
    Jagadish.

  • halcogen  set up  same  only know sir , SPI1,SPI3, previous  what  u  said  for  SPI3 ,  in  code  two separate transmit function for both register  and  receive function , 

  • in  code  two separate transmit function for both register  and  receive function , 

    Sorry, i don't get your point.

  • Nothing  sir  once  after execute code  if  i face  any  problem i will text  you , but  last  one  doubt sir , i will ask in  new  thread  related to  SCI protocol 

  • Dear  sir  if  u  have  code  related  to SPI  communication  using  spiTransmitData and  spiReceiveData  which is  test  and  working  send  me sir  by  refering  that  i will built  my code 

  • Hi Jeev,

    Please refer SPI examples available in the below FAQ:

    (+) [FAQ] TMS570LC4357: Examples and Demos available for Hercules Controllers (E.g. TMS570x, RM57x and RM46x etc) - Arm-based microcontrollers forum - Arm-based microcontrollers - TI E2E support forums

    In these examples i used "spiTransmitAndReceiveData" function and in the similar way you can use the "spiTransmitData" function.

    The difference between them is "spiTransmitAndReceiveData" function will do both transmit and receive, that means if master transmitting some data then slave will also send some data right because SPI is a full duplex communication, so this function will transmit data from the tx buffer and it will receive the data into the rx buffer.

    However, if you use "spiTransmitData" this function in master side then it will transmit data, but it will ignore the receive data from slave.

    --
    Thanks & regards,
    Jagadish.

  • Thank  you  providing  example  and  your  support 

  • while((spi->FLG & 0x00000100U) != 0x00000100U)
    {
    }  Dear  sir   it  is  struck   in   this   while  loop how  to  resolve  this  problem   code  also  i  attached  in  previous  message itself ,  help  me   to  overcome  from  this  problem  and  why it is  happening 

  • how  to solve  this  problem  sir  , please help me

  • Hi Jeev,

    That bit we are polling is nothing but RXINTFLG:

    If this bit is not SET means, there is no new data available.

    I would like to know, how you are operating the device master or slave, how you are sending new data?

    Please share your code for debugging?

    --
    Thanks & Regards,
    Jagadish.

  • ok  dear   sir  , i have attach  my completed file  TWO_SPI_TEST.zip

  • Hi Jeev,

    Your project looks very confusion.

    In HALCoGen you are enabling the SPI2 and SPI4:

    So, your initialization code was generated for SPI2 and SPI4

    However, you are trying to transmit/receive data on SPI1 and SPI3? 

    How would this work? Doing initializations for different SPI's and transmit/Receive data on different SPI's?

    --
    Thanks & regards,
    Jagadish.

  • Sorry sir  , first  i choose  SPI1  and  SPI3  then  later  i  have  changed  SPI2 and  SPI4 , i missed  to  change  sir in  code  some place  , Thank  you  sir  i will change  check sir