Adding 10-bit i2c addressing support to the SDK #721
No reviewers
Labels
No labels
bazel
bluetooth
board settings
boot_stage2
bug
build
c++
can't reproduce
clang
clib-interface
cmsis
code cleanliness
code size
compiler version issues
cyw43_driver
debug
discussion
documentation
duplicate
dynamic_clock
elf2uf2
enhancement
errata
filesystem
flash layout
floating point
FreeRTOS
hardware_adc
hardware_claim
hardware_clocks
hardware_dma
hardware_exception
hardware_flash
hardware_gpio
hardware_i2c
hardware_irq
hardware_pio
hardware_pwm
hardware_rcp
hardware_rtc
hardware_spi
hardware_sync
hardware_uart
hardware_vreg
hardware_watchdog
hardware_xosc
help wanted
host
IAR
installation
invalid
linker scripts
lto
lwip
mbedtls
missing API
needs reporter detail
networking
newlib
newlib-multicore
non-c
non-cmake
non-gcc
openocd
orphan PR
OS integration
pico_async_context
pico_base
pico_binary_info
pico_flash
picolibc
pico_lwip
pico_malloc
pico_multicore
pico_printf
pico_runtime
pico_stdio
pico_stdio_usb
pico_sync
pico_time
pico_util
pioasm
port
question
review
review2
rtos interop
runtime init
static library
svd
test
tinyusb
vscode
wifi integration
wontfix
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
gh-raspberrypi/pico-sdk!721
Loading…
Reference in a new issue
No description provided.
Delete branch "zbaltzer228/develop"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Fixes #720
Raspberry Pi Pico SDK with 10-bit i2c addressing support
As of v1.3.0 of the SDK, neither 10-bit i2c master mode nor 10-bit i2c slave mode is implemented.
The RP2040 Datasheet
suggests, in two places that I can find, that 10-bit i2c addressing is not supported in slave mode.
Introducing 10-bit i2c addressing support
In the revised i2c.h
there are 10 new functions
In the revised i2c.c
there are 3 new functions
All prototypes are identical to their non-10-bit-qualified counterparts,
except wherever there is a uint8_t addr parameter, it has been replaced with
uint16_t addr.
Their functionality is also identical, but adapted to 10-bit addressing.
Example usage is found at RP2040_10bit_i2c_host.c
and RP2040_10bit_i2c_periph.c
Overview of a 10-bit i2c transaction using the examples
RP2040_10bit_i2c_host and RP2040_10bit_i2c_periph were built using the modified SDK proposed here.
Due to the limitations of the scope used to measure the i2c bus, the transaction
will be split across 6 different pictures.
In whole, the i2c host writes 2 bytes to the bus for address 0x02CF, then asks
the device with address 0x02CF for 3 bytes in response.
The host initiates a transaction by dropping SDA while SCL is held high.
The next 5 bits are a specific sequence, 0b11110, reserved by the i2c spec to signal a 10-bit transaction,
followed by the 2 most significant bits of the 10-bit address, in this case 0x2.
The next byte delivers the rest of the 10-bit address, 0xCF.
Here, the 2 bytes are written to the bus, 0xA5 proceeded by 0x5A with the required ACK inbetween.
The host then starts a read request by transmitting the peripheral address, 0x02CF in a similar manner to Figure 3.
The R/W bit suggests a write, even though this is a read request. This is solved by
transmitting a 3rd byte with the Read bit set.
The host transmits its 3rd and final byte for the read request, this is a repeat of the first
start byte, with the reserved 0b11110 and 2 most significant bits of the periph address,
but with the Read bit set.
The peripheral then holds SDA low while it prepares to transmit its data.
The periph transmits its data and gets the required ACK, it transmits 3 bytes in total.
The first being a constant 0x5A, and the last two bytes are a counter that is incremented
each time a i2c transaction takes place.
At the end, the host has acknowledged the bytes its expects and stops driving SCL.
In conclusion
The RP2040 does, in fact, support 10-bit addressing in both host and peripheral modes.
The changes required to the SDK to fully support 10-bit addressing are provided in i2c.h
and i2c.c
addrhere is auint8_t, so it's impossible for it to be>= 0x400? (i.e. is this a typo?)You are absolutely correct - it should be uint16_t, not uint8_t on line 144.
@zbaltzer228 are you gonna fix that so we can get your feature, oooor...?
It'd be great if this could be merged, but it's worth pointing out that this line should not be uint16_t, as this is the 7-bit addressing function. This should stay as 0x80. However, I believe the
invalid_params_ifin the 10-bit function should be 0x400 instead.This PR is now so old that it has merge-conflicts which need to be resolved.
View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.