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 Sensor

Part Number: TMS570LS1224
Other Parts Discussed in Thread: HALCOGEN

Tool/software: Code Composer Studio

Hello,

I am using Halcogen to generate the driver for spi. I am trying to communicate with a simple gyroscope L3GD20H  (https://www.pololu.com/file/0J731/L3GD20H.pdf)

I have seen a lot example codes about spi communication , but still I am not able to communicate with this device. I will try to describe my configuration as detailed as possible. First of all, I use 4-wire SPI communication (SOMI, SIMO, CLK, CS[0]).

More specifically I enabled the SPI1 driver  , check clock polarity (0)and clock phase (1) in Halogen and SPI frequency is 10 MHz. (Baudrate set to 10MHZ) and then i  generated the code .

could anyone help me  in writing the main source in ccs ,I just need to read the three axis (x,y,z) gyro. ( sorry this is my first time to deal with SPI interface ) 

Best Regards,

Ahmad

  • Hello,
    What do you mean with "I am not able to communicate"? Do you observe clock and data going out from the master (using oscilloscope or logic analyzer )?

  • Hello Miro,

    i tried to read the device ID (following the below project) but unfortunately i received 0x00FF.

    for now i just need to receive (x,y,z) gyro reading. and i don't know how to do that.

    Best Regards,

    Ahmad

    5483.spi-adxl.zip

  • Hello,

    Do you have data outgoing from MCU?

  • Here is what the console shows 

    i followed this code



    #include "sys_common.h" #include "spi.h" void main(void) { uint16_t TX_Data_Master[8] = { 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}; uint16_t RX_Data_Master[8] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; spiDAT1_t dataconfig1_t; 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; spiTransmitAndReceiveData(spiREG1, &dataconfig1_t, 2, TX_Data_Master, RX_Data_Master); printf("Device ID = %x\r\n",RX_Data_Master[1]); } }

  • Hello,

    Please, verify that data is going out from MCU (using oscilloscope or other tool).

    From sensor datasheet: Adddress of WHO_AM_I register is 0x0F. Addresses 0x00 to 0x0E are reserved and value is not defined.

    You should send R/W bit followed MS bit and address in the first byte.

  • Hello Miro,

    the problem is solved. i receive the correct device ID.

    could you please help me with reading x,y,x gyroscope   sensor data.

    Best regards,

    Ahmad

  • Hello,

    I am not aware with this sensor. Please, use sensor manufacturer forum for information how to use it. Reading any register should be done in a same manner.

  • i tried without any success . I am unable to follow the datasheet and understand how to use it.

    Thank You! 

  • Hello,

    TI does not provide driver for communication between  Hercules MCUs and ADXL345 . You should write your own driver following the datasheet of the device.According to datasheet you can use both I2C and SPI interfaces. HALCoGen generates APIs for both Hercules MCUs modules and you can use this APIs while following the datasheet of ADXL345

  • Hello Miro,

    i need your help in writing the main code please.as i mintioned above I use 4-wire SPI communication (SOMI, SIMO, CLK, CS[0]). 

    I  connected SDA To J9.6, CLK To J6.7 ,SDO to J9.7 and CS to J9.3  

    I enabled the SPI1 driver  , check clock polarity (0)and clock phase (1) in Halogen and SPI frequency is 10 MHz. (Baudrate set to 10MHZ) ,In SPI1 Port i enabled DIR for each (SIMO[0],SOMI[0],CLK  and    (SCS[0] with DOUT (0))    )and then i  generated the code

    i found this SPI Interface Code for reading Gyroscope L3GD20H with  Arduino Uno. 

    #include  // Include Arduino SPI library
    
    #define CTRL1       0x20
    #define OUT_X_L     0x28
    #define OUT_X_H     0x29
    #define OUT_Y_L     0x2A
    #define OUT_Y_H     0x2B
    #define OUT_Z_L     0x2C
    #define OUT_Z_H     0x2D
    
    int8_t readData   = 0x80;
    int8_t writeData  = 0x00;
    int16_t gx, gy, gz;
    
    const int CS = 10;
    
    void setup() {
      Serial.begin(9600);
      SPI.begin();
      pinMode(CS, OUTPUT);
      writeRegister(CTRL1, 0x0F);
      delay(100);
    }
    
    void loop() {
      gx = readRegister(OUT_X_L) <<8 | readRegister(OUT_X_H);
      gy = readRegister(OUT_Y_H) <<8 | readRegister(OUT_Y_L);
      gz = readRegister(OUT_Z_H) <<8 | readRegister(OUT_Z_L);
      Serial.print("Angular Velocity (dps):\t");
      //to convert the raw data to dps, use 8.75 mdps/digit (LSb) for default 250dps
      Serial.print((gx+0), DEC); Serial.print("\t"); //replace +zero with x-axis offset value
      Serial.print((gy+0), DEC); Serial.print("\t"); //replace +zero with y-axis offset value
      Serial.print((gz+0), DEC); Serial.print("\t"); //replace +zero with z-axis offset value
      Serial.println();
      delay(100);
    }
    
    int8_t readRegister(int8_t address) {
      
      int8_t buffer = 0;
      digitalWrite(CS, LOW); 
      SPI.transfer(readData | address);
      buffer = SPI.transfer(writeData);
      Serial.print(address, BIN);
      Serial.print(" : ");
      Serial.println(buffer, BIN);
      digitalWrite(CS, HIGH);
      return(buffer);  
    }
    
    void writeRegister(int8_t address, int8_t val) {
      
      digitalWrite(CS, LOW);
      SPI.transfer(writeData | address);
      SPI.transfer(val);
      digitalWrite(CS, HIGH);
    }

    i read in the datasheet that i have to set CTRL1 register to 0x6F (01101111)

    and t have to use these registers

    OUT_X_L (28h), OUT_X_H (29h)

    OUT_Y_L (2Ah), OUT_Y_H (2Bh)

    OUT_Z_L (2Ch), OUT_Z_H (2Dh)

     

    could you give a hand please

    best regards,

    Ahmad

  • Hello,

    I am closing this thread because you have opened new one with similar question. Please, do not duplicate posts.