11 Replies Latest reply on Oct 13, 2015 2:19 AM by user_1377889

    I2C communication with AD5933, how to interpret my received data?

    alexander.bromm

      Hi community,

         

      I am trying to get a connection between my PSoC 5LP and an external device (AD5933) to measure the impedance via the AD5933. At the beginning I am trying to measure the temperature via the AD5933 for testing purposes.

         

      At the moment I think i managed the get some communication, but I am not sure if my received data are the data I wanted to get from my AD5933. I adressed the device and adressed the internal register to please measure the temperature. Then the UART should show me the received data. But now I just geting "27" as output data. Might it be a problem of the size of the data? I think with my code I am just able to transport 8 bits but the AD5933 datasheet says the temperature data are 14 bits.

         

      Maybe my code is wrong, it is my first time to handle with I2C communication.

         

      I hope some of you have some useful tips for me. Thank you in advance.

        • 1. Re: I2C communication with AD5933, how to interpret my received data?
          user_44074550

          Hi StudentA,

             

          for understanding your problem it will be better to see the source code. Are you communicating with AD5933 using the bit/bang or with dedicated HW?

             

          Viktor

          • 2. Re: I2C communication with AD5933, how to interpret my received data?
            alexander.bromm

            Hi Viktor,

               

            my code is attached to my first post. To be honest I am a beginner and just tried to hold on to the datasheet of the I2C and the AD5933.

            • 3. Re: I2C communication with AD5933, how to interpret my received data?
              alexander.bromm

              Maybe it is better in this form for you:

                 

              /* ========================================
               *
               * Copyright YOUR COMPANY, THE YEAR
               * All Rights Reserved
               * UNPUBLISHED, LICENSED SOFTWARE.
               *
               * CONFIDENTIAL AND PROPRIETARY INFORMATION
               * WHICH IS THE PROPERTY OF your company.
               *
               * ========================================
              */
              #include <project.h>
              #include "stdio.h"

                 

              #define I2C_SLAVE_ADDR  (0x0Du)

                 

              #define TRANSMIT_BUFFER_SIZE  80
              uint8 temp=0;

                 

              char TransmitBuffer[TRANSMIT_BUFFER_SIZE];

                 

              int main()
              {
                  CyGlobalIntEnable; /* Enable global interrupts. */
                  uint16  buffer[BUFFER_SIZE];
                  
                  UART_1_Start();
                      
                  I2C_Start();                             //starting I2C
                  I2C_MasterSendStart(I2C_SLAVE_ADDR,0);   //adressing the AD5933 device with 0 for writing    
                  
                  I2C_MasterSendStart(0x80u,0);        //adressing the internal control register
                  I2C_MasterSendStart(0x90u,0);         //sending the command to measure the temperature (all adresses are from the datasheet)
                  I2C_MasterSendStop();            //stop sequence for the writing process
                  
                  
                  I2C_MasterSendStart(I2C_SLAVE_ADDR,1);     //adressing the AD5933 device with 1 for reading
                  I2C_MasterSendStart(0x92u,1);        //adressing the internal register where the temp. data are stored, with 1 for reading
                  temp = I2C_MasterReadByte(I2C_NAK_DATA);    //reading the temp. data with an NAK bit to complete the process
                  I2C_MasterSendStop();
                  
                  UART_1_PutString("COM Port Open");            
                  sprintf(TransmitBuffer, "S1: %d ", temp);        
                  UART_1_PutString(TransmitBuffer);        //showing the output data
                  
                  /* Place your initialization/startup code here (e.g. MyInst_Start()) */

                 

                  for(;;)
                  {
                      /* Place your application code here. */
                  }
              }

                 

              /* [] END OF FILE */

              • 4. Re: I2C communication with AD5933, how to interpret my received data?
                alexander.bromm

                Has anyone maybe some code examples for I2C communication with an external device like AD5933? That would help me a lot!

                   

                StudentA

                • 5. Re: I2C communication with AD5933, how to interpret my received data?
                  user_14586677

                  Here is an impedance meter project done a couple of years ago.

                     

                   

                     

                  Might be of interest.

                     

                   

                     

                  https://www.dropbox.com/s/6s7c58fbartcakd/Phoenix%20Impedance%20meter%20project%20and%20info%20HighSpeed%20-%20Copy.zip?dl=0

                     

                   

                     

                  Regards, Dana.

                  • 6. Re: I2C communication with AD5933, how to interpret my received data?
                    user_1377889

                    Your code is wrong, indeed.

                       

                    An I2C transaction has usually the form

                       

                    MasterSendStart() // Begin of transaction

                       

                    MasterWriteByte() // Set command or set slave Register to read

                       

                    MasterSendRestart // when you want to read from slave

                       

                    MasterReadByte(ACK) // When reading more than one byte

                       

                    .

                       

                    .

                       

                    MasterReadByte(NAK) // Last byte to read

                       

                    MasterSendStop() // End the transaction.

                       

                    Keep in mind that all functions return a value which is (except for MasterReadByte) a status indicating success or failure.

                       

                     

                       

                    Bob

                    • 7. Re: I2C communication with AD5933, how to interpret my received data?
                      alexander.bromm

                      Thanks for your answer, but I already know this project, but it did´nt help me.

                      • 8. Re: I2C communication with AD5933, how to interpret my received data?
                        alexander.bromm

                        Hello Bob,

                           

                        thanks for your reply. Am I right with the following assumptions?
                        With "MasterSendStart()" i send the slave adress and the write bit 0.
                        Then I need to adress an internal register of the slave, in this case the control register 0x80. Therefore I use the "MasterWriteByte()".

                           

                        Now do I then send the command 0x90 for measuring the the temperature also with  "MasterWriteByte()" directly after adressing the internal register?

                           

                        And how do I have to understand "MasterReadByte(ACK)"?  Do I have to really send an ACK bit manually?
                         

                           

                        PS: I read in the forum that you studied in Jülich, so greetings from Jülich, I am studying there right now.

                           

                        Regards, Alexander

                        • 9. Re: I2C communication with AD5933, how to interpret my received data?
                          user_1377889

                          I am not familiar with your slave device, so you will have to check for the needed sequence control/register.

                             

                          Do NOT use a "0" (zero) for the write bit in MasterSendStart(), there is a #define for that bit, dig in the .h-files, better readable what you do. I recently had a similar problem with someone who switched the values.

                             

                          Look at the MasterReadByte() API, There is a parameter for sending an ACK or NAK, also #defined.

                             

                          Make use of the returned status

                             

                           

                             

                          Bob

                             

                          Greetings to the Zitadelle Does the "Saftladen" still exist?

                          • 10. Re: I2C communication with AD5933, how to interpret my received data?
                            alexander.bromm

                            I got it running, using the following code.

                               

                            #include <project.h>
                            #include "stdio.h"

                               

                            #define TRANSMIT_BUFFER_SIZE  80

                               

                            char TransmitBuffer[TRANSMIT_BUFFER_SIZE];
                            uint8 temp=0;

                               

                            int main()
                            {
                                CyGlobalIntEnable; /* Enable global interrupts. */

                               

                                /* Place your initialization/startup code here (e.g. MyInst_Start()) */
                                UART_1_Start();
                                UART_1_PutString("\n COM Port Open");
                                sprintf(TransmitBuffer, "S1: %d ", temp);
                                UART_1_PutString(TransmitBuffer);
                                
                                I2C_Start();
                                
                               I2C_MasterSendStart(0x0Du,I2C_WRITE_XFER_MODE);
                               I2C_MasterWriteByte(0x80);

                               

                               I2C_MasterWriteByte(0x90);
                               I2C_MasterSendStop();
                               if(!(I2C_MasterStatus() & I2C_MSTAT_XFER_INP))
                                {
                                       

                               

                                    I2C_MasterClearStatus();
                                    I2C_MasterSendStart(0x0Du,I2C_WRITE_XFER_MODE);
                                    I2C_MasterWriteByte(0x93u);
                                    
                                    I2C_MasterSendRestart(0x0Du,I2C_READ_XFER_MODE);
                                    temp=I2C_MasterReadByte(I2C_NAK_DATA);
                                    I2C_MasterSendStop();
                                    sprintf(TransmitBuffer,"Temp: %d ", temp);
                                    UART_1_PutString(TransmitBuffer);
                                }
                                
                                
                                
                                for(;;)
                                {
                                    /* Place your application code here. */
                                }
                            }

                               

                            I must admit, that I ve never heard of the "Saftladen". My favourite spot in town is the pub ;)

                            • 11. Re: I2C communication with AD5933, how to interpret my received data?
                              user_1377889

                              Yes, congratulations!

                                 

                               

                                 

                              Bob