So i'm messing around with the following:
I have a custom made shield to operate with an Uno. I now want to update it to a Leonardo because I've found a batch laying around. Trick is, the Uno has it's SDA and SCL on A4 and A5, both connected to the SDA and SCL pins next to AREF. The Leonardo has the SDA and SCL pins on 2 and 3, also connected to the SDA and SCL pins next to the AREF. The custom shield we have already uses pins 2 and 3 for something else, so I want the I2C to relocate to A4 and A5! So I downloaded the softI2Cmaster library (Found here: Arduino Playground - SoftwareI2CLibrary)
And I adjusted the ports to PORTF and SDA/SCL pins (According to the pinout: https://www.arduino.cc/en/Hacking/PinMapping32u4).
When running the I2CScanSoft example, it doesn't do anything.. According to the example the SDA and/or SCL lines "are low"...
code:
// Scan I2C bus for device responses
#define SDA_PORT PORTF
#define SDA_PIN 7
#define SCL_PORT PORTF
#define SCL_PIN 6
#define I2C_TIMEOUT 100
#define I2C_NOINTERRUPT 0
#define I2C_FASTMODE 1
#define FAC 1
#define I2C_CPUFREQ (F_CPU/FAC)
/* Corresponds to A4/A5 - the hardware I2C pins on Arduinos
#define SDA_PORT PORTC
#define SDA_PIN 4
#define SCL_PORT PORTC
#define SCL_PIN 5
#define I2C_FASTMODE 1
*/
#include <SoftI2CMaster.h>
#include <avr/io.h>
//------------------------------------------------------------------------------
void CPUSlowDown(int fac) {
// slow down processor by a fac
CLKPR = _BV(CLKPCE);
CLKPR = _BV(CLKPS1) | _BV(CLKPS0);
}
void setup(void) {
#if FAC != 1
CPUSlowDown(FAC);
#endif
}
void loop(void)
{
if(Serial.available())
{
Serial.begin(115200); // change baudrate to 2400 on terminal when low CPU freq!
Serial.println(F("Intializing ..."));
Serial.print("I2C delay counter: ");
Serial.println(I2C_DELAY_COUNTER);
int temp = 1;
while(temp==1)
{
if (!i2c_init())
{
Serial.println(F("Initialization error. SDA or SCL are low"));
delay(1000);
}
else
{
Serial.println(F("...done"));
temp=0;
}
}
while(1)
{
uint8_t add = 0;
int found = false;
Serial.println("Scanning ...");
Serial.println(" 8-bit 7-bit addr");
// try read
do {
Serial.println(add, HEX);
if (i2c_start(add | I2C_READ)) {
found = true;
i2c_read(true);
i2c_stop();
Serial.print("Read: 0x");
if (add < 0x0F) Serial.print(0, HEX);
Serial.print(add+I2C_READ, HEX);
Serial.print(" 0x");
if (add>>1 < 0x0F) Serial.print(0, HEX);
Serial.println(add>>1, HEX);
}
else i2c_stop();
add += 2;
}
while (add);
}
}
I have adjusted some of the example to have a better control over when the scanning starts and when not.
I have also tried to enable and disable the pull-up resistors and swapping the pins, without effect.
It'll probably be a small thing, but with my heavy case of tunnel vision and a lack of coffee i'm not able to find the problem... Does someone have an idea on what the problem could be or how to continue?
Thanks in advance!