This post is older than 2 years and might not be relevant anymore
More Info: Consider searching for newer posts

TWI communication between two nrf52 device

Hi,

I am trying to extablish TWI communication between 2 nRF52832 devices. One should be master and other slave.

For TWI initialization in nRF52 master, I have below source code:

void twi_init(void)
{

ret_code_t err;

const nrf_drv_twi_config_t twi_config = {
.scl = 25,
.sda = 18,
.frequency = NRF_TWI_FREQ_100K,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH,
.clear_bus_init = false
};

err = nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL);
APP_ERROR_CHECK(err);

nrf_drv_twi_enable(&m_twi);

}

For TWI initialization in nRF52 slave, I have below source code:

void twi_slave_init(void)
{
ret_code_t err;

const nrf_drv_twis_config_t slave_twi_config = {
.addr = {0x44, 0},
.scl = 25,
.scl_pull = NRF_GPIO_PIN_PULLUP,
.sda = 18,
.sda_pull = NRF_GPIO_PIN_PULLUP,
.interrupt_priority = APP_IRQ_PRIORITY_HIGH
};

err = nrf_drv_twis_init(&slave_twi, &slave_twi_config, NULL);
APP_ERROR_CHECK(err);

nrf_drv_twis_enable(&slave_twi);

}

I try to run twi_scanner in nrf52 master, but could not find nrf52 slave device.

Do I need to pullup I2C address pins also in nRF52 slave device?

Can you suggest if above way is correct?

Parents
  • I2C always needs pullups - it is an inherent part of the way the bus works!

    https://www.nxp.com/docs/en/user-guide/UM10204.pdf

    I would strongly suggest that you don't try to do both Slave and Master at the same time! Because then you have no idea whether the problem is in your Slave, or in your Master, or in both!

    Since being that Master is by far the commonest use case for a Microcontroller, I suggest that you start with that; get it talking to some standard I2C peripheral.

    Make sure you thoroughly test & debug your Master to cope with common problems such as no ACK, unexpected NAK, no pullups, etc

    Make sure you carefully instrument your Master to report problems such as no ACK, unexpected NAK, no pullups, etc.

    You will need an oscilloscope and/or analyser so that you can see what is happening on the I2C lines.

    Study the SDK examples.

    how to properly post source code:

Reply
  • I2C always needs pullups - it is an inherent part of the way the bus works!

    https://www.nxp.com/docs/en/user-guide/UM10204.pdf

    I would strongly suggest that you don't try to do both Slave and Master at the same time! Because then you have no idea whether the problem is in your Slave, or in your Master, or in both!

    Since being that Master is by far the commonest use case for a Microcontroller, I suggest that you start with that; get it talking to some standard I2C peripheral.

    Make sure you thoroughly test & debug your Master to cope with common problems such as no ACK, unexpected NAK, no pullups, etc

    Make sure you carefully instrument your Master to report problems such as no ACK, unexpected NAK, no pullups, etc.

    You will need an oscilloscope and/or analyser so that you can see what is happening on the I2C lines.

    Study the SDK examples.

    how to properly post source code:

Children
Related