2013-06-26 05:20 AM
2013-06-26 05:51 AM
I might have got something wrong, but:
while( stop_sent == 0 ); doesn't make sense to me. You are comparing a variable with a constant in a loop. On match, this loop is endless, otherwise a NOP.2013-06-26 06:39 AM
if( tx_idx == 7 ) /* send stop condition */
{
I2C3->CR1 |= I2C_CR1_STOP; /* generate a stop condition */
tx_idx++;
stop_sent = 1;
}
With the above code tx_idx will be 8 at least.Try something like this: if( tx_idx == 7 ) /* send stop condition */
{
if(!stop_sent)
{
I2C3->CR1 |= I2C_CR1_STOP; /* generate a stop condition */
stop_sent = 1;
}
}
2013-06-26 07:00 AM
Is stop_sent declared as volatile? Otherwise results are unpredictable.
Jack Peacock2013-07-12 05:14 AM
1. I had again cheked the code and noticed that even after sending stop conditoin code goes to following interrupt else part:
case I2C_EVENT_MASTER_BYTE_TRANSMITTING: /* EV8 , TRA, BUSY, MSL, TXE flags */
case I2C_EVENT_MASTER_BYTE_TRANSMITTED: /* EV8_2, TRA, BUSY, MSL, TXE and BTF flags */
if( tx_idx == 7 ) /* send stop condition */
{
I2C3->CR1 |= I2C_CR1_STOP; /* generate a stop condition */
tx_idx++;
stop_sent = 1;
}
else
{
I2C3->DR = tx_buffer[tx_idx++] ; /* Transmit the data */
}
2. Yes all vars are volatile.3. Coming back to ISR again indicates that there some ISR flag pending but I had cleared all by reading the registers, but don't what causes that. When code comes to stop condition in ISR then value of event var is = 0x00070080.4. Can anyone check at my code & see if my initialization stpes & ISR are correct2013-07-13 05:28 AM
STM32 doc says:
EV8_2: TxE=1, BTF = 1, Program Stop request. TxE and BTF are cleared by hardware by the Stop conditionI think you should setI2C_CR1_STOP
only when you get2C_EVENT_MASTER_BYTE_TRANSMITTED
(BTF=1). To me it looks like you handle one request which should be ignored.