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.
HeGi_2497906
Level 5
Level 5
100 replies posted 50 replies posted 25 replies posted

I am stumped, I cannot get past the first I2C transaction, no matter what I do or try, using the discrete commands and the buf commands has the same effect to two different peripherals.

I do the first read or write, and after that the I2C ceases to function, no error, nothing!  I am really confused and frustrated, been on this for two days, read every post, and the DS back and front.

Front the scope shot below, you can see the write and acks for the device address 0xA0 and register address 0x00, 0x01, writing 0x01 to that location.  The I try to load the address for the read and it fails to write the selected locations, all you see is the start and device address, but it should send the two byte register address, but does not.  in the next instruction, the read, if I do not put a MODE_REPEAT_START (you can see the back to back start and device address in the scope plot), you get nothing, no read at all, just flat lines high.

I also have an LIS3DH accelerometer and get the same problem, I can write to it and send it the "WHO AM I" register value, and get the ack, but the read of that register never executes or generates any output as a result of the command.

I have tried every combination of discrete commands and buffer options and cannot get this working, I have external pullups and you can see from the scope image, I have good clean transactions and well defined edges.  I am running at 100Kbs, and have nothing special selected, help please.

I have attached the project, but all is commented out, except initialization and EEprom code.

Here is the buf code:

void EE_config(void)

    {

        uint8 writebuff[3];

        uint8 readbuff[16];

      

        for(uint8 i=1;i<17;i++)

        {          

           writebuff[0] = 0x00;

           writebuff[1] = i;

           writebuff[2] = i;

         

            while(I2C_I2C_MSTAT_CLEAR != I2C_I2CMasterStatus());

          

            I2C_I2CMasterWriteBuf(EEprom_addr_write, writebuff, 3, I2C_I2C_MODE_COMPLETE_XFER);             

            while(!(I2C_I2CMasterStatus() & I2C_I2C_MSTAT_WR_CMPLT));      

            I2C_I2CMasterClearStatus();             

            while(I2C_I2C_MSTAT_CLEAR != I2C_I2CMasterStatus());

          

            I2C_I2CMasterWriteBuf(EEprom_addr_write, writebuff, 2, I2C_I2C_MODE_NO_STOP);             

            while(!(I2C_I2CMasterStatus() & I2C_I2C_MSTAT_WR_CMPLT));      

            I2C_I2CMasterClearStatus();             

            volatile uint8 outtemp = I2C_I2CMasterReadBuf(EEprom_addr_read, readbuff, 1, I2C_I2C_MODE_NO_STOP);       

            /* Wait for read to complete, and clear the status */      

            while(!(I2C_I2CMasterStatus() & I2C_I2C_MSTAT_RD_CMPLT));      

            I2C_I2CMasterClearStatus();             

   

         }

    return;

    }//EEprom_config

SDS00004.png

0 Likes
1 Solution

OK, not sure how this is relevant, but I had some variables declared as volatile in my read/write subroutines to ensure the compiler did not optimize them out, once I removed the volatile label from the local, it works.  I can read and write to the EEprom.

Thanks again Gyan,

View solution in original post

0 Likes
3 Replies
GyanC_36
Employee
Employee
250 replies posted 100 replies posted 50 replies posted

Can you put a break point before and after the read API and observe who is causing the problem?

If you have a USB Logic Analyzer with you ,please capture the signals using that and share.

-Gyan

0 Likes

I cannot get the LOGIC analyzer to work, my poor skills with the scope.

I have looked at all aspects of the signals compared to the DS and it meets all specifications, trapped the error codes in a registers when stalled.

I get two codes, one I have never seen before: I get 0x04, which is transfer in progress, but then I get code 0x12 which I think means transfer complete with a timeout?

Herb

0 Likes

OK, not sure how this is relevant, but I had some variables declared as volatile in my read/write subroutines to ensure the compiler did not optimize them out, once I removed the volatile label from the local, it works.  I can read and write to the EEprom.

Thanks again Gyan,

0 Likes