This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI and MPU6050

Hi,

I've been searching the devzone for TWI examples, and preferably an example with MPU6050. Here are a conclusion of stuff that I found, but as some of them were for 2013/2014 wanted to check first that no updated versions are available:

  • It seems the TWI example has been removed after SDK 6, but the drivers are still there. I'm using SDK 9 for PCA20006 (Beacon module).

  • There are twi_hw_master.c and twi_sw_master.c in drivers_nrf folder, which it seems the hw one doesn't work with Softdevice, but sw one works. Don't know what are the pro and cons of hw and sw.

  • In devzone.nordicsemi.com/.../ Alseth has provided a file named sd_twi_hw_master.c which seems will solve the issue with Softdevice. This was originally posted 2 years ago and re-uploaded one year ago. Don't know if the problem has been solved in future releases.

  • I can see a file named nrf_drv_twi.c in the twi_master folder, which was not mentioned in any of the posts that I looked at. Is this a new addition?

  • There are drivers specifically for MPU6050 as explained in devzone.nordicsemi.com/.../ that provide init, write, read, and verify product id.

My goal is read data every 50msec from the sensor and then advertise them whenever they fill a full packet.

Considering those functions provided in MPU6050 drivers, should I just go through the registers of MPU6050 and write the correct values to them by using the WRITE function, and then just read with READ function and save data? Meaning that I do not need to face writing any code for TWI and...?

Any other setting required?

Thanks, FA

Parents
  • Hi.

    The old twi_hw_master.c and twi_sw_master.c are legacy drivers. There has been a lot of confusion around these drivers as they have changed a bit over time to accommodate for a few erratas found in the 1st and 2nd revision of the nRF51. I'm not sure what chip revision is on your particular beacon, but you can compare the chip markings with the compatibility matrix to find out.

    If you have the 3rd revision IC then you should use the new TWI drviers found in SDK 9. They are the ones called nrf_drv_twi.c. Here is a "getting started example" for these drivers.

    I'm not really sure if I understand your last question, but you will need to write to registers to set up and start up the MPU. And you will basically need to go through the registers in the MPU data sheet one-by-one to figure out which bits in the registers to be sets. Time consuming, yes, but it needs to be done.

  • Thanks Martin. I have the PCA20006 board from Nordic and when I was trying to use SD130 I was told here that those boards have the Rev. 2. For SD130 I managed to use them as I'm in initial test of the system and not production. As you said, when I tried to look at the devzone I was very confused about which driver to use, which one works and... So, by having Rev. 2 chips:

    • Do you think the drivers and example you provided will work on Rev 2?
    • If not, is there any confirmed WORKING driver/example for Rev 2? SDK 9 still has the twi_hw_master.c drivers too, so does that mean they can be used somehow?
    • Also, did you take a look at the sd_twi_hw_master.c file that Alseth has provided? Is that useable for SDK 9?
Reply
  • Thanks Martin. I have the PCA20006 board from Nordic and when I was trying to use SD130 I was told here that those boards have the Rev. 2. For SD130 I managed to use them as I'm in initial test of the system and not production. As you said, when I tried to look at the devzone I was very confused about which driver to use, which one works and... So, by having Rev. 2 chips:

    • Do you think the drivers and example you provided will work on Rev 2?
    • If not, is there any confirmed WORKING driver/example for Rev 2? SDK 9 still has the twi_hw_master.c drivers too, so does that mean they can be used somehow?
    • Also, did you take a look at the sd_twi_hw_master.c file that Alseth has provided? Is that useable for SDK 9?
Children
No Data
Related