AnsweredAssumed Answered

I2C Problems Using CW 10.3 and Processor Expert

Question asked by chinniwhites on Jul 27, 2013
Latest reply on Jul 31, 2013 by chinniwhites

Ok, so I am trying to get IIC between MC9S08AW32 and MC9RS08KB4 using processor expert working.  My SCL freq match exactly at 125 kHz but my SDA is a bit different (1.8 us on Master and 1.75 us on Slave) and perhaps this is an issue.  I am trying to get the 7 analog values from the kb4 to the aw32.  The data is coming over but not perfect.  I get one or two values that seem to be correct but then I get some zeros OR very large numbers mixing inbetween the good data.  I believe errors are happening while transmitting from slave (seems to be tx_buffer_full error) after a few successful transmission.  Below is the I2C code related to Master and Slave.  Please, if anyone can help me out on this one it would be much appreciated.

 

MASTER:

        //if transmit complete

        if (IICTxFlag == 0){

            IICTxError = I2C1_SendBlock(&IICTxData, 2, &IICTxRet);

            if (IICTxError != ERR_OK){

                //handle error

            }

            while ((!IICTxFlag) && (I2C1_CheckBus() == I2C1_BUSY));

            startRx = 1;

        }

        //start reception of data

        if (startRx == 1){

            for (IICLoop; IICLoop < 7; IICLoop++){

                IICRxError = I2C1_RecvBlock(&IICRxData, 2, &IICRxRet);

                if (IICRxError != ERR_OK){

                    //handle error

                }

                while((!IICRxFlag) && (I2C1_CheckBus() == I2C1_BUSY));

               

                //if receive complete

                adRemChannels[IICLoop] = (IICRxData[0] << 8) | IICRxData[1];

                IICRxFlag = 0;

            }

            if (IICLoop >= 7){

                IICLoop = 0;

                IICTxFlag = 0;

                startRx = 0;

                solarV2Counts    = adRemChannels[0];

                solarV1Counts    = adRemChannels[1];

                windV3Counts    = adRemChannels[2];

                windV2Counts    = adRemChannels[3];

                windV1Counts    = adRemChannels[4];

                solarAmpsCounts = adRemChannels[5];

                windAmpsCounts    = adRemChannels[6];

            }

        }

 

SLAVE:

      //receive data on full buffer

      while (!IICRxFlag);

      if ((IICRxFlag == 1) && (startTx == 0)){

          IICRxError = I2C1_RecvBlock(&IICRxData, 2, &IICRxRet);

          if (IICRxError != ERR_OK){

              //handle error

          }

          while((!IICRxFlag) && (I2C1_CheckBus() == I2C1_BUSY));

         

          //if message command good (MM), send data to master

          if ((IICRxData[0] == 0x4D) && (IICRxData[1] == 0x4D)){

              IICRxData[0] = 0;

              IICRxData[1] = 0;

              startTx = 1;

          }

      }

      if (startTx == 1){

          for (loop; loop < 7; loop++){

              IICTxData[0] = (unsigned char)(adChannels[loop] >> 8);

              IICTxData[1] = (unsigned char)adChannels[loop];

             

              IICTxError = I2C1_SendBlock(&IICTxData, 2, &IICTxRet);

              if (IICTxError != ERR_OK){

                  //handle error

              }

              while (((IICTxFlag & TX_EMPTY) == 0) && (I2C1_CheckBus() == I2C1_BUSY));

          }

          if (loop >= 7){

                loop = 0;

              startTx = 0;

              IICRxFlag = 0;

          }

      }

Outcomes