2018-05-06 03:51 PM
Hello, i have a STM8L Discovery board with a stm8l152C6T6 microcontroller. I'm currently trying to communicate with a M24LR04E (NFC) board through an I2C connection.
I've done some tests using the 'generateStart' function, that appears to be working fine:
I2C_GenerateSTART
(
I2C1,
ENABLE)
;
while
(
!
I2C_CheckEvent
(
I2C1
,
I2C_EVENT_MASTER_MODE_SELECT
)
)
;
However, when trying to send data to the board through 'send7bits' function, my code get stuck on the next 'while' construction without any apparent reason:
(
I2C1,
(
uint8_t
)
I2C_Slave_Adress,
I2C_Direction_Receiver)
;
while
(
!
I2C_CheckEvent(
I2C1,
I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)
)
;
//This while never stops
Additionally, I've tried other examples available through ST documentation ('I2C EEPROM' / 'I2C TWOBOARDS') without success.
Any clue regarding what is happening will be very appreciated.Thanks!
The complete source code:
Circuit :
// The jumper has been set on#i2c #eeprom #m24lr04e-r #stm8l-discovery #nfc2018-06-13 11:06 PM
Hi everyone, I have the same issue here. I am trying to use the MAX44009 i2C sensor and I am also stuck inside the same loop.
This function I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED) always return 0 and keep the while loop looping.
I put some UART printf inside the for loop to check the event and it always outputs 0:
while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
{printf('%d ',I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));printf('%d\n',I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));Delay(10);}// 0 0 foreverThanks for any help in advance!
2018-06-14 12:37 AM
Problem partly solved, it is because the address is not the correct for my case.
You need to manually shift the slave address by 1 for the function:
void I2C_Send7bitAddress(I2C1,addr << 1, I2C_Direction_Trasmitter);
I think there is a huge room of improvement for the documentation of the library...Credit to:
2018-06-14 03:58 AM
I read though the data sheet of the sensor and the example of the SPL. To be honest , when I see there is a parameter for transceiver and receiver, I automatically think the library will shift the bit for me...
2018-06-14 05:07 AM
'
You need to manually shift the slave address by 1 for the function'that's often the case with i2c addresses. I usually just use 8-bit address notation with the last bit being write/read command.
2018-06-14 05:51 AM
That, and a lot of the I2C documentation for the parts is inconsistent. If I'm unsure I go to the documentation because even when they quote the address as number they usually describe the bitmapping in a table somewhere else, explicitly showing the bits on the wire for a read or write. The confusion is usually because the 7-bit address is the 7 most significant bits and the R/W flag the least significant bit.
2018-06-14 06:38 AM
>>I automatically think the library will shift the bit for me...
I think ST has a 10+ year history of not doing that. My experience across ATMEL, PHILIPS, NXP, TI, etc are mixed, one of the things you have to double-check, and thankfully I2C alerts you when you're not seeing the device on the bus responding, either because the address is wrong, or the device isn't populated/connected.