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

TWIS SDA and SDL can not be pulled low by TWI master

Hello

I am trying to configure your TWIS (not using the SDK) and have run into the problem that the TWI master cannot pull the SDA and SCL line low. So, the communication does not work.

Setup using:

*      nRF52832

*     NRF_TWIS1

*    Stack  V6.1.0       

 

The TWI master used provides pull-ups on SDA and SCL. It can pull the lines low and send data if it is not connected to the TWIS SDA and SDL pins. If it is connected, the lines remain high.

I tried pulling down the pins using a resistor connected to GND and it did not work. So, I assume the pins are set to output high.

I tried switching to different pins, but the problem remained the same. As soon as the pins were assigned to TWIS SDA and SDL, they could no longer be pulled low.

// Set pins for TWI slave
NRF_TWIS1->PSEL.SCL  = PIN_SCL;
NRF_TWIS1->PSEL.SDA  = PIN_SDA;

When debugging the init-function (see attachment), I found that they were working as desired up until the point I set the ENABLE register (line 80):

// Enable TWI slave device
NRF_TWIS1->ENABLE = (TWIS_ENABLE_ENABLE_Enabled << TWIS_ENABLE_ENABLE_Pos);

 

From this point on, I could no longer pull the pins low.

 

Would you have an idea, where I did something wrong?

Thank you very much in advance for any help you might provide in solving this problem.

Attachment:

#define PIN_SCL   (11UL)
#define PIN_SDA   (18UL)

// -----------------------------------------------------------------------------
void TWIS_init(
   uint8 const device_address,
   uint8 * const pTX,
   size_t const tx_size,
   uint8 const * const pRX,
   size_t const rx_size)
{
   
   // Disable TWI slave device
   NRF_TWIS1->ENABLE = (TWIS_ENABLE_ENABLE_Disabled << TWIS_ENABLE_ENABLE_Pos);
   
   // Disconnect pins
   NRF_TWIS1->PSEL.SCL = 0xFFFFFFFFUL;
   NRF_TWIS1->PSEL.SDA = 0xFFFFFFFFUL;

   // Disable and clear the TWI slave interrupt
   NVIC_DisableIRQ(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn);
   NVIC_ClearPendingIRQ(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn);

   // Clear all interrupts
   NRF_TWIS1->INTENCLR = 0xFFFFFFFFUL;
   
   // Enable pull-up
   gpGPIO->PIN_CNF[PIN_SCL] = INPUT_PULLUP_SENSENO;
   gpGPIO->PIN_CNF[PIN_SDA] = INPUT_PULLUP_SENSENO;

   // Store the pointers to TX and RX buffer
   gpTX = pTX;
   gpRX = pRX;
   gTX_size = tx_size;

   // Set pins for TWI slave
   NRF_TWIS1->PSEL.SCL  = PIN_SCL;
   NRF_TWIS1->PSEL.SDA  = PIN_SDA;

   // Set slave address 0,1
   NRF_TWIS1->ADDRESS[0] = (uint32)device_address;
   NRF_TWIS1->ADDRESS[1] = (uint32)device_address;
   // Enable address matching for slave address 0
   NRF_TWIS1->CONFIG = (TWIS_CONFIG_ADDRESS0_Enabled << TWIS_CONFIG_ADDRESS0_Pos);
   // Enable address matching for slave address 1
   NRF_TWIS1->CONFIG |= (TWIS_CONFIG_ADDRESS1_Enabled << TWIS_CONFIG_ADDRESS1_Pos);

   // Set the overread character
   NRF_TWIS1->ORC = ORC_TX_CHAR;

   // Set the TX and RX buffers
   // -> TXD.MAXCNT is set every time when an answer is copied into TX buffer
   NRF_TWIS1->TXD.PTR = ptr_to_addr(gpTX);
   NRF_TWIS1->RXD.PTR = ptr_to_addr(gpRX);
   NRF_TWIS1->RXD.MAXCNT = rx_size;
   NRF_TWIS1->TXD.MAXCNT = 0;

   // Clear all possible pending events
   NRF_TWIS1->EVENTS_STOPPED = 0;
   NRF_TWIS1->EVENTS_ERROR = 0;
   NRF_TWIS1->EVENTS_RXSTARTED = 0;
   NRF_TWIS1->EVENTS_TXSTARTED = 0;
   NRF_TWIS1->EVENTS_READ = 0;
   NRF_TWIS1->EVENTS_WRITE = 0;

   // Clear all interrupts
   NRF_TWIS1->INTENCLR = 0xFFFFFFFFUL;

   // Enable interrupt for the STOPPED event
   NRF_TWIS1->INTENSET = (TWIS_INTENSET_STOPPED_Enabled << TWIS_INTENSET_STOPPED_Pos);

   // Enable the IRQ for the TWI slave unit
   NVIC_SetPriority(
      SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn,
      (uint32)APP_IRQ_PRIORITY_HIGH);
   NVIC_ClearPendingIRQ(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn);
   NVIC_EnableIRQ(SPIM1_SPIS1_TWIM1_TWIS1_SPI1_TWI1_IRQn);

   // Enable TWI slave device
   NRF_TWIS1->ENABLE = (TWIS_ENABLE_ENABLE_Enabled << TWIS_ENABLE_ENABLE_Pos);
}

Parents
  • I do not see anything else in the configuration apart from the GPIO configuration before enabling the TWIS.

    Try to set both the pins to below configuration before enabling the TWIS

     NRF_GPIO_PIN_DIR_INPUT,  NRF_GPIO_PIN_INPUT_CONNECT,  NRF_GPIO_PIN_PULLUP, \
                                                      NRF_GPIO_PIN_S0D1,  NRF_GPIO_PIN_NOSENSE)
Reply
  • I do not see anything else in the configuration apart from the GPIO configuration before enabling the TWIS.

    Try to set both the pins to below configuration before enabling the TWIS

     NRF_GPIO_PIN_DIR_INPUT,  NRF_GPIO_PIN_INPUT_CONNECT,  NRF_GPIO_PIN_PULLUP, \
                                                      NRF_GPIO_PIN_S0D1,  NRF_GPIO_PIN_NOSENSE)
Children
Related