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.

Problem: communication between LMP92064 and Raspberry Pi

Other Parts Discussed in Thread: LMP92064

Hi,


I want to use the LMP92064 to observe the Current und Voltage of my system. To analyse the situation i will use a Raspberry Pi but my problem is that i can't communicate with die LMP92064.


Is it possible that someone can show me an example code of the communication in C oder C++?

Thx

  • Hi Micha,

    The LMP92064 has a 4-wire SPI interface: CSB (active-low chip-select), SDI (data input), SDO (data output) and SCLK (SPI clock input). If the Raspberry Pi has a similar SPI port on-board that you can use, then the communication should be possible. Your best bet is to search for C/C++ examples of generic SPI communication on the Raspberry Pi, and check for compatibility with the SPI protocol described in the LMP92064 datasheet. In general, a simple SPI frame for the LMP92064 consists of 16-bits: 1-bit command, 7-bit address, and 8-bit data. Unfortunately, there are no source-code examples available in the LMP92064 product or EVM page.

    Regards,
    Sergio
  • Thx for your answer

    if i send 0x80 0x00
    or ox80 0x80
    the reply is every time
    0xFF 0xFF

    But it shoud be 0x18 or not?

  • Oh, sorry, the command+address is 16-bit long on this device. You'll need to send 0x80 0x00 0x00 and the device should output data on the SDO pin along with the last 8 clock cycles of send instruction. It's important that the CSB line remains low and is not toggling in-between bytes.

    The reply from register 0x0000 should be 0x18.
  • Whith spi mode does the LMP support? 

    Enumerator
    BCM2835_SPI_MODE0 

    CPOL = 0, CPHA = 0.

    BCM2835_SPI_MODE1 

    CPOL = 0, CPHA = 1.

    BCM2835_SPI_MODE2 

    CPOL = 1, CPHA = 0.

    BCM2835_SPI_MODE3 

    CPOL = 1, CPHA = 1.

    I tryed to send 0x00, 0x00, 0x00 and 0x80, 0x00, 0x00

    but all the time the reply is in every buffer 0xFF 

    The CSB is low as long as the comunication is running.

    it is not necessary to measure something, or?

    That's the code i use

    // Example program for bcm2835 library

    // Shows how to interface with SPI to transfer a number of bytes to and from an SPI device
    //

    #include <bcm2835.h>
    #include <stdio.h>

    int main(int argc, char **argv)
    {
    // If you call this, it will not actually access the GPIO
    // Use for testing
    // bcm2835_set_debug(1);

    if (!bcm2835_init())
    return 1;

    bcm2835_spi_begin();
    bcm2835_spi_setBitOrder(BCM2835_SPI_BIT_ORDER_MSBFIRST); // The default
    bcm2835_spi_setDataMode(BCM2835_SPI_MODE0); // The default
    bcm2835_spi_setClockDivider(BCM2835_SPI_CLOCK_DIVIDER_65536); // abount 3.8 kHz
    bcm2835_spi_chipSelect(BCM2835_SPI_CS0); // The default
    bcm2835_spi_setChipSelectPolarity(BCM2835_SPI_CS0, LOW); // the default

    // Send a some bytes to the slave and simultaneously read
    // some bytes back from the slave
    // Most SPI devices expect one or 2 bytes of command, after which they will send back
    // some data. In such a case you will have the command bytes first in the buffer,
    // followed by as many 0 bytes as you expect returned data bytes. After the transfer, you
    // Can the read the reply bytes from the buffer.
    // If you tie MISO to MOSI, you should read back what was sent.

    char buf[] = { 0x00, 0x00, 0x00}; // Data to send


    printf("Read befor send over SPI: %#X %#X %#X \n", buf[0], buf[1], buf[2]);// Data to send

    bcm2835_spi_transfern(buf, sizeof(buf));
    // buf will now be filled with the data that was read from the slave
    printf("Read from SPI: %#X %#X %#X \n", buf[0], buf[1], buf[2]);

    bcm2835_spi_end();
    bcm2835_close();
    return 0;
    }

  • Hi Micha,

    The LMP92064 reads data from MOSI on the rising edge of the clock, and writes data to MISO on the falling edge of the clock.

    I think this could correspond to MODE3, where the data is clocked in on rising, edge output data (change) on falling edge. This way the MASTER outputs data on the falling edge and the SLAVE reads the data in the next rising edge. When the SLAVE clocks out data on the falling edge, the MASTER clocks in data on the next rising edge.

    Do you have an oscilloscope at hand to monitor the SPI bus?

    Thanks,

    Sergio