This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CC1352R: What is the correct configuration of the pin when it should be used as input and output simultaneously?

Part Number: CC1352R


Hello,

We are developing a new device using CC1352R with two slave I2C devices on two different I2C-bus lines. This MCU has only one I2C bus and we decided to write a software implemented I2C interface. It works properly.

The project is created with the latest SDK 7_10_02_23 and using RTOS. Pins SCL and SDA are defined as outputs - open drain with external pull-ups 10kOhm. Everything works properly.

We would like our code to be written according to the best practices and the philosophy of the current SDK.

1. Pins SCL and SDA are defined in the begging as outputs - open drain. 

Example:

GPIO_setConfig(CONFIG_GPIO_I2C_LEDDRV_SDA, GPIO_CFG_OUTPUT_OPEN_DRAIN_INTERNAL | GPIO_CFG_OUT_STR_MED | GPIO_CFG_OUT_HIGH);
GPIO_setConfig(CONFIG_GPIO_I2C_LEDDRV_SCL, GPIO_CFG_OUTPUT_OPEN_DRAIN_INTERNAL | GPIO_CFG_OUT_STR_MED | GPIO_CFG_OUT_HIGH);

2. During the execution of the code we check the state of the pin SCL with the function GPIO_read(...). It works properly.

The questions are:

2.1 If the pin is defined as output ONLY how does the function GPIO_read() works?

2.2 In this case, is it necessary the pins SCL and SDA to be configured as inputs and output together to be able to write and read the pins?

2.3 If we can read the pin state always with function GPIO_Read(...), that means we don't need to reconfigure the pin to be input during the I2C read operation (SDA line is open drain with pull-up in High state). Is that correct?

Again, our purpose is out code to be written by the best way according to the philosophy of the SDK.

Thank very much in advance for you response.

  • Hi Angel,

    Thank you for the question. I will look into this and get back to you before the end of the day . 

    Regards,

    Sid

  • Hi Angel,

    2.1: When you configure the pin as an output, the GPIO driver will also enable the input buffer to be able to read the current state of the pin using GPIO_read(), as you do. This is intentional, for exactly use cases like yours.

    2.2: You do not need to explicitly configure the pin as an input to be able to read the input state, using your current configuration will be sufficient. Although you should not use GPIO_CFG_OUTPUT_OPEN_DRAIN_INTERNAL, since this as the name suggests is to be used internally by the GPIO driver only. Instead I would suggest that you use  GPIO_CFG_OUT_OD_NOPULL, since you mention that you have external pull-ups.

    2.3: That is correct. If the output level of the open-drain output is high (i.e. you have written "1" to the pin using GPIO_write()), then you can read the input state using GPIO_read() as if it was just configured as an input.

    In short, configuring the pin as an output using GPIO_CFG_OUT_OD_NOPULL and reading the input state with this configuration (while the output state is high) is following the philosophy of the SDK.

    Regards,
    Nikolaj

  • Thank you very much Nikolaj. This is enough for me.