8 Replies Latest reply on Aug 27, 2014 5:58 PM by userc_4243

    I2C Example Code

      Hi All,

       

      I noticed that there seems to be two ways to do I2C communication--

          read_status = cfa_bsc_OpExtended(reg_bytes_to_read, sizeof(reg_bytes_to_read), reg_read_bytes_to_write,

                                                              sizeof(reg_read_bytes_to_write), LM73_SLAVE_ADDR,

                                                              I2C_SLAVE_OPERATION_READ);

       

      and using the interface in i2cm.h. What is the difference with these two methods? Is there a prefered method?

       

       

       

      Also, I was wondering if other I2C examples exist besides the LM73? Ideally, a example that implements the Freescale MMA54XX accelerometer would be great. Also, keeping the examples simple would be great. I am suppose to learn from these examples. If you are 'abstracting' everything it makes it more time consuming to learn from. Ideally, you could have two examples, one with great production quality code practices and one that is easy to learn from. Great going on the commenting and I do notice and appreciate the Broadcom efforts.

        • 1. Re: I2C Example Code
          ArvindS_76

          You can use either, though there have been some reports that the API in i2cm.h don't work. If you are using a serial flash for NV storage and still want to use I2C peripherals, you must use the API in i2cm.h (only allowed/available starting from SDK 2.1).

           

          > Also, I was wondering if other I2C examples exist besides the LM73?....

          The WICED Sense application sources may be made available sometime in the future and this will have plenty of examples of interfacing with some more I2C slaves. We would love to add more samples and sensors, but there are way too many of them out there and once you get the hang of using the I2C API available in the 2073x family of chips, interfacing with a new one should be fairly straightforward.

          1 of 1 people found this helpful
          • 2. Re: I2C Example Code

            With the cfa_bsc...(...) is there a initialization routine? Does anyone have a one [maybe two] functions showing from application start to finish how read a register on a I2C slave device with a arbitrary address? It would be great if I didn't have to reinvent the wheel.

            • 3. Re: I2C Example Code
              MichaelF_56

              I think what you need is here:WICED™ Smart Hardware Interfaces

               

              • There is one code snippet which shows how to initialize SPIFFY2 in the master role, and how to write and then read a byte from a SPI slave
              • There is a second code snippet shows how to initialize SPIFFY2 in the slave role, and how to read and then write a byte to a SPI master.

               

              I suspect others here on the community may be able to provide other examples as well.

              • 4. Re: I2C Example Code

                I am speaking about I2C...it looks like SPIFFYX is for SPI, right? I am using this code for a accelerometer, not any form of memory.

                 

                I went through this guide and it seems like it gives you code to do raw i2c write/read operations but it would be good to have a template on how to read a specific register or write to a specific register. If I could get the code for WICED Sense that could be what I need...

                 

                I am unsure why the code has not been released (as far as I am aware).

                 

                Thank You,

                George

                • 5. Re: I2C Example Code
                  ArvindS_76

                  Doesn't temperature_sensor_read_8_bit_register() or temperature_sensor_write_8_bit_register()  or one of the other 16 bit register read/write functions in the LM73 sensor sample app help?

                  • 6. Re: I2C Example Code
                    MichaelF_56

                    My apologies.  I was working on responding to another SPI related question and mixed the two.  As you noted, within the same document, there is a code snippet shows how to initialize I2C in the master role, and how to write, read and use the combo write-then-read transaction using the driver API available in the WICED SDK.

                     

                    Also as previously noted, there will be some source released soon for the WICED Sense board that was announced today.  That will probably end up being more helpful for your specific needs.

                     

                    Our SDK/API abstracts register level access, so I doubt code of any kind will be released that demonstrates direct register access.

                    • 7. Re: I2C Example Code

                      Ideally, I would like to see the WICED Sense code. I got a WICED Sense yesterday and it seems like it would fit my needs.

                       

                      I have gone over the i2c temperature sensor but would like some additional example because I feel that code is a bit hard to learn from/easy to miss something. I would like to see from start to finish in very simple/concise way (similar to that document you sent me) a way to initialize i2c (if needed) and then how to read a register on a specific i2c device.

                       

                      My I2C code isn't really working. I have it on a scope and haven't checked to see from a hardware level if it is acking/nacking it yet. I do see a transaction happening. I was getting a BUSY (I2CM_BUSY) return code when I was using the i2cm.h class. I can send code if someone can help.

                       

                      I was hoping to see if I can fix the code before I dive into the hardware and deciphering the scope traces. I am trying to get a Freescale MMA8452 accelerometer working.

                       

                      Thank You,

                      George

                      • 8. Re: I2C Example Code
                        Doesn't temperature_sensor_read_8_bit_register() or temperature_sensor_write_8_bit_register()  or one of the other 16 bit register read/write functions in the LM73 sensor sample app help?

                         

                        Yes, it does but I started from there and hit some roadblocks and instead of investing hours into reinventing the I2c wheel, it would be great if I could see a few working solutions to figure out and easily fix the issue.