u8 i2c_read_register(u8 mem_address, u8 *data_read)
{
u8 temp = 0;
u8 ack = 0;
u8 polling_attempt = 0;

#ifdef POLLING
while ((ack) && (polling_attempt < POLLING_ATTEMPTS))
{
i2c_wait();
i2c_wait();
i2c_start();
polling_attempt++;
}
#endif
if (!ack)
{
i2c_repeat_start();
}

return ack;
}

• Notes In order to read two Byes I need to call the function Like This:

With (2) representing the Number of Bytes. But as the function stand it only takes two arguments not three.

• Have you considered calling i2c_read_byte() twice? – user207421 Aug 12 '15 at 11:20
• @EJP Yes, but its not working accordingly – mChad Aug 12 '15 at 11:22
• The Memory Address that I'm trying to read always return two bytes, First byte for Events, and 2nd Bytes for movement, so I have to specify reading the two bytes in my function. – mChad Aug 12 '15 at 11:26
• As suggested - call i2c_read_byte() with the two different addresses you are trying to read from. If this doesn't work, it implies that the device is expecting a multi-byte read and the data is not valid if this is not the case (you should already have seen this in the datasheet). In this case, try Googling "i2c multi-byte read" and "i2c repeated start condition". This info is normally included as a simple timing diagram in the datasheet too. – stefandz Aug 12 '15 at 11:40
• OK - so this is really about STM8 multi-byte reads. I haven't worked with STM8 parts before, but a quick Google on this brought up ST application note AN3281. That looks worth a read - but the fact I found something that quickly suggests you have not done much research on this. – stefandz Aug 12 '15 at 12:07

In the software package for the stm8 Eval board is an example project which is using a serial eeprom which is able to read multiple bytes.

sEE example software

• Yes I do I have the file, as you may have noticed I already Have a function that was working but only for reading a single byte. So I only wanted to modify it to read two Bytes instead of writing a whole new Function. – mChad Aug 13 '15 at 6:57

After Hours of Trying to modify the Code I finally managed to get the Specified two Bytes from my i2c_read_register() Function.

u8 i2c_read_register(u8 register_address, u8 *data_read, u8 NumbOfBytes)
{
u8 i;
u8 temp = 0;
u8 ack = 0;
u8 polling_attempt = 0;

#ifdef POLLING
while ((ack) && (polling_attempt < POLLING_ATTEMPTS))
{
i2c_wait();
i2c_wait();
i2c_start();
polling_attempt++;
}
#endif
if (!ack)
{
i2c_repeat_start();
if(NumbOfBytes > 1)
{
for(i = 0; i < NumbOfBytes -1; i++)
}
}

return ack;
}


All That was needed, was to add a for Loop Incrementing the Number of Bytes to read as input by user with the u8 NumbOfBytes variable.

And you call the function Like This:

i2c_start();