Skip to main content
NBlac
Associate III
April 26, 2019
Question

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

  • April 26, 2019
  • 3 replies
  • 960 views

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

This topic has been closed for replies.

3 replies

S.Ma
Principal
April 26, 2019

S-10110010-N-P

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

NBlac
NBlacAuthor
Associate III
April 26, 2019

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
NBlacAuthor
Associate III
April 27, 2019

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