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

General • Re: I2C operation does not survive jump to user program

$
0
0
I2C0 is on GP16/GP17
I2C1 is on GP14/GP15

Anyways, after much pouring over the assembly code, I had the idea to connect a logic analyzer to the bus (wish I started with this!), and found that the bus had jumped to 2MHz on SCL after the branch. So this looked suspiciously like the pico SDK was not setting clocks correctly.

This is the code that fixed it.

Code:

    clock_set_reported_hz(clk_sys, 125000000);    clock_set_reported_hz(clk_ref, 12000000 );    clock_set_reported_hz(clk_usb, 48000000);    clock_set_reported_hz(clk_adc, 48000000);    clock_set_reported_hz(clk_rtc, 46875);    clock_set_reported_hz(clk_peri, 125000000);
BTW AI models just point to the sdk needing clk_peri, but it actually seems to need clk_sys too...

The values for these are just from the working code, dumped out like this:

Code:

    printf("Clock    | Hz\n");    printf("---------|------------\n");    printf("sys      | %10lu Hz\n", clock_get_hz(clk_sys));    printf("ref      | %10lu Hz\n", clock_get_hz(clk_ref));    printf("usb      | %10lu Hz\n", clock_get_hz(clk_usb));    printf("adc      | %10lu Hz\n", clock_get_hz(clk_adc));    printf("rtc      | %10lu Hz\n", clock_get_hz(clk_rtc));    printf("peri     | %10lu Hz\n", clock_get_hz(clk_peri));    printf("gpio0    | %10lu Hz\n", clock_get_hz(clk_gpout0));    printf("gpio1    | %10lu Hz\n", clock_get_hz(clk_gpout1));    printf("gpio2    | %10lu Hz\n", clock_get_hz(clk_gpout2));    printf("gpio3    | %10lu Hz\n", clock_get_hz(clk_gpout3));
It would interesting if the SDK/linker could have a way of building programs in a way that doesn't disrupt the hardware, would be useful for plugin architectures etc..

Statistics: Posted by kevin_mirrorai — Mon Oct 27, 2025 4:03 am



Viewing all articles
Browse latest Browse all 8013

Trending Articles