5 years, 2 months ago.  This question has been closed. Reason: Too broad - no single answer

mbed I2C: Accessing Pressure Sensor usng I2C

Hi,

I'm new to new to mbed and embedded development, and would like to seek some help out here.

I'm trying to read the calibration coefficients from a pressure sensor MS 89bsd using I2C using Nucleo STM32L053.

https://www.digikey.sg/product-detail/en/te-connectivity-measurement-specialties/89BSD-028BA-A/223-1507-5-ND/5277620

I'm using snippets of the code from: https://www.ccsinfo.com/forum/viewtopic.php?t=54676

So far, I do not think I'm gettting the correct values from the PROM, and would appreciate any advice I can get here.

My code snippets for reading the PROM is attached here. I think the problem lies with the PSEN_CMD_PROM(i) function used to access and read the memory (see attached picture). The data types are also attached,

Any ideas/suggestions?

    while(1)
    {      
        if (mybutton == 0)
        {
            pc.printf("Button pressed\n\r");
            PSEN_CMD_RESET(); //Reset the pressure sensor
            
            for(int i = 0; i < 8; i++)
            {
                   C[i] = PSEN_CMD_PROM(i);   //Read in the sensor register map
                   pc.printf("Coefficient C%d: %d\n\r", i, C[i]);
            }
            pc.printf("\n\r");
            Get_Coefficients(C); //Calculate the sensor coefficients 
        }
    }
===================

**************************
/Read the calibration coefficients
signed int PSEN_CMD_PROM(char coef_num)
{
    unsigned int ret;
    unsigned int rC=0;

    i2c.start();
    i2c.write(PSEN_ADDRESS8);
    i2c.write(CMD_PROM_RD+coef_num*2);
    i2c.start();
    i2c.write((PSEN_ADDRESS8) | 1); //Send a read request
    ret = i2c.read(1); //Read with ACK
    rC = 256 * ret;
    ret = i2c.read(0);   //Read with no ACK
    rC = rC + ret;
    i2c.stop();

    return rC;
}

****