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

nRF9160 comunication not working with Arduino UNO I2C/TWI

I have been trying to get a arduino UNO and arduino Leonardo to communicate with the nRF9160DK but have not been able. That  accounts for the SPI example aswell as the I2C/TWI scanner example in both cases the Arduino's are used as Slave. I am quite new to this but unable to figure out why this all is not working. I have put my eyes on useing I2C because of mutible reasons so that is where this question will be about.

I am running the following slave example on the Arduino UNO

// Wire Slave Sender
// by Nicholas Zambetti <http://www.zambetti.com>

// Demonstrates use of the Wire library
// Sends data as an I2C/TWI slave device
// Refer to the "Wire Master Reader" example for use with this

// Created 29 March 2006

// This example code is in the public domain.


#include <Wire.h>

void setup() {
  Wire.begin(8);                // join i2c bus with address #8
  Wire.onRequest(requestEvent); // register event
  Wire.setClock(100000);
}

void loop() {
  delay(100);
}

// function that executes whenever data is requested by master
// this function is registered as an event, see setup()
void requestEvent() {
  Wire.write("hello "); // respond with message of 6 bytes
  // as expected by master
}


As you can see I have added a maximum Clock speed of 100K since that is what the nRF9160 scanner also uses.

I have changed the config of the nRF9160 to be like this:

&i2c3 {
	status = "ok";
	sda-pin = < 31 >;
	scl-pin = < 30 >;
    clock-frequency = <I2C_BITRATE_STANDARD>;  
};



And have wired the arduino -> nrf9160dk the following 

A4 -> P0.31
A5 -> P.0.30

I have changed the pinouts from the normal one since on the normal basic pinouts it wasnt working either. Once both are running I dont recieve anything execpt the following:

Starting i2c scanner...Value of NRF_TWIM3_NS->PSEL.SCL: 30 Value of NRF_TWIM3_NS->PSEL.SDA: 31 Value of NRF_TWIM3_NS->FREQUENCY: 26738688 26738688 -> 100k


I would love the recieve some help on why I can't seem to get the nRF9160dk working with my arduino's.

Parents Reply
  • I have gotten a TXB0104 and have switched to using SPI since I2C is not recommended to be used with a TXB device. But once again I am having problems. Not sure what it could be I am trying to recieve data on the arduino but if I connect the SS pin it always stays high and never detects any incomming bytes or bits once I but SS to LOW by disconnecting stuff starts happing. Far from stable but atleast something happens. I am unsure which side is to blame in this manner but I am betting on the NRF9160. This is the code I am running on the arduino: 

    // Written by Nick Gammon
    // April 2011
    
    // what to do with incoming data
    volatile byte command = 0;
    
    void setup (void)
    {
      Serial.begin(9600);
      // have to send on master in, *slave out*
      pinMode(MISO, OUTPUT);
    
      // turn on SPI in slave mode
      SPCR |= _BV(SPE);
    
      // turn on interrupts
      SPCR |= _BV(SPIE);
    
    }  // end of setup
    
    
    // SPI interrupt routine
    ISR (SPI_STC_vect)
    {
      byte c = SPDR;
      Serial.println(c);
     
    
    }  // end of interrupt service routine (ISR) SPI_STC_vect
    
    void loop (void)
    {
      // if SPI not active, clear current command
      if (digitalRead (SS) == HIGH){
       //Serial.println("high");
        command = 0;
      }
      if (digitalRead (SS) == LOW){
        //Serial.println("low");
      }
     //delay(10); 
    }  // end of loop

    On the nRF9160 i am just running the example https://github.com/Rallare/fw-nrfconnect-nrf/tree/nrf9160_samples/samples/nrf9160/spi No change to config or whatever.

    I am thinking of buying a logic analyser to get insight in to what is going on.

Children
Related