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

Ready to development TWI application while using softdevice

Hi, I am developing a BLE application using SPI and TWI. (Using nRF51822) This discussion is about my survey in development zone for future develop the TWI part. I want to discuss... not just ask some specific question ;)

I've used SPI slave to read another chip's information, and transmit these information through BLE. And I want to read another chip's information (through TWI) and also try to send other relatively few and less important information through BLE.

Since I've not found the TWI hw sample code. And I read this: devzone.nordicsemi.com/.../twi-of-nrf51822-is-having-internal-twi-engine-or-not And know I can just use GPIO to simulate the TWI behavior. But is any shortcoming using TWI sw module? The SPI part is a real-time data flow application (SPI->BLE). I am not sure using TWI sw will causing more CPU computation thus loss some interrupt from SPIs? Even I've setting SPI MATRX 255.

Is TWI hw more recommand?

The other thing I thought is the Peripheral ID. As reference manual says, ID:4 is used by SPI slave so I've to use ID:3 (TWI0) as my application. I think I can just modify the code in the library NRF_TWI1 => NRF_TWI0

Is that enough?

And I've read more about the confilct between TWI and the softdevice. The reason is using the restricted PPI for shortcut BB-suspend and BB-stop when softdevice is enabled.

And I read this: devzone.nordicsemi.com/.../using-i2c-gpiote-interrupt-with-soft-device-enabled As Ole says, the new version chip can simply enable these shortcut without PPI configuration. The sample code in [sdk 5.1.0 36092] is also using PPI.

If I want to modify these below without using PPI: sd_ppi_channel_assign(0, &(NRF_TWI1->EVENTS_BB), &(NRF_TWI1->TASKS_STOP)); sd_ppi_channel_assign(0, &(NRF_TWI1->EVENTS_BB), &(NRF_TWI1->TASKS_SUSPEND)); sd_ppi_channel_enable_set(PPI_CHEN_CH0_Msk); sd_ppi_channel_enable_clr(PPI_CHEN_CH0_Msk);

as I thought I've to enable these shortcut first:

NRF_TWI0->SHORT = TWI_SHORTS_BB_STOP_Msk | TWI_SHORTS_BB_SUSPEND_Msk;

And then I don't know how to modify these tasks start..... I guess "channel_enable_set" can transfer as setting the task = 1 (Example: NRF_TWI0->TASKS_SUSPEND = 1) And the channel_enable_clr can transfer as the setting task = 0

Is that correct?

Finally, as I've read the PAN and know TWI will consume more power when enabled. To reduce power consumption, It is recommend to disabled when not used. Since the NVIC interrupt is not set in the sample code (twi_xx_master.c) I think disable TWI only use a function with below code is enough.

NRF_TWI1->ENABLE = TWI_ENABLE_ENABLE_Disabled << TWI_ENABLE_ENABLE_Pos; NRF_TWI1->POWER = 0;

Is that correct? And I know while enabled it again, it must needs to initialize first.

If something I didn't notice, please tell me. Thanks a lot!

Related