Skip to content

Commit 3f7609f

Browse files
committed
NRF52840 I2C driver: Initialise I2C pins before transmission
By default D0 - D3 pins are used for the bit-banged SPI com channel between mbed target and the FPGA-test-shield. For some reason, if pins were used as GPIOs and then reconfigured to I2C pins the I2C com does not work on NRF52840. This commit modifies i2c_configure_twi_instance() function and adds proper initialization of the I2C pins.
1 parent 31e72d0 commit 3f7609f

File tree

1 file changed

+14
-0
lines changed
  • targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52

1 file changed

+14
-0
lines changed

targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/i2c_api.c

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,13 @@
5959
#include "app_util_platform.h"
6060
#include "prs/nrfx_prs.h"
6161

62+
#define TWI_PIN_INIT(_pin) nrf_gpio_cfg((_pin), \
63+
NRF_GPIO_PIN_DIR_INPUT, \
64+
NRF_GPIO_PIN_INPUT_CONNECT, \
65+
NRF_GPIO_PIN_PULLUP, \
66+
NRF_GPIO_PIN_S0D1, \
67+
NRF_GPIO_PIN_NOSENSE)
68+
6269
#if 0
6370
#define DEBUG_PRINTF(...) printf(__VA_ARGS__)
6471
#else
@@ -330,6 +337,13 @@ void i2c_configure_twi_instance(i2c_t *obj)
330337
nrf_twi_frequency_set(nordic_nrf5_twi_register[instance],
331338
config->frequency);
332339

340+
/* To secure correct signal levels on the pins used by the TWI
341+
master when the system is in OFF mode, and when the TWI master is
342+
disabled, these pins must be configured in the GPIO peripheral.
343+
*/
344+
TWI_PIN_INIT(config->scl);
345+
TWI_PIN_INIT(config->sda);
346+
333347
/* Enable TWI peripheral with new settings. */
334348
nrf_twi_enable(nordic_nrf5_twi_register[instance]);
335349
}

0 commit comments

Comments
 (0)