Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4873

MicroPython • Re: Pico requested vs measured I2C SCL frequency

$
0
0
I thought that perhaps the IC_FS_SCL_HCNT_1 and IC_FS_SCL_LCNT_1 values could be interposed. I would try to make the high time greater than the low time (opposite to what MicroPython calculates).

Code:

import machinefrom machine import mem32CLOCKS_BASE      = 0x40008000I2C0_BASE        = 0x40044000I2C1_BASE        = 0x40048000IC_CON_0         = I2C0_BASE   + 0x00IC_CON_1         = I2C1_BASE   + 0x00IC_ENABLE_0      = I2C0_BASE   + 0x6CIC_ENABLE_1      = I2C1_BASE   + 0x6CIC_FS_SCL_HCNT_0 = I2C0_BASE   + 0x1CIC_FS_SCL_HCNT_1 = I2C1_BASE   + 0x1CIC_FS_SCL_LCNT_0 = I2C0_BASE   + 0x20IC_FS_SCL_LCNT_1 = I2C1_BASE   + 0x20i2c = machine.I2C(1,sda=machine.Pin(2),scl=machine.Pin(3),freq=400000)print("IC_FS_SCL_HCNT_1 is {:d}".format(mem32[IC_FS_SCL_HCNT_1] & 0x0000FFFF)) # lower 16bitsprint("IC_FS_SCL_LCNT_1 is {:d}".format(mem32[IC_FS_SCL_LCNT_1] & 0x0000FFFF)) # lower 16bitsmem32[IC_ENABLE_1] = 0mem32[IC_FS_SCL_HCNT_1] = 187mem32[IC_FS_SCL_LCNT_1] = 126mem32[IC_ENABLE_1] = 1print("IC_FS_SCL_HCNT_1 is {:d}".format(mem32[IC_FS_SCL_HCNT_1] & 0x0000FFFF)) # lower 16bitsprint("IC_FS_SCL_LCNT_1 is {:d}".format(mem32[IC_FS_SCL_LCNT_1] & 0x0000FFFF)) # lower 16bits
Output is:

Code:

IC_FS_SCL_HCNT_1 is 126IC_FS_SCL_LCNT_1 is 187IC_FS_SCL_HCNT_1 is 187IC_FS_SCL_LCNT_1 is 126
This resulted in the same 250kHz SCL frequency (no different than when the low time was greater than the high time).

Statistics: Posted by chipace — Sat Mar 16, 2024 11:32 pm



Viewing all articles
Browse latest Browse all 4873

Trending Articles