1 2 Previous Next 18 Replies Latest reply on Nov 14, 2015 5:19 PM by SanderB

    Changing the I2C Frequency

    williamh

      I've tried changing the I2C clock frequency using the mraa library (mraa_i2c_frequency) but nothing I do seems to have any effect on the frequency as viewed on an oscilloscope, it always seems to be around ~330Khz. Does the mraa call work on the edison? If not is there some other way to change the frequency (kernel module parameter, etc)?

       

      I've tried several values to mraa_i2c_frequency, and I've tried calling it right after initialization, before every call, etc. I've also updated libmraa a few times to the latest version with opkg update/upgrade.

        • 1. Re: Changing the I2C Frequency
          ovicin

          I think that also in my case the frequency changing is not working. I dont't have an osciloscope to check it but I have 2 devices connected on the same channel, with one of them I have communication but with the other one no, so I am suspecting that the frequency is too big for one of them, I tried to set it to 100kHz using mraa but there was no succes in getting some valid data from the second device.

          • 2. Re: Changing the I2C Frequency
            ovicin

            It seems that the mraa doesn't support the changing of the I2C frequency and this should be done at kernel level but for the moment I don't know how.

            The module responsible for i2c is i2c-designware-*

            • 3. Re: Changing the I2C Frequency
              Intel_Alvarado

              Were the previous suggestions helpful? If you still need assistance please reply with your questions.

              Regards

              Sergio

              • 4. Re: Changing the I2C Frequency
                Zahid

                The I2C module can operate in the following modes:

                • Standard mode (with data rates up to 100Kb/s),
                • Fast mode (with data rates up to 400Kb/s),
                • High-speed mode (with data rates up to 3.4Mb/s).

                 

                  Please try the below steps to modify the I2C bus frequency:

                 

                1. Configure the Linux kernel using  ( bitbake virtual/kernel -c menuconfig  ) and enable  CONFIG_I2C_DW_SPEED_MODE_DEBUG flag. This can be found under “Device Drivers  -> I2C support   -> I2C Hardware Bus support   -> Synopsys DesignWare Controller”
                2. Rebuild the Linux kernel after enabling the above flag using  “bitbake linux-yocto -c compile -f”
                3. Rebuild the Edison image (bitbake edison-image) and flash the new binaries using flashall.sh script.
                4. Once the binary is flashed , login to Edison and write “std” to  < /sys/devices/pci0000:00/0000:00:09.1/i2c_dw_sysnode/mode > file.

                 

                root@edison:/sys/devices/pci0000:00/0000:00:09.1/i2c_dw_sysnode# echo std > mode
                root@edison:/sys/devices/pci0000:00/0000:00:09.1/i2c_dw_sysnode#
                root@edison:/sys/devices/pci0000:00/0000:00:09.1/i2c_dw_sysnode#
                root@edison:/sys/devices/pci0000:00/0000:00:09.1/i2c_dw_sysnode# cat mode
                std

                 

                Now the i2C bus would be configured with Standard mode.

                Supported modes are: std, fast, high

                1 of 1 people found this helpful
                • 5. Re: Changing the I2C Frequency
                  arfoll

                  Zahid is correct, this is the best way. Libmraa will support this if the kernel is build correctly in the future. However for now mraa_set_frequency will return MRAA_FEATURE_NOT_IMPLEMENTED or similar and not MRAA_SUCCESS. Check your return codes

                  • 6. Re: Changing the I2C Frequency
                    Nag

                    Hi Zahid,

                     

                    When I am enabling  CONFIG_I2C_DW_SPEED_MODE_DEBUG flag,I am getting kernel crash.

                     

                     

                    Starting kernel ...

                     

                    [    0.768955] BUG: spinlock bad magic on CPU#0, swapper/0/1

                    [    0.769043]  lock: 0xf5c15024, .magic: 00000000, .owner: /-1913893493, .owner_cpu: -1050600064

                    [    0.769123] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.10.17-poky-edison+ #2

                    [    0.769183] Hardware name: Intel Corporation Merrifield/BODEGA BAY, BIOS 466 2014.06.23:19.20.05

                    [    0.769252]  c16121e0 c16121e0 f6c37a00 c1861950 f6c37a2c c18619e7 c1a5d710 f5c15024

                    [    0.769368]  00000000 c16124e0 8dec4d8b c1611d80 f5c15024 c1a5cbde f5c15024 f6c37a3c

                    [    0.769479]  c1861a0a f5c15024 f5c15024 f6c37a58 c14bbfd9 f73efa90 c126bd7b 00000282

                    [    0.769590] Call Trace:

                    [    0.769640]  [<c16121e0>] ? vlv2_i2c_scl_cfg+0x80/0x80

                    [    0.769697]  [<c16121e0>] ? vlv2_i2c_scl_cfg+0x80/0x80

                    [    0.769759]  [<c1861950>] dump_stack+0x16/0x18

                    [    0.769813]  [<c18619e7>] spin_dump+0x95/0x9d

                    [    0.769867]  [<c16124e0>] ? i2c_dw_xfer_msg+0x130/0x2b0

                    [    0.769924]  [<c1611d80>] ? i2c_gpio_setsda_dir+0x30/0x30

                    [    0.769984]  [<c1861a0a>] spin_bug+0x1b/0x1f

                    [    0.770039]  [<c14bbfd9>] do_raw_spin_lock+0x119/0x120

                    [    0.770100]  [<c126bd7b>] ? update_rq_clock.part.74+0x1b/0x150

                    [    0.770164]  [<c1866bd5>] _raw_spin_lock_irqsave+0x25/0x30

                    [    0.770226]  [<c12654d3>] down+0x13/0x40

                    [    0.770275]  [<c161317c>] i2c_dw_xfer+0x3c/0x5a0

                    [    0.770331]  [<c12c5821>] ? tracing_is_on+0x11/0x30

                    [    0.770392]  [<c160d785>] __i2c_transfer+0x55/0x70

                    [    0.770449]  [<c160e56d>] i2c_transfer+0x4d/0xc0

                    [    0.770503]  [<c1271e1d>] ? __enqueue_entity+0x6d/0x80

                    [    0.770562]  [<c160e8a2>] i2c_smbus_xfer+0x222/0x5d0

                    [    0.770621]  [<c14b37d6>] ? vsnprintf+0x166/0x390

                    [    0.770678]  [<c14b392c>] ? vsnprintf+0x2bc/0x390

                    [    0.770735]  [<c14ab0c7>] ? idr_get_empty_slot+0x147/0x370

                    [    0.770798]  [<c160ef1b>] i2c_smbus_read_word_data+0x3b/0x50

                    [    0.770862]  [<c1866ca6>] ? _raw_spin_unlock_irqrestore+0x26/0x50

                    [    0.770925]  [<c1561458>] ? devres_add+0x38/0x40

                    [    0.770981]  [<c14cfa9e>] pca953x_read_regs.isra.5+0x2e/0xd0

                    [    0.771042]  [<c1262e64>] ? __mutex_init+0x44/0x50

                    [    0.771098]  [<c14cff62>] pca953x_probe+0x1b2/0x4b0

                    [    0.771156]  [<c1373e2c>] ? sysfs_do_create_link_sd+0xac/0x1d0

                    [    0.771222]  [<c160da89>] i2c_device_probe+0x99/0x110

                    [    0.771278]  [<c1373f72>] ? sysfs_create_link+0x22/0x40

                    [    0.771337]  [<c14cfdb0>] ? pca953x_irq_handler+0x270/0x270

                    [    0.771398]  [<c155e1aa>] ? driver_sysfs_add+0x5a/0x80

                    [    0.771456]  [<c155ea60>] ? driver_probe_device+0x360/0x360

                    [    0.771517]  [<c155e779>] driver_probe_device+0x79/0x360

                    [    0.771576]  [<c155ea60>] ? driver_probe_device+0x360/0x360

                    [    0.771637]  [<c155ea60>] ? driver_probe_device+0x360/0x360

                    [    0.771697]  [<c155ea91>] __device_attach+0x31/0x40

                    [    0.771754]  [<c155cc47>] bus_for_each_drv+0x47/0x80

                    [    0.771811]  [<c155e693>] device_attach+0x73/0x90

                    [    0.771865]  [<c155ea60>] ? driver_probe_device+0x360/0x360

                    [    0.771926]  [<c155dbaf>] bus_probe_device+0x6f/0x90

                    [    0.771982]  [<c155c165>] device_add+0x5a5/0x680

                    [    0.772037]  [<c1269748>] ? complete_all+0x48/0x50

                    [    0.772096]  [<c15698ad>] ? pm_runtime_init+0xcd/0xe0

                    [    0.772154]  [<c155c257>] device_register+0x17/0x20

                    [    0.772208]  [<c160f5c8>] i2c_new_device+0x128/0x1c0

                    [    0.772267]  [<c155f788>] ? class_compat_create_link+0x48/0x80

                    [    0.772329]  [<c160fb27>] i2c_register_adapter+0x1d7/0x310

                    [    0.772389]  [<c160fd19>] i2c_add_numbered_adapter+0x59/0x90

                    [    0.772450]  [<c1613092>] i2c_dw_setup+0x272/0x320

                    [    0.772507]  [<c1613a21>] i2c_dw_pci_probe+0xa1/0x1d0

                    [    0.772566]  [<c1866ca6>] ? _raw_spin_unlock_irqrestore+0x26/0x50

                    [    0.772632]  [<c14db27f>] pci_device_probe+0x6f/0xb0

                    [    0.772691]  [<c155e779>] driver_probe_device+0x79/0x360

                    [    0.772751]  [<c155eb11>] __driver_attach+0x71/0x80

                    [    0.772807]  [<c155eaa0>] ? __device_attach+0x40/0x40

                    [    0.772863]  [<c155cba7>] bus_for_each_dev+0x47/0x80

                    [    0.772921]  [<c155e28e>] driver_attach+0x1e/0x20

                    [    0.772975]  [<c155eaa0>] ? __device_attach+0x40/0x40

                    [    0.773031]  [<c155debf>] bus_add_driver+0x1cf/0x290

                    [    0.773089]  [<c14daee0>] ? pci_pm_suspend+0x1b0/0x1b0

                    [    0.773147]  [<c14daee0>] ? pci_pm_suspend+0x1b0/0x1b0

                    [    0.773205]  [<c155f0ba>] driver_register+0x6a/0x130

                    [    0.773260]  [<c18644ed>] ? mutex_unlock+0xd/0x10

                    [    0.773317]  [<c160e0f8>] ? i2c_for_each_dev+0x38/0x50

                    [    0.773377]  [<c1bd2ab2>] ? i2c_gpio_init+0x2e/0x2e

                    [    0.773433]  [<c14da4ea>] __pci_register_driver+0x4a/0x50

                    [    0.773493]  [<c1bd2ac6>] dw_i2c_init_driver+0x14/0x16

                    [    0.773550]  [<c120017a>] do_one_initcall+0xaa/0x160

                    [    0.773611]  [<c1b9bb46>] kernel_init_freeable+0x135/0x1fc

                    [    0.773670]  [<c1b9b4e0>] ? do_early_param+0x78/0x78

                    [    0.773727]  [<c186a405>] ? sub_preempt_count+0x55/0xe0

                    [    0.773787]  [<c1866ced>] ? _raw_spin_unlock_irq+0x1d/0x40

                    [    0.773847]  [<c1269ebe>] ? finish_task_switch+0x4e/0xa0

                    [    0.773909]  [<c184e450>] kernel_init+0x10/0x140

                    [    0.773963]  [<c186c277>] ret_from_kernel_thread+0x1b/0x28

                    [    0.774022]  [<c184e440>] ? rest_init+0x80/0x80

                    [    0.774068] ------------[ cut here ]------------

                    [    0.774121] WARNING: at /home/anapc12/Edison/edison-src/build/tmp/work/edison-poky-linux/linux-yocto/3.10.17+gitAUTOINC+6ad20f049a)

                    [    0.774244] list_add corruption. prev->next should be next (f5c15038), but was 00000001. (prev=c1b5f138).

                    [    0.774314] Modules linked in:

                    [    0.774358] CPU: 0 PID: 1 Comm: swapper/0 Not tainted 3.10.17-poky-edison+ #2

                    [    0.774417] Hardware name: Intel Corporation Merrifield/BODEGA BAY, BIOS 466 2014.06.23:19.20.05

                    [    0.774484]  f6c379f8 f6c379f8 f6c379c0 c1861950 f6c379e8 c123e79e c1a5d898 f6c37a14

                    [    0.774594]  00000021 c14bc54e c14bc54e 00000001 f5c15024 f6c80000 f6c37a00 c123e7f3

                    [    0.774703]  00000009 f6c379f8 c1a5d898 f6c37a14 f6c37a30 c14bc54e c1a5d808 00000021

                    [    0.774813] Call Trace:

                    [    0.774858]  [<c1861950>] dump_stack+0x16/0x18

                    [    0.774915]  [<c123e79e>] warn_slowpath_common+0x5e/0x80

                    [    0.774974]  [<c14bc54e>] ? __list_add+0xde/0xf0

                    [    0.775026]  [<c14bc54e>] ? __list_add+0xde/0xf0

                    [    0.775082]  [<c123e7f3>] warn_slowpath_fmt+0x33/0x40

                    [    0.775139]  [<c14bc54e>] __list_add+0xde/0xf0

                    [    0.775194]  [<c1864bf9>] __down_common+0x25/0xae

                    [    0.775251]  [<c126bd7b>] ? update_rq_clock.part.74+0x1b/0x150

                    [    0.775313]  [<c1864c99>] __down+0x17/0x19

                    [    0.775364]  [<c12654f9>] down+0x39/0x40

                    [    0.775414]  [<c161317c>] i2c_dw_xfer+0x3c/0x5a0

                    [    0.775469]  [<c12c5821>] ? tracing_is_on+0x11/0x30

                    [    0.775528]  [<c160d785>] __i2c_transfer+0x55/0x70

                    [    0.775585]  [<c160e56d>] i2c_transfer+0x4d/0xc0

                    [    0.775638]  [<c1271e1d>] ? __enqueue_entity+0x6d/0x80

                    [    0.775698]  [<c160e8a2>] i2c_smbus_xfer+0x222/0x5d0

                    [    0.775756]  [<c14b37d6>] ? vsnprintf+0x166/0x390

                    [    0.775812]  [<c14b392c>] ? vsnprintf+0x2bc/0x390

                    [    0.775869]  [<c14ab0c7>] ? idr_get_empty_slot+0x147/0x370

                    [    0.775932]  [<c160ef1b>] i2c_smbus_read_word_data+0x3b/0x50

                    [    0.775996]  [<c1866ca6>] ? _raw_spin_unlock_irqrestore+0x26/0x50

                    [    0.776058]  [<c1561458>] ? devres_add+0x38/0x40

                    [    0.776113]  [<c14cfa9e>] pca953x_read_regs.isra.5+0x2e/0xd0

                    [    0.776174]  [<c1262e64>] ? __mutex_init+0x44/0x50

                    [    0.776231]  [<c14cff62>] pca953x_probe+0x1b2/0x4b0

                    [    0.776287]  [<c1373e2c>] ? sysfs_do_create_link_sd+0xac/0x1d0

                    [    0.776353]  [<c160da89>] i2c_device_probe+0x99/0x110

                    [    0.776409]  [<c1373f72>] ? sysfs_create_link+0x22/0x40

                    [    0.776468]  [<c14cfdb0>] ? pca953x_irq_handler+0x270/0x270

                    [    0.776528]  [<c155e1aa>] ? driver_sysfs_add+0x5a/0x80

                    [    0.776587]  [<c155ea60>] ? driver_probe_device+0x360/0x360

                    [    0.776647]  [<c155e779>] driver_probe_device+0x79/0x360

                    [    0.776707]  [<c155ea60>] ? driver_probe_device+0x360/0x360

                    [    0.776768]  [<c155ea60>] ? driver_probe_device+0x360/0x360

                    [    0.776828]  [<c155ea91>] __device_attach+0x31/0x40

                    [    0.776883]  [<c155cc47>] bus_for_each_drv+0x47/0x80

                    [    0.776940]  [<c155e693>] device_attach+0x73/0x90

                    [    0.776995]  [<c155ea60>] ? driver_probe_device+0x360/0x360

                    [    0.777056]  [<c155dbaf>] bus_probe_device+0x6f/0x90

                    [    0.777112]  [<c155c165>] device_add+0x5a5/0x680

                    [    0.777167]  [<c1269748>] ? complete_all+0x48/0x50

                    [    0.777225]  [<c15698ad>] ? pm_runtime_init+0xcd/0xe0

                    [    0.777283]  [<c155c257>] device_register+0x17/0x20

                    [    0.777337]  [<c160f5c8>] i2c_new_device+0x128/0x1c0

                    [    0.777396]  [<c155f788>] ? class_compat_create_link+0x48/0x80

                    [    0.777457]  [<c160fb27>] i2c_register_adapter+0x1d7/0x310

                    [    0.777518]  [<c160fd19>] i2c_add_numbered_adapter+0x59/0x90

                    [    0.777579]  [<c1613092>] i2c_dw_setup+0x272/0x320

                    [    0.777636]  [<c1613a21>] i2c_dw_pci_probe+0xa1/0x1d0

                    [    0.777695]  [<c1866ca6>] ? _raw_spin_unlock_irqrestore+0x26/0x50

                    [    0.777761]  [<c14db27f>] pci_device_probe+0x6f/0xb0

                    [    0.777819]  [<c155e779>] driver_probe_device+0x79/0x360

                    [    0.777879]  [<c155eb11>] __driver_attach+0x71/0x80

                    [    0.777936]  [<c155eaa0>] ? __device_attach+0x40/0x40

                    [    0.777992]  [<c155cba7>] bus_for_each_dev+0x47/0x80

                    [    0.778049]  [<c155e28e>] driver_attach+0x1e/0x20

                    [    0.778103]  [<c155eaa0>] ? __device_attach+0x40/0x40

                    [    0.778160]  [<c155debf>] bus_add_driver+0x1cf/0x290

                    [    0.778218]  [<c14daee0>] ? pci_pm_suspend+0x1b0/0x1b0

                    [    0.778276]  [<c14daee0>] ? pci_pm_suspend+0x1b0/0x1b0

                    [    0.778333]  [<c155f0ba>] driver_register+0x6a/0x130

                    [    0.778389]  [<c18644ed>] ? mutex_unlock+0xd/0x10

                    [    0.778445]  [<c160e0f8>] ? i2c_for_each_dev+0x38/0x50

                    [    0.778503]  [<c1bd2ab2>] ? i2c_gpio_init+0x2e/0x2e

                    [    0.778560]  [<c14da4ea>] __pci_register_driver+0x4a/0x50

                    [    0.778619]  [<c1bd2ac6>] dw_i2c_init_driver+0x14/0x16

                    [    0.778676]  [<c120017a>] do_one_initcall+0xaa/0x160

                    [    0.778735]  [<c1b9bb46>] kernel_init_freeable+0x135/0x1fc

                    [    0.778795]  [<c1b9b4e0>] ? do_early_param+0x78/0x78

                    [    0.778852]  [<c186a405>] ? sub_preempt_count+0x55/0xe0

                    [    0.778912]  [<c1866ced>] ? _raw_spin_unlock_irq+0x1d/0x40

                    [    0.778972]  [<c1269ebe>] ? finish_task_switch+0x4e/0xa0

                    [    0.779032]  [<c184e450>] kernel_init+0x10/0x140

                    [    0.779086]  [<c186c277>] ret_from_kernel_thread+0x1b/0x28

                    [    0.779145]  [<c184e440>] ? rest_init+0x80/0x80

                    [    0.779217] ---[ end trace aad2aa43e78e38c3 ]---

                    [    1.513320] Switching to clocksource tsc

                    • 7. Re: Changing the I2C Frequency
                      Nag

                      Hi Zahid,

                       

                      I have successfully updated i2c frequency by following the steps given by you in your previous post.Please  ignore my previous  post.

                       

                       

                      Thanks,


                      • 8. Re: Changing the I2C Frequency
                        arfoll

                        If you want try the i2cfreq branch of libmraa which should let you do it from mraa_set_frequency intel-iot-devkit/mraa at i2cfreq · GitHub. Once rebased and tested a bit more I'll push it to master and you can grab it from opkg.

                        • 9. Re: Changing the I2C Frequency
                          freshbird

                          Hi, i rebuild the Edison-image. and i don't have the <i2c_dw_sysnode> direction and <mode> file, i'm sure that 

                          “Device Drivers  -> I2C support   -> I2C Hardware Bus support   -> Synopsys DesignWare Controller” is selected .but i don't know CONFIG_I2C_DW_SPEED_MODE_DEBUG in where..would you mind giving me some advise?

                          • 10. Re: Changing the I2C Frequency
                            ovicin

                            I also had problems in seeing the option first, but it is there, take a second look, you are looking in the right place.

                            • 11. Re: Changing the I2C Frequency
                              freshbird

                              yes,i found that flag.and i success slow down the i2c frequency..

                              but it can't solve the problem about multiple i2c sensor..it can't work well if i connect two sensors.do you have any advise?

                              • 12. Re: Changing the I2C Frequency
                                Intel_Alvarado

                                Hi freshbird,

                                 

                                Were you able to solve this issue? In case you haven’t I posted a suggestion for you in this other link how to enable I2C1? for multiple i2C devices.

                                 

                                Regards

                                Sergio

                                • 13. Re: Changing the I2C Frequency
                                  freshbird

                                  yeah, i still have the problem with multiple i2c devices..maybe you can post a suggestion for me .thx.

                                  • 14. Re: Changing the I2C Frequency
                                    MiguelAngelLV

                                    When I try change the i2c's speed, I get MRAA_ERROR_FEATURE_NOT_SUPPORTED. I have activate the module in the kernel and use the lastest version of MRAA. This is my code;


                                    impl->i2c = new I2c(UBLOX_BUS);

                                    mraa_result_t result = impl->i2c->frequency(400000);

                                     

                                     

                                    And the cat of module mode:

                                     

                                    root@edison:/sys/devices/pci0000:00/0000:00:09.1# cat i2c_dw_sysnode/mode

                                    high

                                    1 2 Previous Next