2019-04-26 10:22 AM
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.
thanks
2019-04-26 11:06 AM
S-10110010-N-P
NACK = 1 = slave not present. Write command failed.
2019-04-26 11:10 AM
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
2019-04-27 04:36 AM
Ok, the test that i was trying to do was flawed. I changed the NBYTES to 0 and it now shows in the scope.