2012-07-06 01:02 AM
Hi,
With a STM32, I have a problemto select
either
EEPROM
(
M24LR64-R and M24M02-DR)on the same bus
I2C
.Here are the
''device
select
code
'':For
M24LR64
-R: 1 0 1 0 X 1 1 XIn the order
: 1 0 1 0 = Device type identifier X = E2 1 1 = E1 E0 ( chip enable) X = RWFor
M24M02
-DR:1 0 1
0 1
X
X
X
In the order
: 1 0 1 0 = Device type identifier 1 = E2 ( chip enable) X X = A17 A16 (MSB address bits ) X = RWThe two
address bits
A17
and
A16
for
M24M02
-DRcan not be
used
because they would
pose
a conflict with the
R
-
M24LR64there is
there a way
around the problem
?Thank you for your
response
, #pounds-head-on-desk2012-07-11 07:49 AM
Your test device select codes have bit 0 low which is a write. The data sheet suggests,
In I2C products, the device does not respond (NoAck) when a programming operation is in progress. Data polling thus consists in sending a Device Code in a loop mode and tracking the EEPROM acknowledgement. It is recommended to poll the device with a Write instruction. I'm not sure that helps! I still recommend writing your own bit bashed I2C - the ST implementation is very awkward and unforgiving.2012-07-11 07:57 AM
this has been confusing because sometimes the reference is to the
M24LR64-R and sometimes to the M24M02-DR anyhow I am sure you need to have A16and A17 the same when writing the address and switching to read, do you? Erik2012-07-11 07:57 AM
but A17 bit and A16 bit are selected in the device_selected so you have 4 devices on the bus? if not the above makes no sense
The single device contains 4 arrays of 64KB (ie 256KB or 2Mbit), which array is expressed in the address of the I2C device, not the offset expressed in the following two bytes. It's hanging presumably because the I2C device isn't ACKing because it doesn't recognize the address presented on the bus. Presenting some code might be instructive to see if there is an issue there.2012-07-11 08:22 AM
yes, it's the problem.. no ACK
the code:void
config_i2c()
{
unsigned
char
chip_select = 0xAC;
// 1010 1100
int
i = 0;
char
tx1_buffer[] =
''test''
;
char
rx1_buffer[100];
bzero(rx1_buffer,100);
I2C_InitTypeDef I2C_InitStructure;
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = chip_select;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = 100000;
I2C_Cmd(I2C1, ENABLE);
I2C_DeInit(I2C1);
printf
(
''strlen(tx1_buffer) = %d
''
,
strlen
(tx1_buffer));
I2C_Init(I2C1, &I2C_InitStructure);
while
(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
I2C_ITConfig(I2C1, I2C_IT_EVT | I2C_IT_BUF , ENABLE);
write_EEPROM(0x0, chip_select, tx1_buffer,
strlen
(tx1_buffer));
Delay_ms(5);
read_EEPROM(0x0, chip_select + 1, rx1_buffer,
strlen
(tx1_buffer));
printf
(
''donnees recues de l'eeprom: %s
''
, rx1_buffer);
}
void
write_EEPROM(uint16_t ReadAddr, unsigned
char
chip_select,
char
*ptx1_buffer,
int
len_tx1_buffer)
{
int
i = 0;
I2C_GenerateSTART(I2C1, ENABLE);
while
(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
/*!< Send EEPROM address for write */
I2C_Send7bitAddress(I2C1, chip_select , I2C_Direction_Transmitter);
while
(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData(I2C1, (uint8_t)((ReadAddr & 0xFF00) >> 8));
while
(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
I2C_SendData(I2C1, (uint8_t)(ReadAddr & 0x00FF));
while
(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
for
(i = 0 ; i < len_tx1_buffer ; i++)
{
I2C_SendData(I2C1,*ptx1_buffer);
ptx1_buffer ++;
while
(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
}
I2C_GenerateSTOP(I2C1, ENABLE);
while
(I2C1->CR1 & I2C_CR1_STOP);
}
2012-07-11 09:55 AM
anyhow I am sure you need to have A16and A17 the same when writing the address and switching to read, do you?
you do not show your read routine where the above is essential when you turn the bus. Please post it Erik
2012-07-12 12:07 AM
because that is
when I
send
I2C_Send7bitAddress(I2C1, chip_select , I2C_Direction_Transmitter); I have not received the ACK from the device2012-07-12 10:23 AM
Is the E2 pin on the chip tied to Vcc?
is the !WC pin on the chip tied to ground? Erik2012-07-16 12:40 AM
yes...