1 2 3 Previous Next 41 Replies Latest reply on Jan 23, 2016 12:42 AM by user_1377889

    I2C Write Data Format Problems Hex/Int

    user_385543602

       Hi,

         

      See the attached project.  

         

      What I am trying to do is read data, then send it to a 0-5V DAC chip (MCP4725).  I have no problem reading the data, but when it goes from my data buffer to be written to the I2C port, something bad happens, because the DAC does not respond correctly.  See the picture I captured in the zip file.  The value of the data is, correctly, 0xA1, or 161.  If I manually retype '0xA1' in the bracket instead of putting the variable, it works like it is supposed to.  Do I need to 'cast' the hex as an integer somehow, or inform the compiler what type of data it is?

         

      I know, this is probably extremely basic C programming stuff, but please bear with me.

         

      Thank you,

         

      Tom

        • 1. Re: I2C Write Data Format Problems Hex/Int
          user_14586677

          You declared value as uint32, but should be uint16. Then when

             

          you write to DAC you need to split it into 2 bytes, uint8, and write

             

          those out to the 12 bit DAC. Mask  off upper 8 get lower byte,

             

          and mask off lower 8 and shift >> 8 bits to get upper byte.

             

           

             

          You also do not test the I2C command return values for an error

             

          and handle that.

             

           

             

          Regards, Dana.

          • 2. Re: I2C Write Data Format Problems Hex/Int
            user_385543602

             Hi,

               

            The sensor takes 12 bits of data, but my input data is only 8 bit, therefore I do not need the second part (I write 0x00 to it).  It does not matter what I set 'value' to (int, int32, uint8).  If I use it from a variable, it will not work with the component, but if I simply pause the program, read what the value is as a hex, then type it in (0x96 in this case) then it works perfectly.  See the attached image.  Any idea what is happening here?  

               

            I understand the I2C is not good form, but that is not what is at issue here, as I can hard code the value and the transfer works perfectly.  It is not until I use a variable that it breaks down.

               

            Thank you for your input,

               

            Tom

            • 3. Re: I2C Write Data Format Problems Hex/Int
              user_1377889

              As Dana said "You also do not test the I2C command return values for an error and handle that."

                 

              Test that! This is at least during prototype phase the key to success.

                 

               

                 

              Bob

              • 4. Re: I2C Write Data Format Problems Hex/Int
                user_385543602

                 Hi,

                   

                I copied some 'proper' I2C code from an example and now it does not function at all.  It gets stuck the second time around in this block of code:

                   

                while (0u == (I2C_DAC_I2CMasterStatus() & I2C_DAC_I2C_MSTAT_WR_CMPLT))

                   

                        {

                   

                            /* Waits until master completes write transfer */

                   

                        }

                   

                The I2C component worked flawlessly beforehand (besides not accepting the variable data source) Sort of frustrating.  Any ideas?

                   

                Thank you for your help,
                Tom

                • 5. Re: I2C Write Data Format Problems Hex/Int
                  user_385543602

                   Well,

                     

                  I turned off the striplights because I saw they were interfering with some interrupts, and sure enough, my problem with the 'WR_CMPLT' hanging went away.

                     

                  However, the I2C component still does not respond at all to the variable input into the buffer, but works just fine if I hard code the exact same number in the program.  

                     

                  I am still stuck with the original issue.  Any ideas?

                     

                  Thank you,

                     

                  Tom

                  • 6. Re: I2C Write Data Format Problems Hex/Int
                    user_242978793

                    This sounds like a issue with the ground plane and device layout on the MPC485. The data sheet says that this can be an issue with performance.  "You do not have the issue with a fixed data but when the unit is running at speed you do.  Cjeck 8.4 and on about layout issues..

                    • 7. Re: I2C Write Data Format Problems Hex/Int
                      user_385660486

                      Did you flag the variable as volatile, I don't send an eye into your project but some symptoms can be recognized...

                         

                      volatile uint16 myvar;

                         

                       

                         

                      Regards,

                         

                      PNN

                      • 8. Re: I2C Write Data Format Problems Hex/Int
                        user_14586677

                        Your DSO is your best friend here. Setting up its trigger for signals

                           

                        Vss - .5 >= Vsig >= Vdd + .5 and see if it captures anything on a

                           

                        suspect line or Vdd or even Vss ground bounce. If you have a 4

                           

                        channel scope you can monitor 4 lines at a time. Single shot cap-

                           

                        tures.

                           

                         

                           

                        Also use infinite persistence on supply lines to see how effective

                           

                        your bypassing is.

                           

                         

                           

                        Regards, Dana.

                        • 9. Re: I2C Write Data Format Problems Hex/Int
                          user_385543602

                           Hi,

                             

                          Thank you for the feedback.  I tried the volatile thing, and it did not work.  I guess I don't understand why if the number comes from a variable versus a constant in my program it would be affected by the board layout?  Please see the attached image.  The number in buffer[1], or variable 'test' is the culprit here.  It is being read in as 0xA7, and NOT CHANGING unless I change it externally through hardware.  All I have to do to get the DAC to work correctly is to write 'test = 0xA7' instead of 'test = *dmxValuePtr'.  I had a test program where it would cycle through the 4096 values of the DAC each program cycle, and that worked fine as well.

                             

                          Any ideas?  Unfortunately I do not have a scope, and cannot test the ground plane theory without a board redesign...  I have seen a number of successful boards using this chip that do not have a separate analog ground plane.

                             

                          Thank you,

                             

                          Tom

                          • 10. Re: I2C Write Data Format Problems Hex/Int
                            user_385543602

                             Things seem to be getting even stranger...at least for me.  See the attached image.  The top code does not work, but the bottome code works correctly.  They are both setting buffer[1] directly to 0xCC, but one is conditional on my incoming data.  That one though it seemingly sends the same data to the DAC, does not work at all, in fact it seems to be sending 0x00 because it sets the DAC back to 0V output.

                               

                            Any ideas are greatly appreciated.

                               

                            Thank you in advance,

                               

                            Tom

                            • 11. Re: I2C Write Data Format Problems Hex/Int
                              user_242978793

                              You are asking for trouble not haveing correct ground planes in a high speed analog /digital board.  Ground loop signals and cause all kinds of issues with DAC and ADC devices.  I worked on a military project and it had a large board of ADC and one DAC for a bit signal the ground planes where seperated and only came togetter at one point.  It 's called a Star ground plane.  This board was very quite and worked very well.  It even had some Ferite beads on the board to help filter the high speed noise,.   Check the PSOC 4 design guide lines AN57821.  it shows you how to layout the board Mixed Signal Circuit Board Layout Considerations.

                              • 12. Re: I2C Write Data Format Problems Hex/Int
                                user_385543602

                                 Thank you for your input.

                                   

                                I understand that this board may not be laid out in the best way possible, but isn't that just a red herring?  What would the ground plane have to do with functionality based on what type of variable makes up the data being sent over the bus?  The I2C bus should be sending the same value data at exactly the same levels no matter where it comes from, correct?  

                                   

                                Did you get a chance to look at the image?  Doesn't it seem strange that the compiler shows the exact same data being sent, but depending on it's source it either works or does not?

                                   

                                I don't think this is the issue since the DAC works without any problems at all if I send a constant over the bus.  It generates exactly the voltage it is supposed to with no communication problems or fluctuations.

                                   

                                I do not have much experience with this, obviously, can you explain it to me?

                                   

                                Thank you,
                                Tom

                                • 13. Re: I2C Write Data Format Problems Hex/Int
                                  user_385660486

                                  Like this ?

                                     

                                   

                                     

                                  // Store buffers
                                  volatile int16 DMXbuffer[36];
                                  int16 *dmxReadPtr = DMXbuffer;
                                   

                                     

                                   

                                     

                                  Your DMBXBuffer is updated by an interrupt and sent to the DAC (I2C) in the main ... some compiler optimisations can make this scenario unreliable.

                                  • 14. Re: I2C Write Data Format Problems Hex/Int
                                    content.librarian

                                    Did you already consider to give your I2C component's interrupt the highest priority? The behavior of your I2C is quite abnormal and I haven't seen that before. I would suggest (besides the interrupt) to try reducing your project piece by piece to the bare I2C communication to see what causes the error.

                                       

                                     

                                       

                                    Bob

                                    1 2 3 Previous Next