Solved
STM32L -> I2C -> M24LR16E
Posted on November 19, 2014 at 00:22
My ANT1M24LR16E does not seem to repond to my I2C commands.
After the Send7bitAddress it reponds with a NACK (SDA high on one SCL clock). This is the first time I'm writing to it. Any ideas on why it is not working?/* Turn on M24LR16E */
GPIO_HIGH(GPIOD, GPIO_Pin_2);
Delay(100);
//x10ms
/* Generate start condition */
I2C_GenerateSTART(I2C1, ENABLE);
while
(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)){}
//Wait until bus is free
/* Send device select+read/write cmd and wait for ACK */
I2C_Send7bitAddress(I2C1, 0xA6, I2C_Direction_Transmitter);
//0xA6 = 0b10100 Page 18 datasheet
while
(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)){}
/* Send address byte. Wait until data has been received */
I2C_SendData(I2C1, 0x00);
//Register
while
(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)){}
I2C_SendData(I2C1, 0x2A);
// Data to be written
while
(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED)){}
/* Generate Stop condition */
I2C_GenerateSTOP(I2C1, ENABLE);
Delay(100);
while
(1){}
/* Shut down M24LR16E */
//GPIO_LOW(GPIOD, GPIO_Pin_2);
//Delay(100);
#stm32l-m24lr16e-i2c