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.

CCS/TMS570LS1224: TMS570LS1224 :SPI

Part Number: TMS570LS1224
Other Parts Discussed in Thread: HALCOGEN

Tool/software: Code Composer Studio

         as given in the datasheet to configure the L3GD20H sensor as SPI interface CS must be low (1: I2C mode; 0: SPI enabled)

i connected CS of L3GD20H to pin J9.3 (MIBSPI1NCS[0]) is it right to configure CS to be low (from SPI1 select SPI1 port  enable DIR of SCS[0] and DOUT =0)

or their is another way to do that

Best Regards

  • Hello,

    Your connection to J9.3 is right.
    In Port Tab just set all pins that you are NOT using as GIO ( not functional ) and all used as Functional. DOUT and DIR check-boxes are valid only when pin is set to be GIO and you don't have to set them for the pins set as functional. When the pin is set as functional the I/O direction is determined by CLKMOD bit in SPIGCR. In other words, when TMS570LS1224 is set as master CS is output. By default CS is active low. Default CS state is controlled by SPIDEF register.

    According to L3GD20H datasheet:

    " CS is the Serial Port Enable and it is controlled by the SPI master. It goes low at the start of the transmission and goes back high at the end. SPC is the Serial Port Clock and it is controlled by the SPI master. It is stopped high when CS is high (no transmission). "

    All this is handled by SPI module in TMS570LS1224.

    Detailed description of SPI module is in Chapter 28 of TMS570LS1224 TRM

    There is an example for using SPI module in HALCoGen - under examples folder and in Help->Help topics->Examples.

  • Hello Miro,

    my halcogen configurations are enabled the SPI1 driver  , check clock polarity (0)and clock phase (1)  and SPI frequency is 10 MHz. (Baudrate set to 10MHZ) ,In SPI1 Port i enabled each (SIMO[0],SOMI[0],CLK  and  (SCS[0] ) as SPI and the others as GIO    ) then i  generated the code

    in ccs i wrote the following code 

    #include "sys_common.h"
    
    /* USER CODE BEGIN (1) */
    #include "spi.h"
    /* USER CODE END */
    
    /** @fn void main(void)
    *   @brief Application main function
    *   @note This function is empty by default.
    *
    *   This function is called after startup.
    *   The user can use this function to implement the application.
    */
    
    /* USER CODE BEGIN (2) */
    uint16 TX_Data_Master[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    uint16 RX_Data_Master[16] = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
    /* USER CODE END */
    
    void main(void)
    {
    /* USER CODE BEGIN (3) */
        spiDAT1_t dataconfig1_t;
        sint16 x,y,z=0;
    
        dataconfig1_t.CS_HOLD = TRUE;
        dataconfig1_t.WDEL    = TRUE;
        dataconfig1_t.DFSEL   = SPI_FMT_0;
        dataconfig1_t.CSNR    = 0xFE;
    
    
        spiInit();
    
        while(1)
        {
            TX_Data_Master[0] = 0x80 ;        //read
            TX_Data_Master[0] =0xD7;        //WHO_AM_1
            spiTransmitAndReceiveData(spiREG1, &dataconfig1_t, 2, TX_Data_Master, RX_Data_Master);
            printf("Device ID = %x\r\n",RX_Data_Master[1]);
    
    
            TX_Data_Master[0] = 0x20;
            TX_Data_Master[1] = 0x6F;
            spiTransmitAndReceiveData(spiREG1, &dataconfig1_t, 2, TX_Data_Master, RX_Data_Master);
    
    
              TX_Data_Master[0] = 0x80 | 0x40 | 0x28;
              spiTransmitAndReceiveData(spiREG1, &dataconfig1_t, 16, TX_Data_Master, RX_Data_Master);
    
              x = (sint8)RX_Data_Master[2]<< 8 | (sint8)RX_Data_Master[1];
              y = (sint8)RX_Data_Master[4]<< 8 | (sint8)RX_Data_Master[3];
              z = (sint8)RX_Data_Master[6]<< 8 | (sint8)RX_Data_Master[5];
    
              printf("x = %d, y = %d, z = %d\r\n",x,y,z);
    
        }
    /* USER CODE END */
    }
    

    i received  i don't know what is my mistake any help 

    here is L3G datasheet (https://www.pololu.com/file/0J731/L3GD20H.pdf)

  • Hello,

    Since I am not familiar with this sensor I can't be very specific in my comment. May be you should try to reach the sensor manufacturer forum.

    According to sensor datasheet WHO_AM_I register address is 0x0F. From the timing diagram for reading, I can see that bit 7 of the first byte defines whether read or write operation has to be done. In your case this should be read operation ( bit 7 should be 1 ). Because you have to read only one register M/S bit (bit 6) should be 0. The following bits 5-0 defines register address. So, the first byte to send, if you want to read WHO_AM_I register should be 0x8F. In your code you sent D7 which should be the ID read from sensor.

    I am not sure why you are assigning these values (I think you should remove the first row and change the 0xD7 with 0x8F in the second row):

            TX_Data_Master[0] = 0x80 ;        //read
            TX_Data_Master[0] =0xD7;        //WHO_AM_1
    This should be enough to read ID if your wiring is fine and data is going out from MCU.
  • hello Miro ,

    Thanks for your help, As you mentioned I changed the code as below but i still receive 0xFFFF

    while(1)
    {
    
    TX_Data_Master[0] = 0x8F; //WHO_AM_1
    spiTransmitAndReceiveData(spiREG1, &dataconfig1_t, 2, TX_Data_Master, RX_Data_Master);
    printf("Device ID = %x\r\n",RX_Data_Master[1]);
    
    }