Ok, so I managed to identify the I2C address of my LCD with a single set of I2C pins on the Nucleo F413HZ. Most of them didnt find the address, which is really weird…
I already knew what the address was, it is a classic LCD 4x20 with an address of 0x27, I used it plenty with arduinos.
So I managed to print device found at 0x27 with this code:
#include <mbed.h>
I2C i2c(PB_11, PB_10); // SDA pin, SCL pin // PB_9, PC_6 not working, make the weird LD1 flash and no comm
Serial pc(USBTX, USBRX); // TX pin, RX pin
int main()
{
pc.baud(9600);
while (1)
{
pc.printf("Hello World!\n");
thread_sleep_for(1000);
int count = 0;
for (int address = 0; address < 127; address++)
{
if (!i2c.write(address << 1, NULL, 0)) // 0 returned is ok
{
pc.printf("I2C device found at address 0x%02X (0x%02X in 8-bit)\n", address, address << 1);
count++;
}
thread_sleep_for(20);
}
if (count)
pc.printf("%d", count);
else
pc.printf("No");
pc.printf(" device found\n\n");
}
}
I decided to try my lcd printing code again, since now I knew that the device address was at least identified, but no luck. Still nothing showing up. Played with the nob again to make sure. I never had used 5V before, I believed the pins were only 3v3 tolerant, but it didn’t seem to work either. Here is the code I am using (maybe the firmware I wrote is the problem):
#include <mbed.h>
I2C i2c(PB_11, PB_10); // SDA pin, SCL pin // PB_9, PC_6 not working, make the weird LD1 flash and no comm
Serial pc(USBTX, USBRX); // TX pin, RX pin
int main()
{
pc.baud(9600);
while (1)
{
pc.printf("Hello World!\n");
thread_sleep_for(1000);
int count = 0;
for (int address = 0; address < 127; address++)
{
if (!i2c.write(address << 1, NULL, 0)) // 0 returned is ok
{
pc.printf("I2C device found at address 0x%02X (0x%02X in 8-bit)\n", address, address << 1);
count++;
}
thread_sleep_for(20);
}
if (count)
pc.printf("%d", count);
else
pc.printf("No");
pc.printf(" device found\n\n");
}
}