The freescale MPL115A1 Pressure and Temperature Sensor can not read the sensor data.

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

The freescale MPL115A1 Pressure and Temperature Sensor can not read the sensor data.

907 Views
erdi_
Contributor I

We used in the project F28M35X microprocessor.The data from the sensors to communicate via the line SPI (four wire communication).

Only 4-pin sensor connected to the microprocessor.CS pin, DIN pin, DOUT pin, SCLK pin.In our project we use the four  functions generally in .c file system.

The project is .h (header file) system in  define sensor address.

In .c file system;

For example;

sensor_read();

sensor_start();

sensor_write();

sensor_stop();

this like  define functions.

I didn't  sensor data read.How can help me in sensor data reading?

Thank you.

Labels (2)
0 Kudos
4 Replies

482 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Erdi,

It is hard to say where the problem might be without knowing more details (schematic, source code, graphic/screen shot from an oscilloscope or a logic analyzer showing all DIN, DOUT, SCLK, CS lines).

I would recommend taking a closer look at the MPL115A1 data sheet or AN3785 describing the SPI protocol, commands and pressure calculation in detail.

In short, to start a pressure and temperature conversion, you need to use the following sequence:

[CS=0], [0x24], [0x00], [CS=1], [3 ms delay]

So you should drive CS low, then send 0x24 followed by 0x00 and then drive CS high. Then wait ~3ms before reading the data using this sequence:

[CS=0], [0x80], [0x00], [0x82], [0x00], [0x84], [0x00,] [0x86], [0x00], [0x00], [CS=1]

Basically, where the “0x00” values appear in the sequence above, you should receive the following values:

1. Pressure MSB

2. Pressure LSB

3. Temperature MSB

4. Temperature LSB

Make sure the base value of the SCLK signal is zero, data are read (write) on a rising edge and data are changed on a falling edge (Mode 0 SPI protocol).

I hope it helps.

Regards,

Tomas

PS: If my answer helps to solve your question, please mark it as "Correct". Thank you.

0 Kudos

482 Views
erdi_
Contributor I

First of all,Thank you for answer the question.But I read twice mpl115a1 datasheet and  AN3785 .Although I have not read any data to send to the address above.I do not understand parts how do we use the coefficient reading and writing.Below are particular of code.

The header file system;

#ifndef MPL115A1_H_

#define MPL115A1_H_

/* Sensor adres tanımlamaları yapılıyor */

#define BASINC_MASK_ADRES             0x0000

/* Sensör yazma adresleri tanımlanıyor. */

#define MPL115A1_BASINC_MSB           0x00 /* 10 bit basınç adc çıkışı */

#define MPL115A1_BASINC_LSB           0x02

#define MPL115A1_SICAKLIK_MSB         0x04 /* 10 bit sıcaklık adc çıkışı */

#define MPL115A1_SICAKLIK_LSB         0x06

#define A0_KATSAYI_MSB                0x08 /* Basınç offset katsayısı */

#define A0_KATSAYI_LSB                0x0A

#define B1_KATSAYI_MSB                0x0C /* Basınç duyarlılık katsayısı */

#define B1_KATSAYI_LSB                0x0E

#define B2_KATSAYI_MSB                0x10 /* Sıcaklık offset katsayısı */

#define B2_KATSAYI_LSB                0x12

#define C12_KATSAYI_MSB               0x14 /* Sıcaklık duyarlılık katsayısı */

#define C12_KATSAYI_LSB               0x16

#define SPI_BASLA_DONUSTUR            0x24 /* Sıcaklık ve Basınç dönüştürme yazma adresi */

/* Sensör okuma katsayı verisi tanımlanıyor */

#define MPL115A1_BASINC_MSB_VERI       0x80  //Basınç verisinin msb byte - 8 bit boyutunda msb verisi

#define MPL115A1_BASINC_LSB_VERI       0x82  //Basınç verisinin lsb byte - 2 bit boyutunda lsb verisi

#define MPL115A1_SICAKLIK_MSB_VERI     0x84  //Sıcaklık verisinin msb byte

#define MPL115A1_SICAKLIK_LSB_VERI     0x86  //Sıcaklık verisinin lsb byte

#define A0_KATSAYI_MSB_VERI            0x88  //A0 basınç offset katsayısı msb

#define A0_KATSAYI_LSB_VERI            0x8A  //A0 basınç offset katsayısı lsb

#define B1_KATSAYI_MSB_VERI            0x8C  //B1 basınç duyarlılık katsayısı msb

#define B1_KATSAYI_LSB_VERI            0X8E  //B1 basınç duyarlılık katsayısı lsb

