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

TWI on nRF51822

I just entered a Case to Nordic with this same question but do not expect to get a response over the weekend so I am posting here. I made the assumption that the Nordic Cases and the Developer Zone are not related. If this is considered a double-post I apologize.

I used the RF6350_radio_configuration_example as a starting point for our TWI interface. The goal is for the nRF51822 to act a a Master and send commands to a Slave to read/write the Slave's RAM/EEPROM.

I am using the nRF51822 EK with our TWI Slave attached and uVision 4 and the TWI transmission are unsuccessful. When a command is issured there are two negative SDA pulses followed by continuous SCL pulses. (36 usec period = 27.8KHz). The Slave requires clock freuencies of 10KHz-100KHz. When the code reaches “if (timeout == 0)” in the twi_master_write() while loop timeout always equals 0 which may be why the transmissioin fails. Of course this may not be the only problem.

I am still plugging away on this but time is short so any suggestions will be appreciated.

twi.txt

  • There are 8K external pull-ups on both SCL and SDA. The sensor recommends 1.5K - 20K. The Eval Kit board is USB powered and the sensor gets its power for an output pin.

    Yes, the Softdevice is loaded. Is that an issue?

  • Hi Tom

    If the softdevice is enabled, you can not access the PPI directly as you have done in your code. You have to use the softdevice API to access the PPI. The PPI is mentioned as restricted in the softdevice specification, which means you must access it via the sd API. As example, the following code strip

    NRF_PPI->CH[0].EEP = (uint32_t)&NRF_TWI1->EVENTS_BB;
    NRF_PPI->CH[0].TEP = (uint32_t)&NRF_TWI1->TASKS_SUSPEND;
    

    should be replaced by sd_ppi_channel_assign(0, &NRF_TWI1->EVENTS_BB, &NRF_TWI1->TASKS_SUSPEND);

    All the NRF_PPI references need to be replace by sd_ppi_* equivalent commands.

    I did not notice that your softdevice is enabled (or disabled for that matter) in your code, but the code file you sent is probably a summarized version of your actual code? If you are using BLE in your project, then it is probably enabled in which case you have to modify the code as I have indicated above. As quick reference, simply do the following replacements in your code (with the above example as well):

    NRF_PPI->CHENCLR = PPI_CHENCLR_CH0_Msk; should be sd_ppi_channel_enable_clr(PPI_CHENCLR_CH0_Msk);

    NRF_PPI->CH[0].TEP = (uint32_t)&NRF_TWI1->TASKS_STOP; should be sd_ppi_channel_assign(0, &NRF_TWI1->EVENTS_BB, &NRF_TWI1->TASKS_STOP);

    NRF_PPI->CH[0].TEP = (uint32_t)&NRF_TWI1->TASKS_SUSPEND; should be sd_ppi_channel_assign(0, &NRF_TWI1->EVENTS_BB, &NRF_TWI1->TASKS_SUSPEND);

    Hope this helps

  • To clean things up, I'd be happy if you could evaluate the answers you have received and accept one of them if you feel it's sufficient. If not, it might be useful to expand your question a little and provide further information.

Related