Go Down

Topic: I2C cannot detect (Read 436 times) previous topic - next topic

MateMatev

Apr 19, 2014, 07:46 pm Last Edit: Apr 19, 2014, 11:11 pm by MateMatev Reason: 1
Hello, finally I get arduino mini pro and accelerometer. Tried connect them together, but can't get communication working. I cannot use HW I2C (just because I use breadboard). So I wondered to use SoftI2CMaster library to emulate I2C by sw pins.

I don't know, If I'm configuring it right. So if anyone could check my code - configuration mainly of PINS and PORTS.

Connection should be fine.
Vcc -> 5V
SCL -> SCL
SDA -> SDA
GND -> GND

SCL on arduino mini pro is on pin marked as 6, SDA on pin marked as 7 - both should be on port D.

Code: [Select]

#define SCL_PIN PD6
#define SCL_PORT PORTD
#define SDA_PIN PD7
#define SDA_PORT PORTD

#define LED_PIN 13

#define I2C_TIMEOUT 250

#include <SoftI2CMaster.h>

int status = 0;
int I2C_STATUS = 0;

void scanI2CBus(){
for(int i = 0; i < 255; i++){
  Serial.print("Scan device: 0x");
  Serial.println(i, HEX);
  if(i2c_start(i|I2C_WRITE)){
   Serial.print("Found device: 0x");
   Serial.print(i,HEX);
   return;
  }
}
}

void loop(){
 status = digitalRead(LED_PIN);
 Serial.println("Loop:");
 Serial.println((status == HIGH) ? "HIGH\n" : "LOW\n");
 Serial.println("I2C_STATUS:");
 Serial.println(I2C_STATUS);
 
 if(status == LOW){
   digitalWrite(LED_PIN, HIGH);
 } else {
   digitalWrite(LED_PIN, LOW);
 }
 
 scanI2CBus();
 
 delay(800);
}


void setup(){
 pinMode(LED_PIN, OUTPUT);
 
 Serial.begin(38400);
 I2C_STATUS = i2c_init();
 Serial.println("Setup done!\n");
}


Thanks

robtillaart

one small issue, I2C device addresses only go up to 127
so a loop to scan up to 255 is wrong , but at the same time it should give some output in the lower numbers...

no experience with softI2Cmaster. a quick scan on github. All functions seem to be written in assembler in the .h so no .cpp files used. (doesn't solve your problem, I know)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

MateMatev

Issue with address range - I know about it, but there are some more questions about 7-bit and 8-bit addresses - so for scanning more is better.

My question is now mainly about setting
SCL_PIN 6
SCL_PORT PORTD
SDA_PIN 7
SDA_PORT PORTD

I I get it right, it should be the port into which IO expander is connected. According the schematics http://arduino.cc/en/uploads/Main/Arduino-Pro-Mini-schematic.pdf, D6 and D7 are connected to PORTD, pins 6,7. Is that right ?

If this is right, last question could be about HW part of thing. Accelerometer is using 3.3V logic, so it's high is around 3.3V, what could be low for 5V logic ?

Regards

robtillaart

do you have pull up resistors?
for I2C you need typically 4K7 or with longer wires 2K2  (or lower) resistor between the SCL/DTA and +5V
Think that will also be true for softI2C
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Northof49

Is a breadboard and typical 6" long breadboard wires suitable for testing i2c devices?

robtillaart

should not give any problems if you add a pull up resistor 4K7

one of the best backgrounders about i2c - http://www.gammon.com.au/forum/?id=10896 -
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Grumpy_Mike

Quote
I cannot use HW I2C (just because I use breadboard).

No that doesn't follow at all.

If there is something stopping you using hardware I2C then the same thing also stops you using software I2C.
What is it about your bread board that makes you think you can't use the hardware pins?

MateMatev


do you have pull up resistors?
for I2C you need typically 4K7 or with longer wires 2K2  (or lower) resistor between the SCL/DTA and +5V
Think that will also be true for softI2C


Yes, I have pull ups, but I used 10K, but also slow speed communication. I'll try test it with 4K7.


Is a breadboard and typical 6" long breadboard wires suitable for testing i2c devices?


Using of breadboard should be ok in my opinion. And wires I use as short as possible, not typical 6"


Quote
I cannot use HW I2C (just because I use breadboard).

No that doesn't follow at all.

If there is something stopping you using hardware I2C then the same thing also stops you using software I2C.
What is it about your bread board that makes you think you can't use the hardware pins?


I cannot use HW I2C beacuse it is not possible to pin it into breadboard, because of arduino mini pro pins for I2C.

Thank you all

Grumpy_Mike


I cannot use HW I2C beacuse it is not possible to pin it into breadboard, because of arduino mini pro pins for I2C.

There is a radical new concept in electronics it is called wires and soldering. You solder a wire to a pad and connect the other end of the wire to the bread board. Therefore allowing you to use the I2C hardware drivers.

Go Up