cancel
Showing results for 
Search instead for 
Did you mean: 

Why can't i send a specific number with i2c?

NBlac
Associate III

I have started writing an i2c driver for the stm32f051c8 and have stumbled upon an issue.

The code i use to test a very basic version is:

	RCC->AHBENR|= 1<<18;  // gpio clock enable gpiob
	RCC->APB1ENR|= 1<<21; // enable i2c1 clock
	GPIOB->MODER|= 2<<12; // alternate function for two lines
	GPIOB->MODER|= 2<<14;
	GPIOB->AFR[0]|= (1<<24) | (1<<28); // i2c for alternate function
	I2C1->TIMINGR= 0x10420F13; // taken from the datasheet
	
	I2C1->CR1|= 1<<0;  // i2c enable
	I2C1->CR2|= (1<<25) | (1<<16);  // 1 byte, autoend enable 
	I2C1->CR2|= 0x50<<1;  // slave address
	I2C1->CR2|= 1<<13;  // start 
	

When i choose the slave address 0x59, for example, i do get the correct output (pic), but when i leave it 0x50, nothing comes out from either line.

0690X000008Az0ZQAS.png

thanks

3 REPLIES 3
S.Ma
Principal

S-10110010-N-P

NACK = 1 = slave not present. Write command failed.

NBlac
Associate III

Yes i know a NAK is present as the correct device address is 0x50. When i transmit 0x59 i expect to get a NAK as it's the wrong address. What i am having an issue with is that when i try to send 0x50, the SCK and SDA lines don't show anything (they stay high always).

thanks

NBlac
Associate III

Ok, the test that i was trying to do was flawed. I changed the NBYTES to 0 and it now shows in the scope.