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

Where is the structure definition inside the sdk for peripheral registers structure used in the two wire interface api functions?

Hi everyone,

I was just going through the library functions provided here in this link : nordic functions twi

But inside all these functions ,there is this parameter which is a pointer to a structure of this format : 

NRF_TWI_Type *  p_reg

Can anyone tell me where i can find the elements that needs to be stored inside this structure ? or give me any idea on how to declare and define this structure?

Thanks!

Rajat

Parents
  • Hi,

    NRF_TWI_Type * is a pointer to a structure with TWI registers. If you are using nRF52832 you will find the definition of the structure in a file called nrf52.h. This is what the structure looks like in SDK 15:

    /**
      * @brief I2C compatible Two-Wire Interface 0 (TWI)
      */
    
    typedef struct {                                    /*!< TWI Structure                                                         */
      __O  uint32_t  TASKS_STARTRX;                     /*!< Start TWI receive sequence                                            */
      __I  uint32_t  RESERVED0;
      __O  uint32_t  TASKS_STARTTX;                     /*!< Start TWI transmit sequence                                           */
      __I  uint32_t  RESERVED1[2];
      __O  uint32_t  TASKS_STOP;                        /*!< Stop TWI transaction                                                  */
      __I  uint32_t  RESERVED2;
      __O  uint32_t  TASKS_SUSPEND;                     /*!< Suspend TWI transaction                                               */
      __O  uint32_t  TASKS_RESUME;                      /*!< Resume TWI transaction                                                */
      __I  uint32_t  RESERVED3[56];
      __IO uint32_t  EVENTS_STOPPED;                    /*!< TWI stopped                                                           */
      __IO uint32_t  EVENTS_RXDREADY;                   /*!< TWI RXD byte received                                                 */
      __I  uint32_t  RESERVED4[4];
      __IO uint32_t  EVENTS_TXDSENT;                    /*!< TWI TXD byte sent                                                     */
      __I  uint32_t  RESERVED5;
      __IO uint32_t  EVENTS_ERROR;                      /*!< TWI error                                                             */
      __I  uint32_t  RESERVED6[4];
      __IO uint32_t  EVENTS_BB;                         /*!< TWI byte boundary, generated before each byte that is sent or
                                                             received                                                              */
      __I  uint32_t  RESERVED7[3];
      __IO uint32_t  EVENTS_SUSPENDED;                  /*!< TWI entered the suspended state                                       */
      __I  uint32_t  RESERVED8[45];
      __IO uint32_t  SHORTS;                            /*!< Shortcut register                                                     */
      __I  uint32_t  RESERVED9[64];
      __IO uint32_t  INTENSET;                          /*!< Enable interrupt                                                      */
      __IO uint32_t  INTENCLR;                          /*!< Disable interrupt                                                     */
      __I  uint32_t  RESERVED10[110];
      __IO uint32_t  ERRORSRC;                          /*!< Error source                                                          */
      __I  uint32_t  RESERVED11[14];
      __IO uint32_t  ENABLE;                            /*!< Enable TWI                                                            */
      __I  uint32_t  RESERVED12;
      __IO uint32_t  PSELSCL;                           /*!< Pin select for SCL                                                    */
      __IO uint32_t  PSELSDA;                           /*!< Pin select for SDA                                                    */
      __I  uint32_t  RESERVED13[2];
      __I  uint32_t  RXD;                               /*!< RXD register                                                          */
      __IO uint32_t  TXD;                               /*!< TXD register                                                          */
      __I  uint32_t  RESERVED14;
      __IO uint32_t  FREQUENCY;                         /*!< TWI frequency                                                         */
      __I  uint32_t  RESERVED15[24];
      __IO uint32_t  ADDRESS;                           /*!< Address used in the TWI transfer                                      */
    } NRF_TWI_Type;

    You can see how it lines up the actual TWI peripheral registers

  • Thanks a lot!

    Can you please tell me how to set the pin number?

    can we write directly like scl=11;

    sda=13;

    and use them inside the function to set the pins?

    or we need to proceed in some other way?

  • I suggest that you use the TWI drivers in the SDK and follow the documentation as well as having a look at the simple TWI examples, like the TWI Scanner example, to see how it can be configured. In this example the TWI pins are configured like this:

    void twi_init (void)
    {
        ret_code_t err_code;
    
        const nrf_drv_twi_config_t twi_config = {
           .scl                = scl_pin,
           .sda                = sda_pin,
           .frequency          = NRF_DRV_TWI_FREQ_100K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
           .clear_bus_init     = false
        };
    
        err_code = nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_twi_enable(&m_twi);
    }

Reply
  • I suggest that you use the TWI drivers in the SDK and follow the documentation as well as having a look at the simple TWI examples, like the TWI Scanner example, to see how it can be configured. In this example the TWI pins are configured like this:

    void twi_init (void)
    {
        ret_code_t err_code;
    
        const nrf_drv_twi_config_t twi_config = {
           .scl                = scl_pin,
           .sda                = sda_pin,
           .frequency          = NRF_DRV_TWI_FREQ_100K,
           .interrupt_priority = APP_IRQ_PRIORITY_HIGH,
           .clear_bus_init     = false
        };
    
        err_code = nrf_drv_twi_init(&m_twi, &twi_config, NULL, NULL);
        APP_ERROR_CHECK(err_code);
    
        nrf_drv_twi_enable(&m_twi);
    }

Children
No Data
Related