2016-02-24 10:47 AM
2016-02-24 11:49 AM
I'd strongly recommend the use of local variables, and the volatile keyword where appropriate. A lot of this stuff doesn't need global scope and you can contain issues more tightly.
Absent an asynchronous reset you might need to clock jammed up I2C peripherals out of stuck states. Watch for appropriate speed settings, and pull-ups. Avoid software only delay loops, if you need delays of specific lengths, ie 100us or 10ms, you really need to pace them and time-outs against a timer. Otherwise your system will be marginal and dependent on code placement, register utilization or optimization levels.2016-02-24 12:52 PM
Ok, I will try to filter what you wrote tomorrow, I am really tired right now.
BTW that hung thing happened again and I have 3 screenshots with it!I would be really thankful if someone take a look at these:http://postimg.org/image/4s1b1fc9f/
UART seems strange, any idea what is happening there?2016-02-24 01:14 PM
I think you need to set your iteration variables to zero/known values before you enter while() loops.
When you reset the I2C peripheral when it is busy, do you actually reconfigure it again? Also not sure resetting the I2C clears anything attached to the bus, just the STM32 side of it.2016-02-25 01:41 AM
I took out this reset function now.
I am trying to adjust my code so it is not such a mess.Meanwhile can you please check this ? Sometimes the 9th clock pulse for ACK bit is delayed, and I can't figure out why.2016-02-25 07:37 AM
I am not getting that error what I was talking about earlier, but this STOP mode after NACK doesn't seem OK.
Can someone approve my routine for SMBus command write and receive?while (I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY))
{
asm('''');
}
I2C_TransferHandling(I2C1, 0x16, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Write);
I2C_SendData(I2C1, 0x8);
while (I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY))
{
asm('''');
}
I2C_TransferHandling(I2C1, 0x16, 1, I2C_SoftEnd_Mode, I2C_Generate_Start_Read);
while (I2C_GetFlagStatus(I2C1, I2C_FLAG_RXNE) == 0)
{
i++;
if (i == 10000)
{
i = 0;
break;
}
}
i = 0;
temp = I2C_ReceiveData(I2C1);