Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.
Photo

Pull Up, Pull Down, Pulling my hair out!

I2C

  • Please log in to reply
11 replies to this topic

#1 TheIceManProgrammeth

TheIceManProgrammeth

    New Member

  • Members
  • Pip
  • 9 posts

Posted 18 February 2015 - 11:34 PM

Hi really love the netduino but I'm definitely more of a programmer than an electronics guy so am probably doing something silly but I can't work out what.

 

I'm trying to use  LSM303DLH compass and accelerator module on a Netduino 1 firmware 4.2 using the excellent code provided in the netduino forums "Sensor Library" by sfugrino on 14th March 2014.

 

Unfortunately I didn't do my research enough and bought an arduino sensor shield thinking I could just plug the i2c cable in there. The sensor didn't return any readings.

 

On reading a few other posts I realised my mistake that the ND doesn't have pulldown or pullup resistors so I abandoned the sensor shield and tried to connect the sensor to the ND via a breadboard instead.

 

The sensor is on (the red LED is on) but I just can't get any readings from it.  I'm not entirely sure where to place the resistors but I've placed them seemingly in every combination I could think of but the reading is always 0 bytes transferred.

 

I've also noticed that even if I don't plug in anything to A4 or A5 that the code still registers that the write succeeded which can't be right can it?

 

Any help would be greatly received.

 

 

 

 



#2 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 19 February 2015 - 08:41 AM

Hi IceMan,

 

I2C uses transistors to pull the signals to ground and pull up resistors to pull the signals up to the positive rail.

This allows the same two wires to send data in either direction, and you can have many nodes on the wires - e.g its a multi-drop system.

 

After each 8 bits, the sender listens for an ACK. An ACK is a low bit. If the pull-ups are not connected correctly, then it would be possible for the Netduino (the master) to hear a low bit for the ACK and assume it was the slave pulling the data line down. So your sends might be reported as successful.

 

This external page shows the waveform and talks about the signals in a down to earth way.

 

There is a Forum page about choosing the right voltage to pull-up to. I would pull-up to 3.3V unless your I2C device needs a 5V pull-up.

 

I think it would be worth initially adding the resistors with nothing else connected. Try sending something and verify the send now fails.

 

Then connect the two data lines and a ground to the slave device.

The slave will also need power, this may either come from the Netduino or a separate supply - as long as the grounds are joined.

Now try again and see if the send is reported as successful.

 

Take small steps and you should get there.

 

Have Fun - Paul



#3 TheIceManProgrammeth

TheIceManProgrammeth

    New Member

  • Members
  • Pip
  • 9 posts

Posted 19 February 2015 - 12:41 PM

Thanks Paul! Will give it a go tonight when I get home!

 

Nice to know there is another Netduiner in the area (I'm in Berkshire too!)



#4 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 19 February 2015 - 07:28 PM

I think there are a few of us from the Shire on the forums.



#5 TheIceManProgrammeth

TheIceManProgrammeth

    New Member

  • Members
  • Pip
  • 9 posts

Posted 19 February 2015 - 11:03 PM

Cool hopefully you will see one of my netduino projects flying around the Reading area soon!

 

So I tried the i2C again and still nothing.

 

With absolutely nothing attached to the netduino the write seems to work sending 2 bytes for the init and 1 for the pre-read. The read returns 0. This is exactly the same result when I plug in the sensor with or without resistors between them and the board.

 

I did notice the arduino library code for the sensor was slightly different to the Netduino conversion but even changing those had no effect and would explain why the sensor seems to have no impact on the results whatsoever.

 

Pretty frustrating. Is there any way to test the i2c using something simpler?

 

Thanks again in advance for any help. I'm sure it's probably something silly.



#6 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 20 February 2015 - 08:16 AM

Just to confirm - return value of "0" means success?

 

What happens if you just add the resistors? (Pull-up to 3.3.V)

I would expect the return value to change to fail.

 

I'll have to get a hard hat.



#7 TheIceManProgrammeth

TheIceManProgrammeth

    New Member

  • Members
  • Pip
  • 9 posts

Posted 20 February 2015 - 10:44 AM

Haha thanks Paul well this is the sensor for the heading so it could end up anywhere in Berkshire if it doesn't work! ;-)
 
So the code sends 8bytes to be populated by the sensor and then checks if the number of bytes coming back is equal to the buffer.

            lock (_slaveDevice)

            {

                // the i2c data is received here from the device.

                int transferred = _slaveDevice.Execute(readXAction, transactionTimeout);

 

                // make sure the data was received.

                if (transferred != readBuffer.Length)

                   throw new Exception("Could not read from device.");

            }

When I use the code above transferred is always 0. When I use the same _slaveDevice.Execute method for the write it returns 2 for the init and 1 for the pre-read send. Adding the resistors has no impact (I've placed one between the power and the SDA and one one betwen the SCL and power). Even without anything connected to the netduino the write returns 2 and 1 from the method and the read still returns 0.

 

So what I can't get my head round is why is the netduino saying the write worked when clearly there was nothing attached to it? Your earlier post suggested the ACK was being wrongly interpreted but since there is nothing connected to the pin where did the ACK come from?

 

Thanks for any suggestions you can give me.



#8 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 20 February 2015 - 05:01 PM

My knowledge has run out now.

There have been lots of threads about I2C on the forums, but I found that searching for them does not seem to work for me.

 

Perhaps someone else knows if the ACK is actually checked by the Netduino?

Maybe when writing, the ACK is not checked and the Netduino just counts the number of bytes sent out.

 

Anyone?



#9 TheIceManProgrammeth

TheIceManProgrammeth

    New Member

  • Members
  • Pip
  • 9 posts

Posted 21 February 2015 - 10:45 PM

Ok update on this one. I eventually started to get some readings when I switched the I2C sensor code to the toolbox MultiI2c but only for the magnet not the accelerometer. No resistors needed and worked using the sensor shield I bought so haven't wasted money after all.

 

Will post the code when I get the accelerometer working!

 

Thanks to Paul for his suggestions and I've certainly learnt a lot more about how I2C works!



#10 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 22 February 2015 - 07:39 PM

Good to hear.

When you're done, the wiki is a good place to share.



#11 TheIceManProgrammeth

TheIceManProgrammeth

    New Member

  • Members
  • Pip
  • 9 posts

Posted 22 February 2015 - 10:45 PM

Thanks Paul. Got readings from both the magnet and accelerometer now but I'm intrigued as to why the standard I2C stuff didn't work. Think one of the other posters mentioned repeated-start condition so going to experiment with that to see if I can see what is wrong with the standard transaction based stuff.

 

Will post all results to the wiki once I've finished.

 

Seems so easy now it's working properly!



#12 Paul Newton

Paul Newton

    Advanced Member

  • Members
  • PipPipPip
  • 724 posts
  • LocationBerkshire, UK

Posted 24 February 2015 - 09:02 PM

Well done.

 

My first experience of I2C (not on a Netduino) was a very bad one. We spent around a week trying to debug our comms issue before we finally read the data sheet's errata list and found out the I2C would never work properly on the processor we were using. Then we had to work out how to make the product work without working I2C hardware - not fun!

 

Paul







0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.