1 Reply Latest reply on Dec 9, 2015 11:38 PM by user_1377889

    I2C fails after fail on I2C_MasterSendStart

    netanel.unger
          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); 
              }
          }