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.

LMH0318: difficulty in reading and writing register using SPI

Part Number: LMH0318

Hi Team,

i'm using LMH0318RTWR and controller is ESP32. i'm facing difficulty in writing data and reading data from it's registers

#define LMH_ENABLE 25
#define LMH_MOD_SEL 26

#define LMH_CS 5

#define MISO_PIN 19
#define MOSI_PIN 23
#define READ 0xFF
#define WRITE 0xFE

#define SPI_SETTING SPISettings(20000000, MSBFIRST, SPI_MODE0)
void lmh_read_spi_data(uint8_t registerAddr) {
  uint8_t data1, data2, data3;
  SPI.beginTransaction(SPI_SETTING);
  digitalWrite(LMH_CS, LOW);
  SPI.transfer(READ);
  SPI.transfer(registerAddr);
  SPI.transfer(READ);
  digitalWrite(LMH_CS, HIGH);
  delayMicroseconds(1000);
  digitalWrite(LMH_CS, LOW);
  data1 = SPI.transfer(READ);
  data2 = SPI.transfer(READ);
  data3 = SPI.transfer(READ);
  digitalWrite(LMH_CS, HIGH);

  SPI.endTransaction();

  Serial.print("\nData get from register :: ");
  Serial.print(registerAddr, HEX);
  Serial.print("\n****************");
  Serial.print(data1, HEX);
  Serial.print(" ::  ");
  Serial.print(data2, HEX);
  Serial.print(" ::  ");
  Serial.println(data3, HEX);
}  //end read

void lmh_write_spi_data(uint8_t registerAddr, uint8_t DATA) {
  SPI.beginTransaction(SPI_SETTING);
  digitalWrite(LMH_CS, LOW);
  SPI.transfer(WRITE);
  SPI.transfer(registerAddr);
  SPI.transfer(DATA);
  digitalWrite(LMH_CS, HIGH);
  SPI.endTransaction();
  //delayMicroseconds(1000);
}  //end write
 
 
In reading register i get desired data frame (R/W A7 A6 A5 A4 A3 A2 A1 A0 D7 D6 D5 D4 D3 D2 D1 D0 ) but in place of data (D7 - D0) i am getting 0x00
 

Best Regards,

James Man

Texas Instruments Customer Support

  • Hi James,

    Please refer to the video below discussing how to interface to the device using SPI interface:

    https://www.ti.com/video/5600358649001?keyMatch=

    Regards,Nasser 

  • Hi James,

    The same customer reach out to me and provided the feedback below:
    "I did watch this video, and based on this I made Read and Write Function.
    while reading 0xF0 (Device Version register) I get default data value which is 0x01. But when I try to write data, I am not able to do.
    Data frame which I am sending to write data is [0xFE] [Register Address(A7-A0)] [DATA(D7-D0)]. Please review this frame.
    And, for other registers I am not able to read default value."

    Please help advise. Thank you.

    Best regards,
    Gerald

  • Hi James,

    May I ask for updates? Thank you.

    Best regards,
    Gerald

  • Greetings,

    1). Please make sure we are writing into the appropriate register.

    2). Secondly, it seems you are able to read register but not write register. For write operation, we need to first write the register address we are going to write to. Then we need to in-active or un-assert ssbar# for few microsecond(please refer to the data sheet timing) and then re-assert ssbar# to shift out the register content. 

    3). Also, please put logic analyzer or scope to confirm write timing.

    Regards,Nasser