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

Help needed on finding twi device...

Hi
Env: keil uvision 5 and SDK 9 and custome breakoutboard for nRF51822 (PTR5518: no external crystal) and no SD.


I am trying doing the first steps in twi over nRF51822, in a custom breakoutboard (PTR5518) without external crystal.

I have a TMP102 temp sensor connected to pins 9 (SDA) and 8(SCL)


I have copied the nrf_drv_config.h from components/nrf_drivers to my project root. I have done the following changes:

Desabled twi 1 and enabled twi 0:
#define TWI0_ENABLED 1

#if (TWI0_ENABLED == 1)
#define TWI0_CONFIG_FREQUENCY NRF_TWI_FREQ_100K
#define TWI0_CONFIG_SCL 8
#define TWI0_CONFIG_SDA 9
#define TWI0_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_HIGH

#define TWI0_INSTANCE_INDEX 0
#endif

and changed clock settings too:


/* CLOCK */
#define CLOCK_CONFIG_XTAL_FREQ NRF_CLOCK_XTALFREQ_16MHz
#define CLOCK_CONFIG_LF_SRC NRF_CLOCK_LF_SRC_RC
#define CLOCK_CONFIG_LF_RC_CAL_INTERVAL RC_500MS_CALIBRATION_INTERVAL
#define CLOCK_CONFIG_IRQ_PRIORITY APP_IRQ_PRIORITY_LOW


In the app:


#include <stdbool.h>
#include <stdint.h>
#include "nrf_delay.h"
#include "nrf_gpio.h"
#include "boards.h"

#include "nrf_drv_twi.h"

const nrf_drv_twi_t twi2 = NRF_DRV_TWI_INSTANCE(0);


uint32_t err_code;
uint8_t device_address = 0; 
bool device_found = false;


void twi_init (void)
{
   const nrf_drv_twi_config_t twi_config = {
   .scl = 8,
   .sda = 9,
   .frequency = NRF_TWI_FREQ_100K,
   .interrupt_priority = 3
   };

   err_code=nrf_drv_twi_init(&twi2,&twi_config,NULL); //Returns SUCCESS!
   
   nrf_drv_twi_enable(&twi2);
}


int main(void)
{
   nrf_gpio_cfg_output(19); //LED ON custom board

   twi_init();

   uint8_t dummy_data = 0x55;
   for(uint8_t i = 0; i <= 0x7F; i++)
   {
      device_address = i;
      nrf_drv_twi_tx(&twi2, i, &dummy_data, 1, false);
      nrf_delay_ms(10);
}

if(device_found)
{
   while(true)
   {
      nrf_gpio_pin_set(19);
      nrf_delay_ms(100);
   }
}
else
{
      nrf_gpio_pin_clear(19);
      while(true)
      {
         ;
      }
 }




}


Device is never found. It seems that nrf_drv_twi_tx always return Internal_error.


Why? Could it be related with clock settings?


Any help would be very appreciated. Thank you


Alex

Related