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

Sharing GPIO between I2C and SPI ?

Dear Members,

How can I share GPIO pin between SPI and I2C peripheral ?

I see SCK_PIN and MISO_PIN for SPI are the same with SCK and SDK on I2C

#define SER_APP_SPIM0_SCK_PIN       NRF_GPIO_PIN_MAP(0,27)     // SPI clock GPIO pin number.
#define SER_APP_SPIM0_MOSI_PIN      NRF_GPIO_PIN_MAP(0,2)      // SPI Master Out Slave In GPIO pin number
#define SER_APP_SPIM0_MISO_PIN      NRF_GPIO_PIN_MAP(0,26)     // SPI Master In Slave Out GPIO pin number

#define ARDUINO_SCL_PIN             27    // SCL signal pin
#define ARDUINO_SDA_PIN             26    // SDA signal pin

Thanks

Parents
  • Hi,

    Any GPIO can be assigned to any serial peripheral in all the nRF5x series ICs, thanks to the pin crossbar feature. Just disable one peripheral using the pins before assigning the pins to another peripheral. You cannot configure two different peripherals to control the same GPIOs at the same time.

    Note that the defines in the board header files are used for different examples, and may not all be intended for use by one example. These pins often chosen from convenience by the software developer, and may not be optimal from a HW perspective or for your application. E.g, make sure that you follow the guidelines with regards to "Standard drive, low frequency I/O only" markings in Pin assignments documentation.

    Best regards,
    Jørgen

  • For example I use in PCB :

    P0.20 = MOSI

    P0.21=MISO

    P0.22=SCK  

    they're configureable via software ?

    Thanks

  • Hi,

    Not sure if I understand your question. You cannot change the HW traces on the PCB from software, but you can configure which internal peripheral in the nRF52840 that is connected to receive or output data to the traces.

    I do not know if the devices you connect will work correctly if you output both SPI and I2C data to the same pins, without some kind of switch to disconnect the device(s) that uses another protocol. For instance, if you use the same pin for SPI and I2C clock and runs SPI at 8 MHz, this is way outside the maximum clock frequency supported by most I2C devices, and may cause damage or issues with the I2C device. 

    Best regards,
    Jørgen

Reply
  • Hi,

    Not sure if I understand your question. You cannot change the HW traces on the PCB from software, but you can configure which internal peripheral in the nRF52840 that is connected to receive or output data to the traces.

    I do not know if the devices you connect will work correctly if you output both SPI and I2C data to the same pins, without some kind of switch to disconnect the device(s) that uses another protocol. For instance, if you use the same pin for SPI and I2C clock and runs SPI at 8 MHz, this is way outside the maximum clock frequency supported by most I2C devices, and may cause damage or issues with the I2C device. 

    Best regards,
    Jørgen

Children
Related