#define B2_KATSAYI_MSB_VERI            0x90  //B2 sıcaklık offset katsayısı msb

#define B2_KATSAYI_LSB_VERI            0x92  //B2 sıcaklık offset katsayısı lsb

#define C12_KATSAYI_MSB_VERI           0x94  //C12 sıcaklık duyarlılık katsayısı msb

#define C12_KATSAYI_LSB_VERI           0x96  //C12 sıcaklık duyarlılık katsayısı lsb

extern void mpl115a1_basla();

extern void mpl115a1_durdur();

extern void mpl115a1_sifirla();

extern Uint16 mpl115a1_oku();

#endif /* MPL115A1_H_ */

The .c file system ;

void mpl115a1_basla();

void mpl115a1_durdur();

void mpl115a1_sifirla();

Uint16 mpl115a1_oku();

/*Katsayılar int tipinde olabilir */

Uint16 a0_veri;

Uint16 a0_katsayi_msb;

Uint16 a0_katsayi_lsb;

Uint16 b1_veri;

Uint16 b1_katsayi_msb;

Uint16 b1_katsayi_lsb;

Uint16 b2_veri;

Uint16 b2_katsayi_msb;

Uint16 b2_katsayi_lsb;

Uint16 c12_veri;

Uint16 c12_katsayi_msb;

Uint16 c12_katsayi_lsb;

Uint16 Padc_veri;

Uint16 Padc_lsb_veri;

Uint16 Padc_msb_veri;

Uint16 Tadc_veri;

Uint16 Tadc_lsb_veri;

Uint16 Tadc_msb_veri;

void mpl115a1_basla()

{

}

void mpl115a1_durdur()

{

}

void mpl115a1_sifirla()

{

}

Uint16 mpl115a1_oku()

