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

How to Switch from spi0 to i2c0

Hi

i am using NRf51822 custom board. In that i have NOR(spi0) and LED(i2c0).

But switching from spi0 to i2c0 is not possible so that i am not able to switch

off led. But once i comment the spi_master_init(), led is going to off.

I know both uses same id means have same base address.

Kindly suggest how to switch from spi0 to i2c0.

i am not going to change spi and i2c bus for NOR and LED , because i have some other peripherals,

which is connected to i2c1 and spi1 bus.

Regards Balaji

  • Are you also using custom software? I don't recognize your definitions (NOR(spi0) and LED(i2c0)) from any of the Nordic examples.

  • Hi

    It means for NOR i am using spi0 bus and for LED i am using i2c0 bus.

    Here is Pseudo code:

    twi_master_init(); //i2c0 initialization for LED red_orange_periodicaly_05s(); //some i2c write calls to blink led. spi_master_init(SPI0,SPI_MODE0,0); //spi0 initialization for NOR read_Nor_send_to_ble_stack(); //some spi transfer call to read data from Nor. twi_master_init_rgb(); //i2c0 initialization for LED stop_led(); //some i2c write call to stop led.

    But here i am able to switch on LED and able to read data from NOR.

    but not able to switch off LED. but once i comment spi_master_init(SPI0,SPI_MODE0,0); LED is

    going to off.

    Kindly suggest me.

    Regards Balaji

  • As you can see in the instance table (table 3 in the nRF51 Reference Manual), SPI0 and TWI0 share the same register space. You can therefore not use them simultaneously. Instead, I'd recommend you to either use SPI0 and TWI1 (or opposite), or make sure to disable SPI0 by writing the appropriate value to the ENABLE register and only after this initialize TWI0.

Related