Skip to content

Commit 735055b

Browse files
committed
RP2040: i2c: fix addressing mismatch
1 parent 8eb2f86 commit 735055b

File tree

1 file changed

+11
-2
lines changed
  • targets/TARGET_RASPBERRYPI/TARGET_RP2040

1 file changed

+11
-2
lines changed

targets/TARGET_RASPBERRYPI/TARGET_RP2040/i2c_api.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void i2c_frequency(i2c_t *obj, int hz)
4848
int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
4949
{
5050
int const bytes_read = i2c_read_blocking(obj->dev,
51-
(uint8_t)address,
51+
(uint8_t)(address >> 1),
5252
(uint8_t *)data,
5353
(size_t)length,
5454
/* nostop = */(stop == 0));
@@ -60,8 +60,17 @@ int i2c_read(i2c_t *obj, int address, char *data, int length, int stop)
6060

6161
int i2c_write(i2c_t *obj, int address, const char *data, int length, int stop)
6262
{
63+
if (length == 0) {
64+
// From pico-sdk:
65+
// static int i2c_write_blocking_internal(i2c_inst_t *i2c, uint8_t addr, const uint8_t *src, size_t len, bool nostop,
66+
// Synopsys hw accepts start/stop flags alongside data items in the same
67+
// FIFO word, so no 0 byte transfers.
68+
// invalid_params_if(I2C, len == 0);
69+
length = 1;
70+
}
71+
6372
int const bytes_written = i2c_write_blocking(obj->dev,
64-
address,
73+
address >> 1,
6574
(const uint8_t *)data,
6675
(size_t)length,
6776
/* nostop = */(stop == 0));

0 commit comments

Comments
 (0)