port set problem when using twi_sw_master.c

 Hello,

It is being developed using nrf52833, SOFTDEVICE-s140, SDK-17.1.0.

There is no problem in port-0 during I2C communication using twi_sw_master.c

,but when port-1 is used, the following warning is shown.

 

- in twi_master_config.h

#define   TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER      NRF_GPIO_PIN_MAP(1,0)   // or 32

 

- warinig when build

compiling twi_sw_master.c...
..\..\components\drivers_nrf\twi_master\deprecated\twi_sw_master.c(89): warning: #175-D: subscript out of range

WI_SCL_STANDARD0_NODRIVE1(); /*lint !e416 "Creation of out of bounds pointer" */
..\..\components\drivers_nrf\twi_master\deprecated\twi_sw_master.c(92): warning: #63-D: shift count is too large

WI_SCL_HIGH();
..\..\components\drivers_nrf\twi_master\deprecated\twi_sw_master.c(93): warning: #63-D: shift count is too large

I want to ask which part needs to be modified.

 thanks.

Parents Reply Children
  • It is still difficult to understand the exact operation because there is a problem in my custom board,

    It was confirmed that the code was corrected and the build was made without errors / warnings

    and that the SCL/SDA port level was properly reflected.

    I modified the macros in twi_sw_master.c and twi_master.h.

    The BOARD_CUSTOM part is the part I modified.

    Please check to see if there is any problem with using this.

    /////////////////////////////
    // *** twi_sw_master.c *** //
    /////////////////////////////
    #include <stdbool.h>
    #include <stdint.h>
    #include "twi_master.h"
    #include "nrf_delay.h"
    
    #ifdef BOARD_CUSTOM
    	#include "board_config.h"
        // port defined
        // TWI_MASTER_CONFIG_DATA_PIN_NUMBER - NRF_GPIO_PIN_MAP(0,24)
        // TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER - NRF_GPIO_PIN_MAP(1,0)
    #else
    	#include "twi_master_config.h"
    #endif
    
    
    #ifndef BOARD_CUSTOM
    /*lint -e415 -e845 -save "Out of bounds access" */
    #define TWI_SDA_STANDARD0_NODRIVE1() do { \
            NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_DATA_PIN_NUMBER] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
            |(GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)    \
            |(GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)  \
            |(GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \
            |(GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);  \
    } while (0) /*!< Configures SDA pin to Standard-0, No-drive 1 */
    
    
    #define TWI_SCL_STANDARD0_NODRIVE1() do { \
            NRF_GPIO->PIN_CNF[TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER] = (GPIO_PIN_CNF_SENSE_Disabled << GPIO_PIN_CNF_SENSE_Pos) \
            |(GPIO_PIN_CNF_DRIVE_S0D1 << GPIO_PIN_CNF_DRIVE_Pos)    \
            |(GPIO_PIN_CNF_PULL_Pullup << GPIO_PIN_CNF_PULL_Pos)  \
            |(GPIO_PIN_CNF_INPUT_Connect << GPIO_PIN_CNF_INPUT_Pos) \
            |(GPIO_PIN_CNF_DIR_Input << GPIO_PIN_CNF_DIR_Pos);  \
    } while (0) /*!< Configures SCL pin to Standard-0, No-drive 1 */
    
    #else
    #define TWI_SDA_STANDARD0_NODRIVE1()	nrf_gpio_cfg(TWI_MASTER_CONFIG_DATA_PIN_NUMBER,		\
    																	NRF_GPIO_PIN_DIR_INPUT,						\
    																	NRF_GPIO_PIN_INPUT_CONNECT,				\
    																	NRF_GPIO_PIN_PULLUP,							\
    																	NRF_GPIO_PIN_S0D1,							\
    																	NRF_GPIO_PIN_NOSENSE)
    
    #define TWI_SCL_STANDARD0_NODRIVE1() 	nrf_gpio_cfg(TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER,	\
    																	NRF_GPIO_PIN_DIR_INPUT,						\
    																	NRF_GPIO_PIN_INPUT_CONNECT,				\
    																	NRF_GPIO_PIN_PULLUP,							\
    																	NRF_GPIO_PIN_S0D1,							\
    																	NRF_GPIO_PIN_NOSENSE)
    #endif	// BOARD_CUSTOM
    
    
    
    //////////////////////////
    // *** twi_master.h *** //
    //////////////////////////
    #include <stdbool.h>
    #include <stdint.h>
    
    #ifdef BOARD_CUSTOM
    	#include "nrf_gpio.h"
    #endif
    
    
    #ifdef __cplusplus
    extern "C" {
    #endif
    
    /** @file
    * @brief Software controlled TWI Master driver.
    *
    *
    * @defgroup lib_driver_twi_master Software controlled TWI Master driver
    * @{
    * @ingroup nrf_twi
    * @brief Software controlled TWI Master driver (deprecated).
    *
    * @warning This module is deprecated.
    *
    * Supported features:
    * - Repeated start
    * - No multi-master
    * - Only 7-bit addressing
    * - Supports clock stretching (with optional SMBus style slave timeout)
    * - Tries to handle slaves stuck in the middle of transfer
    */
    
    #define TWI_READ_BIT                 (0x01)        //!< If this bit is set in the address field, transfer direction is from slave to master.
    
    #define TWI_ISSUE_STOP               ((bool)true)  //!< Parameter for @ref twi_master_transfer
    #define TWI_DONT_ISSUE_STOP          ((bool)false) //!< Parameter for @ref twi_master_transfer
    
    #ifndef BOARD_CUSTOM
    /* These macros are needed to see if the slave is stuck and we as master send dummy clock cycles to end its wait */
    /*lint -e717 -save "Suppress do {} while (0) for these macros" */
    /*lint ++flb "Enter library region" */
    #define TWI_SCL_HIGH()   do { NRF_GPIO->OUTSET = (1UL << TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER); } while (0)   /*!< Pulls SCL line high */
    #define TWI_SCL_LOW()    do { NRF_GPIO->OUTCLR = (1UL << TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER); } while (0)   /*!< Pulls SCL line low  */
    #define TWI_SDA_HIGH()   do { NRF_GPIO->OUTSET = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER);  } while (0)   /*!< Pulls SDA line high */
    #define TWI_SDA_LOW()    do { NRF_GPIO->OUTCLR = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER);  } while (0)   /*!< Pulls SDA line low  */
    #define TWI_SDA_INPUT()  do { NRF_GPIO->DIRCLR = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER);  } while (0)   /*!< Configures SDA pin as input  */
    #define TWI_SDA_OUTPUT() do { NRF_GPIO->DIRSET = (1UL << TWI_MASTER_CONFIG_DATA_PIN_NUMBER);  } while (0)   /*!< Configures SDA pin as output */
    #define TWI_SCL_OUTPUT() do { NRF_GPIO->DIRSET = (1UL << TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER); } while (0)   /*!< Configures SCL pin as output */
    /*lint -restore */
    
    #define TWI_SDA_READ() ((NRF_GPIO->IN >> TWI_MASTER_CONFIG_DATA_PIN_NUMBER) & 0x1UL)                     /*!< Reads current state of SDA */
    #define TWI_SCL_READ() ((NRF_GPIO->IN >> TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER) & 0x1UL)                    /*!< Reads current state of SCL */
    
    #else
    #define TWI_SCL_HIGH()		nrf_gpio_pin_set(TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER)		// Pulls SCL line high
    #define TWI_SCL_LOW()		nrf_gpio_pin_clear(TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER)	// Pulls SCL line low
    #define TWI_SDA_HIGH()		nrf_gpio_pin_set(TWI_MASTER_CONFIG_DATA_PIN_NUMBER)		// Pulls SDA line high
    #define TWI_SDA_LOW()		nrf_gpio_pin_clear(TWI_MASTER_CONFIG_DATA_PIN_NUMBER)		// Pulls SDA line low
    
    #define TWI_SDA_INPUT()		nrf_gpio_pin_dir_set(TWI_MASTER_CONFIG_DATA_PIN_NUMBER, NRF_GPIO_PIN_DIR_INPUT)		// Configures SDA pin as input 
    #define TWI_SDA_OUTPUT()	nrf_gpio_pin_dir_set(TWI_MASTER_CONFIG_DATA_PIN_NUMBER, NRF_GPIO_PIN_DIR_OUTPUT)		// Configures SDA pin as output
    #define TWI_SCL_OUTPUT()	nrf_gpio_pin_dir_set(TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER, NRF_GPIO_PIN_DIR_OUTPUT)	// Configures SCL pin as output
    
    #define TWI_SDA_READ()		nrf_gpio_pin_read(TWI_MASTER_CONFIG_DATA_PIN_NUMBER)		// Reads current state of SDA
    #define TWI_SCL_READ()		nrf_gpio_pin_read(TWI_MASTER_CONFIG_CLOCK_PIN_NUMBER)		// Reads current state of SCL
    #endif	// BOARD_CUSTOM
    
    #ifndef BOARD_CUSTOM
    	#define TWI_DELAY() nrf_delay_us(4) /*!< Time to wait when pin states are changed. For fast-mode the delay can be zero and for standard-mode 4 us delay is sufficient. */
    #else
    	#define TWI_DELAY() nrf_delay_us(1) /*!< Time to wait when pin states are changed. For fast-mode the delay can be zero and for standard-mode 4 us delay is sufficient. */
    #endif	// BOARD_CUSTOM
    

  • Hi

    components\drivers_nrf\twi_master\deprecated\twi_sw_master.c(93)

    The TWI driver you are using is deprecated, as you can see from the file path.

    I recommend that you use one of the drivers listed in nRF52833 drivers or have a look at out Hardware Peripheral examples.

    Regards,
    Sigurd Hellesvik

Related