• AVR Freaks

Hot!Interface si7021 with Pic24f32ka301 using I2c (by MCC).

Author
Shiv@16
New Member
  • Total Posts : 5
  • Reward points : 0
  • Joined: 2020/01/01 03:42:10
  • Location: 0
  • Status: offline
2020/07/27 05:30:06 (permalink)
0

Interface si7021 with Pic24f32ka301 using I2c (by MCC).

Hi everyone,
 
I am trying to interface si7021 with pic24f32ka301 which is i2c interfaced sensor. So I create a project in mplab and use MCC to create I2c now in next step I don't know how to use its functions, and where to start.
 
I went through the si7021 datasheet and found a sequence where I first have to start I2C, then write a slave address followed by 0xE0 command then read slave address, I do the same steps in programming but I received zero(0) value (seen by uart). Please help me where I am lacking.
 
Thank you.
#1

4 Replies Related Threads

    BobAGI
    Super Member
    • Total Posts : 1731
    • Reward points : 0
    • Joined: 2011/03/09 00:04:35
    • Location: Texas and Sweden
    • Status: offline
    Re: Interface si7021 with Pic24f32ka301 using I2c (by MCC). 2020/07/27 09:00:13 (permalink)
    4.5 (2)
    You should be familiar with the way I2C works before you start programming an interface...
    The UART is not involved for instance.
    I have contributed to an earlier post with my take on implementing I2C for communicating with an EEPROM device using only 2 GPIO pins and some very simple code.
    You may want to start reading here.
    In principle the code I used is a bit-bang type of solution and it is very simple to use. It can be used with ANY microcontroller, it does not have to have an I2C sub-system built in at all and you can thus connect to many I2C buses without problem.
    Talking to a temp/humid sensor seems like a very simple task...

    --
    Bo B
    Sweden & Texas
     
    #2
    Shiv@16
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2020/01/01 03:42:10
    • Location: 0
    • Status: offline
    Re: Interface si7021 with Pic24f32ka301 using I2c (by MCC). 2020/07/28 00:37:51 (permalink)
    0
    Thank you for your quick reply and advice.
    I know the basics of the I2C but problem is that I m not be able to get value here is my code if any advice please let me know.
     
    int main(void)
    {
        uint16_t tempValueC =0;
        SYSTEM_Initialize();
        while(1)
        {
           I2C1_MasterWrite(&si7021_cmd,1,0x40,&I2C_status);
           while (I2C1_MESSAGE_PENDING  == I2C_status);
           I2C1_MasterWrite(&si7021_cmd,1,0xF3,&I2C_status);
           while (I2C1_MESSAGE_PENDING  == I2C_status);
           I2C1_MasterRead( &readValue, 1, 0x40, &I2C_status);
           while (I2C1_MESSAGE_PENDING  == I2C_status );
           tempValueC = readValue;
           printf("\nTemp value is:%u",tempValueC);
           Delay_ms(1000);
        }
        return -1;
    }
    #3
    BobAGI
    Super Member
    • Total Posts : 1731
    • Reward points : 0
    • Joined: 2011/03/09 00:04:35
    • Location: Texas and Sweden
    • Status: offline
    Re: Interface si7021 with Pic24f32ka301 using I2c (by MCC). 2020/07/28 03:36:05 (permalink)
    5 (1)
    I have not used these MCP library functions and also not used the I2C subsystem on the PIC because of the problems reported at the time.
    That is why I used the bit-bang approach outlined in my linked pages.
    So I cannot help if you use the library functions...
     

    --
    Bo B
    Sweden & Texas
     
    #4
    Shiv@16
    New Member
    • Total Posts : 5
    • Reward points : 0
    • Joined: 2020/01/01 03:42:10
    • Location: 0
    • Status: offline
    Re: Interface si7021 with Pic24f32ka301 using I2c (by MCC). 2020/07/28 21:42:48 (permalink)
    5 (1)
    ok thank you so much I will try bit-bang method.
     
    #5
    Jump to:
    © 2020 APG vNext Commercial Version 4.5