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

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

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.

0 Likes
11 Replies
ViDv_264506
Level 5
Level 5
50 sign-ins 25 sign-ins 5 solutions authored

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

0 Likes
Anonymous
Not applicable

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.

0 Likes
Anonymous
Not applicable

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 */

0 Likes
Anonymous
Not applicable

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

   

StudentA

0 Likes
ETRO_SSN583
Level 9
Level 9
250 likes received 100 sign-ins 5 likes given

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%20HighS...

   

 

   

Regards, Dana.

0 Likes
Anonymous
Not applicable

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

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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

0 Likes
Anonymous
Not applicable

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

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

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?

0 Likes
Anonymous
Not applicable

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 😉

0 Likes
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Yes, congratulations!

   

 

   

Bob

0 Likes