1 2 Previous Next 15 Replies Latest reply on Feb 5, 2017 6:29 AM by user_1377889

    ADXL345

    m.roshandelpoor_1580446

      Hi freinds;

         

      I want to running adxl345 by psoc5 but i cant runing in i2c or spi peripheral.older topic is not useful for me.

         

      Anyone have any example code for interfacing a 5LP to use correct programing  for relationship between master and slave in i2c or spi , or tested psoc creator file for adxl345?

         

      Roshandel

        • 1. Re: ADXL345
          m.roshandelpoor_1580446

          My psoc is CY5888LTI-LP097 please help me for solve problem?

             

          little example for psoc is one of most problem with them.tanks for attention...

          • 2. Re: ADXL345
            user_1377889

            Welcome in the forum Roshandel.

               

            I would suggest you to use I2C interface. Wire your ADXL345 as shown in the datasheet.

               

            Are you using a Cypress development/prototyping Kit? Which one??

               

            Place an I2C Master component onto your topdesign. Do not forget the required pullup resistors. ADXL's I2C address will be 0x1D or 0x52 depending on the level of the AltAddress pin.

               

            Byte I2C interface is quite simple: After setting up the component and starting it you use

               

                I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE);    // Initialize a transaction for writing
                I2C_MasterWriteByte(Register);                // Indicate which register you want to write to
                I2C_MasterWriteByte(Value);                // Write to register
                I2C_MasterSendStop();                    // End of transaction

               

            When you want to read from a device you use (example for reading two bytes

               

                I2C_MasterSendStart(DeviceAddress,I2C_WRITE_XFER_MODE);    // Initialize a transaction for writing
                I2C_MasterWrite(Register);                // Indicate which register you want to write to
                I2C_MasterSendRestart(DeviceAddress,I2C_READ_XFER_MODE);
                I2C_MasterReadByte(I2C_ACK_DATA);            // Read from register
                I2C_MasterReadByte(I2C_NAK_DATA);            // Read from register, last byte is NAKed
                I2C_MasterSendStop();                    // End of transaction

               

            Not too difficult. Keep in mind that most of the APIs (except those for reading a byte) return a status byte which, when non-zero indicate an error condition.

               

            The high-level APIs must be used in this way:

               

            Writing to slave Count bytes
            I2C_MasterWriteBuf(SlaveAddress,DataPtr,Count,I2C_MODE_COMPLETE_XFER);

               

            Reading from Slave sending register byte first:
            I2C_MasterWriteBuf(SlaveAddress,&RegAddress,1,I2C_MODE_NO_STOP);
            I2C_MasterReadBuf(SlaveAddress,DataPtr,Count,I2C_MODE_REPEAT_START);

               


            Bob

            • 3. Re: ADXL345
              m.roshandelpoor_1580446

              Tanks for your description MR Marlowe,but i want examples or psoc creator project that i can see and running.but my problem is i2c peripheral,i think because it is not sync with sensor.i dont now why.can you give me a sample?

                 

              my psoc is cy8ckit-059 prototyping kit.

                 

              tanks

              • 4. Re: ADXL345
                user_1377889

                I2C "is not sync with sensor" What do you mean with that (language barrier, please explain)

                   

                "why.can you give me a sample?" Because I would have to write it.

                   

                Start Creator. At Start page scroll to "Find Code Example"

                   

                or

                   

                Right click on the I2C Master component and select "Find Code Example"

                   

                 

                   

                Bob

                • 5. Re: ADXL345
                  m.roshandelpoor_1580446

                  Excuse me Bob Marlowe for language barrier.I test adxl345 with avr and work verygood.now i want to use header of avr from codevision in psoc creator.I did it and change format of header on psoc creator,but it is not work.can you see my code?and tell me where is mistake.it is  important for me to run with psoc.tanks alot...

                  • 6. Re: ADXL345
                    user_1377889

                    The project compiles fine exept the warnings concerning the #pragma which is installation/compiler dependent code, you may delete them.

                       

                    What is really strange is the fact that in your .h file are the definitions (code) for many variables and functions. Normally a .h file only contains declarations (also known as function prototypes or forward declarations) and declarations of external variables. So a k. file never allocates code or ram space and can be #included several times in a project without conflicts.

                       

                    All those definitions go into a corresponding (usually same name) .c file which #includes the .h file.

                       

                     

                       

                    The I2C address of your ADCL is wrong. Creator expects a 7 bit address as listed in the ADXL manual, so not 0xa6 but 0x53.

                       

                     

                       

                    Bob

                    • 7. Re: ADXL345
                      m.roshandelpoor_1580446

                      This .h code worked very well in avr and calculate x , y , z and calibration to calculate exact.I deleted #pragma but it is not working right now.Then i changed I2C address of 0xa6 to 0x53 and 0x1d but not working again.

                         

                      Even when i test i2c or spi from psoc creator on my  cypress,not sending and recieving.I want to test your code sample for adxl and check with my code to find mistake?

                         

                      this picture of adxl345 running by avr...

                      • 8. Re: ADXL345
                        user_1377889

                        You do not start the I2C interface. Put a I2C_1_Start() before accessing the ADXL.

                           

                        As you prove with your picture: Even badly written software can run correctly. The problems tend to start when platform changes are needed.

                           

                         

                           

                        Bob

                        1 of 1 people found this helpful
                        • 9. Re: ADXL345
                          m.roshandelpoor_1580446

                          Hi friends.i want to ask question.please help me and show guidline to me that solve problem please...

                             

                          I am running adxl345 on i2c and its worked very well.project file is attached here,but i am using fixed function.when i changed i2c component from fixed function to UDB it is not working.why it is happening?how can i solved problem?

                          • 10. Re: ADXL345
                            user_1377889

                            Got a virus alert when I copied your project. Please check on your side...

                               

                             

                               

                            Bob

                            • 11. Re: ADXL345
                              user_1377889

                                  Accel_Xout_Val =((read_i2c(ADXL345_Addr,RA_DATAX1)<<8) | read_i2c(ADXL345_Addr,RA_DATAX0))+Cal_Xout_Val;

                                 


                              This will not work: read_i2c() returns a char which always will deliver 0x00 when shifted left by 8.

                                 

                              Another issue might be

                                 

                                  Data=I2C_MasterReadByte(I2C_ACK_DATA);            // Read from register
                                  //I2C_MasterReadByte(I2C_NAK_DATA);            // Read from register, last byte is NAKed

                                 


                              You just read one byte, but that should be NAKed, so

                                 

                                  Data=I2C_MasterReadByte(I2C_NAK_DATA);            // Read from register

                                 

                              would be correct.

                                 

                               

                                 

                              Bob

                              • 12. Re: ADXL345
                                m.roshandelpoor_1580446

                                Oh i dont know why it has virus but now i clear with kaspersky.please check my file.

                                   

                                tanks alot...

                                • 13. Re: ADXL345
                                  user_1377889

                                  No virus warning in your code now. Some html files had been corrupted.

                                     

                                   

                                     

                                  Bob

                                  • 14. Re: ADXL345
                                    m.roshandelpoor_1580446

                                     I changed and do any thing in program but it is not work.dear Bob my program is working well when i select I2C component as fixed function and not working when i select UDB.i dont know why it is happening?

                                    1 2 Previous Next