I2C fails after fail on I2C_MasterSendStart

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,   
   
    I'm using the I2C block as master (version 3.50).   
   
    After sending I2C_MasterSendStart to the wrong address and missing Ack:   
   
    1. I2C_MasterSendStart  returns I2C_MSTR_NO_ERROR, which is not true.   
   
    2. The second command is "I2C_MasterWriteByte", and it's stuck in:   
   
            /* Wait until data byte has been transmitted */    
        while(I2C_WAIT_BYTE_COMPLETE(I2C_CSR_REG))   
   
    included the scope catpure.   
   
        
   
    Here is very simple code demonstrate it:   
   
    

    uint8 state = 0;
    uint8 dev_id = 0;
    uint8 wBuffer[2] = {1,2};

    


    /*Enable Global Interrupts */
    CYGlobalIntEnable; 

    

    I2C_Start();
    
    for (dev_id=5 ; dev_id<0xff ; dev_id++)
    {
        state = I2C_MasterSendStart(dev_id, 0);    //always returns I2C_MSTR_NO_ERROR
        if (state != I2C_MSTR_NO_ERROR)
        {
            state = I2C_MasterClearStatus();
            state =  I2C_MasterWriteByte(0x00);  // stuck here every time
            state =  I2C_MasterSendRestart(dev_id, 1);
            wBuffer[0] = I2C_MasterReadByte(I2C_ACK_DATA); 
            wBuffer[1] = I2C_MasterReadByte(I2C_NAK_DATA); 
        }
    }

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

When you got stuck, the variable state must show an error (state != I2C_MSTR_NO_ERROR). You get stuck because you continue accessing the I2C

   

 

   

Bob

0 Likes