This thread has been locked.
If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.
Hi,
I have very little experience of using I2C, so there's a lot I don't know. So, I'm trying the get this working by starting with the example code in the HalCoGen directories. I have a slightly modified version of this loopback code, so that I can see what's going on.
I understand the BB flag is cleared when a STOP condition is set. On real communications between micros and looking on a logic analyser I don't ever see this happen. The code shown captures the state of the BB flag on the example code and it doesn't clear either. (see screenshot)
First question: am I right in saying that if the BB flag is set this will prevent other devices from sending messages to the master? If so this would be bad, because I'm looking to implement multi-master comms.
Second question: The datasheet states the ICCNT causes STOP to be generated when this is zero, but ICCNT doesn't appear to change. Calling i2cSetStop() HalCoGen function also doesn't set a STOP.
I have spent all week on this and it's driving me crazy. For the sake of my sanity, please help.
Andy
Hello Andy,
1. The I2C module on this device does support multi-master transmitter/receiver modes.
2. The stop condition is generated when ICCNT passes 0 when the I2C is in non-repeat mode (RM=0). In repeat mode (RM=1), the stop condition is generated if STP bit is 1
Let me put it another way. If STOP is generated by ICCNT decrementing to 0, what sets the initial value, given that neither of the HalCoGen functions i2cSendByte or i2cSend access this register?
Hello,
1. No, I didn't say that TRM is wrong.
2. Both i2cSendByte and i2cSend don't use ICCNT. You need to set the ICCNT using i2cREG1->CNT = DATA_COUNT if you want to generate the STOP automatically after transmitting ICCNT data.
You don't have to use ICCNT to generate STOP bit when the I2C is in non-repeat mode (RM=0 mode). i2c->MDR |= ( 1<<11) can generate a STOP.