13 Replies Latest reply on May 2, 2018 4:39 AM by arh

    RTC DS1307 0xD0 address issue (using i2c)

    bob.shankle

      Hi All,

       

      I'm using the I2C master (Fixed Function, V3.5) and trying to communicate with a DS1307 Real Time Clock.

       

      When I put the SCL and SDA lines on a scope / digital analyser it is showing the address as 0x50 instead of 0xD0 needed for the RTC.  (It looks like it is dropping the first bit of the write command.

       

      I'm using the CY8CKIT-059 PSoC 5LP prototyping kit.   (Using 12_0 for SCL and  12_1 for SDA.)

       

      My code is basically:

       

      #define I2C_SLAVE_ADDR  (0xd0u)

      /* Delay between commands in milliseconds */

      #define CMD_TO_CMD_DELAY  (500u)

       

      void main(void)

      {

          I2C_Start();

          CyGlobalIntEnable;

          for(;;)

          {

              ReadStatusPacket();

              CyDelay(CMD_TO_CMD_DELAY); /* Delay between commands */

          }

      }

       

      uint32 WriteCommandPacket(uint8 cmd)

      {

          uint8  buffer[BUFFER_SIZE];

          uint32 status = TRANSFER_ERROR;

       

          buffer[0] = cmd;

       

          (void) I2C_MasterWriteBuf(I2C_SLAVE_ADDR, buffer, 1, I2C_MODE_COMPLETE_XFER);

       

          /* Waits until master completes write transfer */

          while (0u == (I2C_MasterStatus() & I2C_MSTAT_WR_CMPLT))

          {

          }

       

          /* Displays transfer status */

          if (0u == (I2C_MSTAT_ERR_XFER & I2C_MasterStatus()))

          {

              /* Check if all bytes was written */

              if (I2C_MasterGetWriteBufSize() == 1)

              {

                  status = TRANSFER_CMPLT;

              }

          }

          else

          {

              status = TRANSFER_ERROR;

          }

       

          (void) I2C_MasterClearStatus();

          return (status);

      }

       

      uint32 ReadStatusPacket(void)

      {

          uint8  buffer[BUFFER_SIZE];

          uint8 my_cmd[2];

          uint8 datacount =0;

          uint32 status = TRANSFER_ERROR;

         

          my_cmd[0] = 0xd0;

          my_cmd[1] = 0xff;

         

         (void) I2C_MasterWriteBuf(I2C_SLAVE_ADDR, my_cmd, 1, I2C_MODE_COMPLETE_XFER); // should set address/reg to read.

       

          // Waits until master completes write transfer

          while (0u == (I2C_MasterStatus() & I2C_MSTAT_WR_CMPLT))

          {

          }

          // Displays transfer status

          if (0u == (I2C_MSTAT_ERR_XFER & I2C_MasterStatus()))

          {

              // Check if all bytes was written

              datacount = I2C_MasterGetWriteBufSize(); // how many bytes went out?

          }

          else

          {

              status = -1;  // there was an error

          }

       

          (void) I2C_MasterReadBuf(I2C_SLAVE_ADDR, buffer, 6, I2C_MODE_COMPLETE_XFER );

       

          /* Waits until master complete read transfer */

          while (0u == (I2C_MasterStatus() & I2C_MSTAT_RD_CMPLT))

          {

          }

       

          /* Displays transfer status */

          if (0u == (I2C_MSTAT_ERR_XFER & I2C_MasterStatus()))

          {

              status = TRANSFER_CMPLT;

          }

          else

          {

              status = TRANSFER_ERROR;

          }

       

          (void) I2C_MasterClearStatus();

       

          return (status);

      }

       

      =======================================================

      thanks for any suggestions,

      Bob

       

      below is what I'm seeing on the scope.

      scope.png