cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L -> I2C -> M24LR16E

jesperhede
Associate II
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
1 ACCEPTED SOLUTION

Accepted Solutions
Posted on December 08, 2015 at 17:28

Hello

I2C_Send7bitAddress(I2C1, 0xA6, I2C_Direction_Transmitter);

 

-> for STM32L i2c library (Hold library, please use Cube library), the 7bit format I2C_Address byte (0xA6 ) has to be written 0x93 (shift 1 bit @ right).

This is the reason why the device doesn't ACK to Device Select request.

In addition, reading your code, there is a mistake on

''

Send address byte

''

part of your code : the M24LR has 2 address bytes.

To help you to complete your program, this is in attached file, ,an example of I2C code for STM32L.

But again, please, uses CUBE platform, easier to compile and use.

Best regards

ST NFC customer support

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);

________________

Attachments :

I2C_M24LR04E-R.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzMN&d=%2Fa%2F0X0000000bKU%2FAxJ1h1LeSGIBW7EXI4mSxkvsxEdMmA2E4MlIpXmBQAM&asPdf=false

View solution in original post

1 REPLY 1
Posted on December 08, 2015 at 17:28

Hello

I2C_Send7bitAddress(I2C1, 0xA6, I2C_Direction_Transmitter);

 

-> for STM32L i2c library (Hold library, please use Cube library), the 7bit format I2C_Address byte (0xA6 ) has to be written 0x93 (shift 1 bit @ right).

This is the reason why the device doesn't ACK to Device Select request.

In addition, reading your code, there is a mistake on

''

Send address byte

''

part of your code : the M24LR has 2 address bytes.

To help you to complete your program, this is in attached file, ,an example of I2C code for STM32L.

But again, please, uses CUBE platform, easier to compile and use.

Best regards

ST NFC customer support

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);

________________

Attachments :

I2C_M24LR04E-R.c : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006HzMN&d=%2Fa%2F0X0000000bKU%2FAxJ1h1LeSGIBW7EXI4mSxkvsxEdMmA2E4MlIpXmBQAM&asPdf=false