I am trying to connect two ublox C027 boards via I2C. For that purpose I have soldered an adapter cable which connects the two boards' SCL and SDA pins, respectively, and pulls up each of them to 3.3V on one of the boards by a 2.2kOhm resistor.
I use the code below, and get the given output, which means to me that there is no communication between the two boards.
Have I missed something? What about the I2C classes' start and stop methods? Must they be called somewhere?
Common code
#include <string>
#include "mbed.h"
#include "C027_api.h"
DigitalOut led(LED);
const int slaveAddress = 0xA0;
const string successfully = "successfully";
const string unsuccessfully = "unsuccessfully";
string translateFailure(int failure) {
return failure ? unsuccessfully : successfully;
}
Master code
int main() {
c027_init();
I2C i2cMaster(SDA, SCL);
char count = 0;
char read;
int failure;
while (true) {
failure = i2cMaster.write(slaveAddress, &count, 1, false);
printf("Master wrote '%d' %s.\n", count++, translateFailure(failure).c_str());
led = !led;
if (!failure) {
failure = i2cMaster.read(slaveAddress, &read, 1, false);
printf("Master read '%d' %s.\n", read, translateFailure(failure).c_str());
}
wait(1);
}
}
Slave code
int main() {
c027_init();
printf("I2C slave pre-start...\n");
I2CSlave i2cSlave(SDA, SCL);
i2cSlave.address(slaveAddress);
char count = 0;
char read;
int failure;
while (true) {
int status = i2cSlave.receive();
switch (status) {
case I2CSlave::NoData:
printf("Slave received no data.\n");
break;
case I2CSlave::ReadAddressed:
failure = i2cSlave.write(&count, 1);
printf("Slave wrote '%d' %s.\n", count--, translateFailure(failure).c_str());
break;
case I2CSlave::WriteGeneral:
failure = i2cSlave.read(&read, 1);
printf("Read general message '%d' %s.\n", read, translateFailure(failure).c_str());
break;
case I2CSlave::WriteAddressed:
failure = i2cSlave.read(&read, 1);
printf("Read addressed message '%d' %s.\n", read, translateFailure(failure).c_str());
break;
}
}
}
Master output
Master wrote '0' unsuccessfully.
Master wrote '1' unsuccessfully.
Master wrote '2' unsuccessfully.
Master wrote '3' unsuccessfully.
...
Slave output
I2C slave pre-start...
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Slave received no data.
Read general message '0' successfully.
Slave received no data.
Slave received no data.
...
Thank you for your help.
I am trying to connect two ublox C027 boards via I2C. For that purpose I have soldered an adapter cable which connects the two boards' SCL and SDA pins, respectively, and pulls up each of them to 3.3V on one of the boards by a 2.2kOhm resistor.
I use the code below, and get the given output, which means to me that there is no communication between the two boards.
Have I missed something? What about the I2C classes' start and stop methods? Must they be called somewhere?
Common code
Master code
Slave code
Master output
Slave output
Thank you for your help.