I2C bus occupied

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
2
down vote

favorite












I have a problem with an I2C communication and want you to ask whether there is a better solution than mine.



I am programming an STM32F103 at the moment. There is one sensor (MPU6050) which is connected via I2C to the STM32. I recognized that if I reset the STM32 a few times, the STM32 gets stuck (or got an timeout error) during the initialization of the I2C. The timeout error was during the wait of the busy flag. So the I2C communication was "occupied". The MPU6050 is the only other I2C device (slave).



In my opinion there is an error, because I was reading a register from the MPU6050 when I reset the STM32. So the MPU6050 never gets the stop condition.



I do not know how to reset the I2C connection, when the bus is "occupied" (by the MPU6050). So my solution would be to do a hardware reset with a transmission gate of the MPU6050. Is there maybe a simpler software solution?



Thanks for the help.










share|improve this question



























    up vote
    2
    down vote

    favorite












    I have a problem with an I2C communication and want you to ask whether there is a better solution than mine.



    I am programming an STM32F103 at the moment. There is one sensor (MPU6050) which is connected via I2C to the STM32. I recognized that if I reset the STM32 a few times, the STM32 gets stuck (or got an timeout error) during the initialization of the I2C. The timeout error was during the wait of the busy flag. So the I2C communication was "occupied". The MPU6050 is the only other I2C device (slave).



    In my opinion there is an error, because I was reading a register from the MPU6050 when I reset the STM32. So the MPU6050 never gets the stop condition.



    I do not know how to reset the I2C connection, when the bus is "occupied" (by the MPU6050). So my solution would be to do a hardware reset with a transmission gate of the MPU6050. Is there maybe a simpler software solution?



    Thanks for the help.










    share|improve this question

























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I have a problem with an I2C communication and want you to ask whether there is a better solution than mine.



      I am programming an STM32F103 at the moment. There is one sensor (MPU6050) which is connected via I2C to the STM32. I recognized that if I reset the STM32 a few times, the STM32 gets stuck (or got an timeout error) during the initialization of the I2C. The timeout error was during the wait of the busy flag. So the I2C communication was "occupied". The MPU6050 is the only other I2C device (slave).



      In my opinion there is an error, because I was reading a register from the MPU6050 when I reset the STM32. So the MPU6050 never gets the stop condition.



      I do not know how to reset the I2C connection, when the bus is "occupied" (by the MPU6050). So my solution would be to do a hardware reset with a transmission gate of the MPU6050. Is there maybe a simpler software solution?



      Thanks for the help.










      share|improve this question















      I have a problem with an I2C communication and want you to ask whether there is a better solution than mine.



      I am programming an STM32F103 at the moment. There is one sensor (MPU6050) which is connected via I2C to the STM32. I recognized that if I reset the STM32 a few times, the STM32 gets stuck (or got an timeout error) during the initialization of the I2C. The timeout error was during the wait of the busy flag. So the I2C communication was "occupied". The MPU6050 is the only other I2C device (slave).



      In my opinion there is an error, because I was reading a register from the MPU6050 when I reset the STM32. So the MPU6050 never gets the stop condition.



      I do not know how to reset the I2C connection, when the bus is "occupied" (by the MPU6050). So my solution would be to do a hardware reset with a transmission gate of the MPU6050. Is there maybe a simpler software solution?



      Thanks for the help.







      i2c stm32f10x






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 19 at 21:55









      SamGibson

      10.1k41436




      10.1k41436










      asked Aug 19 at 21:09









      Lukas_M94

      162




      162




















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          6
          down vote













          One general solution to unsticking an I2C bus is to just clock the SCL line for 18 or more cycles. This will clock the rest of the current byte out of the slave, let it see a NACK and then clock out one more byte. However, if the slave is very confused, this may not work. Also, most hardware I2C modules cannot do this so you would need to take control of the I2C lines as GPIOs and clock it manually.



          Externally driving a reset line to the slave is the best solution. Also, some slaves can be configured to timeout after a relatively long time (e.g. 250 ms).






          share|improve this answer
















          • 4




            +1 I believe this issue is documented in an old Philips AppNote, but I can't find it right now. So in case it helps readers, here's a link to Analog Devices AppNote AN-686 which also describes the problem and the approaches you kindly mentioned, for those who want more reading material on the topic.
            – SamGibson
            Aug 19 at 22:13










          • Thanks. Yeah like in the document at figure 1, I would do a cut of the power line to reset the MPU6050.
            – Lukas_M94
            Aug 20 at 5:17










          Your Answer




          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("mathjaxEditing", function ()
          StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
          StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
          );
          );
          , "mathjax-editing");

          StackExchange.ifUsing("editor", function ()
          return StackExchange.using("schematics", function ()
          StackExchange.schematics.init();
          );
          , "cicuitlab");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "135"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          convertImagesToLinks: false,
          noModals: false,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: null,
          bindNavPrevention: true,
          postfix: "",
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













           

          draft saved


          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2felectronics.stackexchange.com%2fquestions%2f391839%2fi2c-bus-occupied%23new-answer', 'question_page');

          );

          Post as a guest






























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          6
          down vote













          One general solution to unsticking an I2C bus is to just clock the SCL line for 18 or more cycles. This will clock the rest of the current byte out of the slave, let it see a NACK and then clock out one more byte. However, if the slave is very confused, this may not work. Also, most hardware I2C modules cannot do this so you would need to take control of the I2C lines as GPIOs and clock it manually.



          Externally driving a reset line to the slave is the best solution. Also, some slaves can be configured to timeout after a relatively long time (e.g. 250 ms).






          share|improve this answer
















          • 4




            +1 I believe this issue is documented in an old Philips AppNote, but I can't find it right now. So in case it helps readers, here's a link to Analog Devices AppNote AN-686 which also describes the problem and the approaches you kindly mentioned, for those who want more reading material on the topic.
            – SamGibson
            Aug 19 at 22:13










          • Thanks. Yeah like in the document at figure 1, I would do a cut of the power line to reset the MPU6050.
            – Lukas_M94
            Aug 20 at 5:17














          up vote
          6
          down vote













          One general solution to unsticking an I2C bus is to just clock the SCL line for 18 or more cycles. This will clock the rest of the current byte out of the slave, let it see a NACK and then clock out one more byte. However, if the slave is very confused, this may not work. Also, most hardware I2C modules cannot do this so you would need to take control of the I2C lines as GPIOs and clock it manually.



          Externally driving a reset line to the slave is the best solution. Also, some slaves can be configured to timeout after a relatively long time (e.g. 250 ms).






          share|improve this answer
















          • 4




            +1 I believe this issue is documented in an old Philips AppNote, but I can't find it right now. So in case it helps readers, here's a link to Analog Devices AppNote AN-686 which also describes the problem and the approaches you kindly mentioned, for those who want more reading material on the topic.
            – SamGibson
            Aug 19 at 22:13










          • Thanks. Yeah like in the document at figure 1, I would do a cut of the power line to reset the MPU6050.
            – Lukas_M94
            Aug 20 at 5:17












          up vote
          6
          down vote










          up vote
          6
          down vote









          One general solution to unsticking an I2C bus is to just clock the SCL line for 18 or more cycles. This will clock the rest of the current byte out of the slave, let it see a NACK and then clock out one more byte. However, if the slave is very confused, this may not work. Also, most hardware I2C modules cannot do this so you would need to take control of the I2C lines as GPIOs and clock it manually.



          Externally driving a reset line to the slave is the best solution. Also, some slaves can be configured to timeout after a relatively long time (e.g. 250 ms).






          share|improve this answer












          One general solution to unsticking an I2C bus is to just clock the SCL line for 18 or more cycles. This will clock the rest of the current byte out of the slave, let it see a NACK and then clock out one more byte. However, if the slave is very confused, this may not work. Also, most hardware I2C modules cannot do this so you would need to take control of the I2C lines as GPIOs and clock it manually.



          Externally driving a reset line to the slave is the best solution. Also, some slaves can be configured to timeout after a relatively long time (e.g. 250 ms).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Aug 19 at 21:24









          DoxyLover

          5,19811221




          5,19811221







          • 4




            +1 I believe this issue is documented in an old Philips AppNote, but I can't find it right now. So in case it helps readers, here's a link to Analog Devices AppNote AN-686 which also describes the problem and the approaches you kindly mentioned, for those who want more reading material on the topic.
            – SamGibson
            Aug 19 at 22:13










          • Thanks. Yeah like in the document at figure 1, I would do a cut of the power line to reset the MPU6050.
            – Lukas_M94
            Aug 20 at 5:17












          • 4




            +1 I believe this issue is documented in an old Philips AppNote, but I can't find it right now. So in case it helps readers, here's a link to Analog Devices AppNote AN-686 which also describes the problem and the approaches you kindly mentioned, for those who want more reading material on the topic.
            – SamGibson
            Aug 19 at 22:13










          • Thanks. Yeah like in the document at figure 1, I would do a cut of the power line to reset the MPU6050.
            – Lukas_M94
            Aug 20 at 5:17







          4




          4




          +1 I believe this issue is documented in an old Philips AppNote, but I can't find it right now. So in case it helps readers, here's a link to Analog Devices AppNote AN-686 which also describes the problem and the approaches you kindly mentioned, for those who want more reading material on the topic.
          – SamGibson
          Aug 19 at 22:13




          +1 I believe this issue is documented in an old Philips AppNote, but I can't find it right now. So in case it helps readers, here's a link to Analog Devices AppNote AN-686 which also describes the problem and the approaches you kindly mentioned, for those who want more reading material on the topic.
          – SamGibson
          Aug 19 at 22:13












          Thanks. Yeah like in the document at figure 1, I would do a cut of the power line to reset the MPU6050.
          – Lukas_M94
          Aug 20 at 5:17




          Thanks. Yeah like in the document at figure 1, I would do a cut of the power line to reset the MPU6050.
          – Lukas_M94
          Aug 20 at 5:17

















           

          draft saved


          draft discarded















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2felectronics.stackexchange.com%2fquestions%2f391839%2fi2c-bus-occupied%23new-answer', 'question_page');

          );

          Post as a guest













































































          Popular posts from this blog

          How to check contact read email or not when send email to Individual?

          Bahrain

          Postfix configuration issue with fips on centos 7; mailgun relay