6 years, 11 months ago.

I2C on Nucleo F030R8 not working

Hi,

I'm trying to set up I2C on the Nucleo F030R8 board, but it seems that it's not working. I've tried flashing the I2C scanner program to find my I2C slave, so I expect it to find only one address. However, the program finds an I2C device at every address.

I've tried the same program on the Nucleo F401RE board, and it works fine - finds just one I2C slave.

Do you know what could be the problem here? It seems that after sending the address on the I2C line, the master does not release the SDA line for the slave to send the ACK bit.

/media/uploads/paplaukias/i2c.png

/media/uploads/paplaukias/printout.png

1 Answer

6 years, 10 months ago.

Hi, I had same problem on Nucleo F767ZI... Mbed i2c.write has two variants:

int  write (int address, const char *data, int length, bool repeated=false) 
int  write (int data)  

One variant was OK but second had a same problem like you = same result. I do not remember which one is. The problem was propably solved in release 145 of mbed lib. so update your mbed and try again.

Accepted Answer

Jan,

Thanks for your reply. I noticed that there's a difference between these two write() functions.

However, in the end it turns out it was my mistake. I was trying to send only one byte to the slave, using the first write() (the one that takes 4 arguments in). And I overlooked that for data you can't just put in a char - it has to be a pointer to a char array.

So in the end, this code worked and still works perfectly fine:

int sensors::check(int addr) {
	char cmd[2];
	int error;

	cmd[0] = REG_ADDR_CONFIG;
    cmd[1] = 0x20;
	
	error = i2c.write(addr, cmd, 0);
	if(error == 0) {
		//pc.printf("[ OK ] ADC at 0x%X found\n\r", addr);
		i2c.write(addr, cmd, 2, false);
		return ADC_OK;
	} else {
		//pc.printf("[ ERROR ] ADC at 0x%X not found!\n\r", addr);
		return ADC_ERROR;
	}
}
posted by Domantas Cibas 06 Jul 2017