{

    int i;

    //spi_sifirla();

    demux_yaz(BASINC_CS);

    spi_yaz(SPI_BASLA_DONUSTUR);

    spi_yaz(BASINC_MASK_ADRES);

    demux_yaz(NEM_CS);

       for(i = 0; i < 40; i++){}

       spi_sifirla();

       demux_yaz(BASINC_CS);

    //spi_yaz(MPL115A1_BASINC_MSB_VERI | BASINC_MASK_ADRES);

    spi_yaz(MPL115A1_BASINC_MSB_VERI);

    Padc_msb_veri = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    Padc_msb_veri = spi_oku();

    spi_sifirla();

    //spi_yaz(MPL115A1_BASINC_LSB_VERI | BASINC_MASK_ADRES);

    spi_yaz(MPL115A1_BASINC_LSB_VERI);

    Padc_lsb_veri = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    Padc_lsb_veri = spi_oku();

    spi_sifirla();

    //spi_yaz(MPL115A1_SICAKLIK_MSB_VERI | BASINC_MASK_ADRES);

    spi_yaz(MPL115A1_SICAKLIK_MSB_VERI);

    Tadc_msb_veri = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    Tadc_msb_veri = spi_oku();

    spi_sifirla();

    //spi_yaz(MPL115A1_SICAKLIK_LSB_VERI | BASINC_MASK_ADRES | BASINC_MASK_ADRES);

    spi_yaz(MPL115A1_SICAKLIK_LSB_VERI);

    Tadc_lsb_veri = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    spi_yaz(BASINC_MASK_ADRES);

    Tadc_lsb_veri = spi_oku();

       spi_sifirla();

    demux_yaz(NEM_CS);

    return Padc_msb_veri;

   /* spi_yaz(A0_KATSAYI_MSB_VERI);

    a0_katsayi_msb = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    a0_katsayi_msb = spi_oku();

    //for(i=0; i < 50; i++){}

    spi_sifirla();

    spi_yaz(A0_KATSAYI_LSB_VERI);

    a0_katsayi_lsb = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    a0_katsayi_lsb = spi_oku();

    spi_sifirla();

    //for(i=0; i < 50; i++){}

    spi_yaz(B1_KATSAYI_MSB_VERI);

    b1_katsayi_msb = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    b1_katsayi_msb = spi_oku();

    spi_sifirla();

    //for(i=0; i < 50; i++){}

    spi_yaz(B1_KATSAYI_LSB_VERI);

    b1_katsayi_lsb = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    b1_katsayi_lsb = spi_oku();

    spi_sifirla();

    //for(i=0; i < 50; i++){}

    spi_yaz(B2_KATSAYI_MSB_VERI);

    b2_katsayi_msb = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    b2_katsayi_msb = spi_oku();

    spi_sifirla();

    //for(i=0; i < 50; i++){}

    spi_yaz(B2_KATSAYI_LSB_VERI);

    b2_katsayi_lsb = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    b2_katsayi_msb = spi_oku();

    spi_sifirla();

    //for(i=0; i < 50; i++){}

    spi_yaz(C12_KATSAYI_MSB_VERI);

    c12_katsayi_msb = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    c12_katsayi_msb = spi_oku();

    spi_sifirla();

    //for(i=0; i < 50; i++){}

    spi_yaz(C12_KATSAYI_LSB_VERI);

    c12_katsayi_lsb = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    c12_katsayi_lsb = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    c12_katsayi_lsb = spi_oku();

    demux_yaz(NEM_CS);

    spi_sifirla();

    //for(i=0; i < 50; i++){}

    demux_yaz(BASINC_CS);

    spi_yaz(SPI_BASLA_DONUSTUR);

    spi_yaz(BASINC_MASK_ADRES);

    demux_yaz(NEM_CS);

    for(i=0; i < 50; i++){}  //3 ms gecikme

    spi_sifirla();

    demux_yaz(BASINC_CS);

    spi_yaz(MPL115A1_BASINC_MSB_VERI);

    Padc_msb_veri = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    Padc_msb_veri = spi_oku();

    spi_sifirla();

    //for(i=0; i < 50; i++){}

    spi_yaz(MPL115A1_BASINC_LSB_VERI);

    Padc_lsb_veri = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    Padc_lsb_veri = spi_oku();

    spi_sifirla();

    //for(i=0; i < 50; i++){}

    spi_yaz(MPL115A1_SICAKLIK_MSB_VERI);

    Tadc_msb_veri = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    Tadc_msb_veri = spi_oku();

    spi_sifirla();

    //for(i=0; i < 50; i++){}

    spi_yaz(MPL115A1_SICAKLIK_LSB_VERI);

    Tadc_lsb_veri = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    Tadc_lsb_veri = spi_oku();

    spi_yaz(BASINC_MASK_ADRES);

    Tadc_lsb_veri = spi_oku();

    demux_yaz(NEM_CS);

    spi_sifirla();

    return a0_katsayi_msb;*/

  /* Birinci kısım */

   /*  spi_yaz(A0_KATSAYI_MSB_VERI | BASINC_MASK_ADRES);

     for(i = 0; i < 10; i++) {}

    a0_katsayi_msb = spi_oku();

  spi_yaz(A0_KATSAYI_LSB_VERI | BASINC_MASK_ADRES);

  for(i = 0; i < 10; i++) {}

  a0_katsayi_lsb = spi_oku();

  spi_yaz(B1_KATSAYI_MSB_VERI | BASINC_MASK_ADRES);

  for(i = 0; i < 10; i++) {}

  b1_katsayi_msb = spi_oku();

  spi_yaz(B1_KATSAYI_LSB_VERI | BASINC_MASK_ADRES);

  for(i = 0; i < 10; i++) {}

  b1_katsayi_lsb = spi_oku();

  spi_yaz(B2_KATSAYI_MSB_VERI | BASINC_MASK_ADRES);

  for(i = 0; i < 10; i++) {}

  b2_katsayi_msb = spi_oku();

  spi_yaz(B2_KATSAYI_LSB_VERI | BASINC_MASK_ADRES);

  for(i = 0; i < 10; i++) {}

  b2_katsayi_lsb = spi_oku();

  spi_yaz(C12_KATSAYI_MSB_VERI | BASINC_MASK_ADRES);

  for(i = 0; i < 10; i++) {}

  c12_katsayi_msb = spi_oku();

  spi_yaz(C12_KATSAYI_LSB_VERI | BASINC_MASK_ADRES | BASINC_MASK_ADRES);

  for(i = 0; i < 10; i++) {}

  c12_katsayi_lsb = spi_oku();

  demux_yaz(NEM_CS);

  for(i = 0; i < 10; i++) {}

  spi_sifirla();

  for(i = 0; i < 10; i++) {}

  demux_yaz(BASINC_CS);

  spi_yaz(SPI_BASLA_DONUSTUR | BASINC_MASK_ADRES);

  for(i = 0; i < 100; i++) {}

  demux_yaz(NEM_CS);

  for(i = 0; i < 10; i++) {}

  spi_sifirla();

  for(i = 0; i < 10; i++) {}

  demux_yaz(BASINC_CS);

  spi_yaz(MPL115A1_BASINC_MSB_VERI | BASINC_MASK_ADRES);

  for(i = 0; i < 10; i++) {}

  Padc_msb_veri = spi_oku();

  spi_yaz(MPL115A1_BASINC_LSB_VERI | BASINC_MASK_ADRES);

  for(i = 0; i < 10; i++) {}

  Padc_lsb_veri = spi_oku();

  spi_yaz(MPL115A1_SICAKLIK_MSB_VERI | BASINC_MASK_ADRES);

  for(i = 0; i < 10; i++) {}

  Tadc_msb_veri = spi_oku();

  spi_yaz(MPL115A1_SICAKLIK_LSB_VERI | BASINC_MASK_ADRES | BASINC_MASK_ADRES);

  for(i = 0; i < 10; i++) {}

  Tadc_lsb_veri = spi_oku();

  demux_yaz(NEM_CS);

  return Padc_lsb_veri;*/

The spi_sifirla(); function is spi reset,

demux_yaz(BASINC_CS) function is ChipSelect is low;

demux_yaz(NEM_CS) function is ChipSelect is HIGH.

spi_oku() function is spi read.

spi_yaz(address) function is spi write.

0 Kudos

482 Views
TomasVaverka
NXP TechSupport
NXP TechSupport

Hi Erdi,

Please find below my example code that illustrates how to read the coefficients, execute both pressure and temperature conversions, read raw pressure and temperature data and finally calculate the pressure.

If you cannot read the coefficients, please send me your schematic and a screen shot from an oscilloscope or a logic analyzer to find out possible problems. Also make sure the SHDN pin is high, otherwise the device is disabled.

uint8_t PressureADC_High, PressureADC_Low, Temperature_High, Temperature_Low;

uint8_t A0_High, A0_Low, B1_High, B1_Low, B2_High, B2_Low, C12_High, C12_Low;

uint16_t Tadc, Padc;

int16_t A0, B1, B2, C12;

float c12x2, a1, a1x1, y1, a2x2, Pcomp, Pfinal, Temp;

int main (void)

{

    Pause(0x277E); // Wait ~5ms as recommended in the data sheet

    // Read coefficients

    GPIOD_PCOR |= 1; // CS low

    // a0 coefficient

    SPIWriteByte(0x88);

    A0_High=SPIReadByte();

    SPIWriteByte(0x8A);

    A0_Low=SPIReadByte();

    // b1 coefficient

    SPIWriteByte(0x8C);

    B1_High=SPIReadByte();

    SPIWriteByte(0x8E);

    B1_Low=SPIReadByte();

    // b2 coefficient

    SPIWriteByte(0x90);

    B2_High=SPIReadByte();

    SPIWriteByte(0x92);

    B2_Low=SPIReadByte();

    // c12 coefficient

    SPIWriteByte(0x94);

    C12_High=SPIReadByte();

    SPIWriteByte(0x96);

    C12_Low=SPIReadByte();

    GPIOD_PSOR |= 1; // CS high

    A0 = (int16_t) (A0_High<<8 | A0_Low);

    B1 = (int16_t) (B1_High<<8 | B1_Low);

    B2 = (int16_t) (B2_High<<8 | B2_Low);

    C12 = ((int16_t) (C12_High<<8 | C12_Low)) >> 2;

    while (1)

    {

            // Start Conversion

            GPIOD_PCOR |= 1; // CS low

            SPIWriteByte(0x24);

            SPIWriteByte(0x00);

            GPIOD_PSOR |= 1; // CS high

            Pause(0x17B2); // Wait ~3ms

            // Read raw pressure and temperature

            GPIOD_PCOR |= 1; // CS low

            SPIWriteByte(0x80);

            PressureADC_High=SPIReadByte();

            SPIWriteByte(0x82);

            PressureADC_Low=SPIReadByte();

            SPIWriteByte(0x84);

            Temperature_High=SPIReadByte();

            SPIWriteByte(0x86);

            Temperature_Low=SPIReadByte();

            GPIOD_PSOR |= 1; // CS high

            // Pressure calculation

            Tadc = ((uint16_t) (Temperature_High<<8 | Temperature_Low)) >> 6;

            Padc = ((uint16_t) (PressureADC_High<<8 | PressureADC_Low)) >> 6;

            c12x2 = (((float) C12) / 4194304) * Tadc;

            a1 = (((float) B1) / 8192) + c12x2;

            a1x1 = a1 * Padc;

            y1 = (((float) A0) / 8) + a1x1;

            a2x2 = (((float) B2) / 16384) * Tadc;

            Pcomp = y1 + a2x2;

            Pfinal = (Pcomp * 65 / 1023) + 50;

    }

}

Hope it helps.

Regards,

Tomas

0 Kudos

482 Views
erdi_
Contributor I

Hi Tomas;

You are the share above code is use to  my project is a not open.I don't understand is read data of sensor.The SHDN pin is not connected Gnd my project.The pcb card is SHDN is connected GND, but also not start is read data coefficient and Padc.Which try to up the code is microprocessor?

0 Kudos