SparkFun Forums 

Where electronics enthusiasts find answers.

General project discussion / help
Did you make a robotic coffee pot which implements HTCPCP and decafs unauthorized users? Show it off here!
By whay
#193640
Good afternoon~everybody,thanks for expending time to reading my post firstly!I am so pleasure to be here and share you my problems and I hope there are someone could help me!
At present,I’m using the monolithic--PIC18f25k80(this product:http://www.kynix.com/Detail/870618/PIC1 ... %2FSO.html) to communicate passing by I2C and LIS3DH. However,I failed in the first step! SDA and SCL pulled up.How can I do ? Anyone could tell me what should I notice when using LIS3DH? Or the monolithic I used is wrong? :cry:
Your help will be grateful.Thanks a lot. :)
User avatar
By phalanx
#193646
Hi whay,

I'm going to take a wild guess and say English may not be your primary language. What the translator called a "monolithic" should be "microcontroller." In any case, I understood what you were trying to ask. There is no problem with the PIC18F25K80 as it has a hardware I2C port. What they mean by pulled up is the SDA and SCL lines are connected to your power supply rail through a resistor to limit current. I2C devices are open-drain which means they generate data by grounding and releasing the line. Since the connection to ground is a dead short, the pull-up resistors are set to limit the current through the device so it doesn't burn the ports out. A common pull-up resistor value for I2C is 4.7K but if you look at page 20 of the LIS3DH datasheet, you will see that they recommend 10K resistors. There are tradeoffs to using higher and lower values that link to overall bus speed and power requirements but you should be safe using their recommended value.

Here is an example sketch of an I2C bus. The master device would be your PIC18F25K80, the slave device would be the LIS3DH, and Rp are your pull-up resistors:
Image

-Bill
By whay
#193661
Haha...yes,you are right,friend.I'm not very good at English and I think maybe I need to learn it as soon as possible.I think I have understood what you mean,I will try it again right now.You are so kind!Thanks a lot!
By brianfaires
#193787
I too am having issues with LIS3DH in I2C mode. I'm using an Arduino Micro, and hooked up the accelerometer as per the hookup guide (I believe the Arduino Wire library handles pull up resistors internally?). My problem is that after connecting the LIS3DH to the SDA and SCL lines, the 3.3V pin raises to ~4.3V, and the LI3DH reads a constant 0 on all axes. I've read at http://playground.arduino.cc/Main/I2CBi ... velShifter under "Internal pull-up resistors activated by Wire library" that I may need an external resistor between 3.3V and Gnd, due to high current flow disabling the Arduino's 3.3V regulator. Is this correct, and is the LI3DH likely damaged due to the 4.3V?
User avatar
By phalanx
#193788
Hi brianfaires,

What Arduino are you using and are you sure it's a 3.3V model? Also, are you using a breakout board for the LIS3DH, and if so, which one? And finally, how are you powering the Arduino and the LIS3DH? You definitely should not be seeing 4.3V on the bus but there is a decent possibility you didn't wreck anything.

In terms of pull-ups, the ones that are built into microcontrollers are usually considered weak pull-ups which means they are a high value. Nominal 50K values are not uncommon but the specs can range from 10-100K depending on the brand and model. Typically you will not get the current you need from them to properly drive an I2C bus so you need to make use of external ones sized to meet the requirements of the devices being driven.

-Bill
By brianfaires
#193789
Hi Bill, thanks for the quick response.

I'm using an Arduino Micro, currently powering it through USB. It's a 5V model, so I'm using the 3.3V pin to power the LIS3DH. The SDA and SCL pins are attached to pins 2 and 3 on the Arduino, which are the default for I2C. I am using a breakout board too, SEN-13963.

If I understand your second paragraph, I may need to include external pull-ups on the SDA and SCL lines, and disable the internal pull-ups? Does the external pull-down on the 3.3V supply make any sense in this context? The out-of-spec voltage scares me as I'd obviously like to avoid damaging the breakout board. What's interesting too is that the voltage doesn't raise to >4V until I connect the SDA or SCL line. Prior to that it holds steady at 3.3V.

Thanks,
Brian
User avatar
By phalanx
#193791
Do you have a link to the specific Arduino Micro you're using? Since you stated it's a 5V model, pins #2 and #3 will be 5V since they come from the microcontroller. You will have to use a level shifter for compatibility or change to a 3.3V model.

-Bill
By brianfaires
#193793
Ah I see, so that explains where >3.3V is coming from. The link for my Arduino is: https://www.arduino.cc/en/Main/ArduinoBoardMicro , I'm not sure if there's a more specific link but that's what I've been referencing.

I shall get a bi-directional level shifter, though perhaps I will first try the somewhat hacky approach described at http://playground.arduino.cc/Main/I2CBi ... velShifter , running 4k7 resistors from SDA and SCL to 3.3V, and a ~22k resistor from 3.3V to Gnd. (Patiently waiting for shipments is not my strong suit). Thanks for all your help Bill!

Brian
By brianfaires
#193796
Just wanted to report for posterity's sake that the resistor hacking was successful! I believe it's going out of spec a bit so I'll probably just use a level shifter in the future, but all is well in my current implementation, and fortunately the accelerometer is alive and well.
By whay
#193825
Please allow me to express my appreciation to you all! The problem has been solve successfully in your help and my processor! I will try my best to learn it more professional and be a person like you in the future who can help others! Thanks a lot! !