Работаю с железкой по i2c, в основном "обращения" все по 1 байту - пишу адресс, читаю 1 байт. всё это работает. Но вот если хотя бы 2 байта, а то и более зависает приём на последнем байте.
Код
void MPU6050_I2C_BufferRead(u8 slaveAddr, u8* pBuffer, u8 readAddr, u16 NumByteToRead)
{
// ENTR_CRT_SECTION();
/* While the bus is busy */
//while (I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
/* Send START condition */
I2C_GenerateSTART(ENABLE);
/* Test on EV5 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
/* Send MPU6050 address for write */
I2C_Send7bitAddress(slaveAddr, I2C_DIRECTION_TX);
/* Test on EV6 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
/* Clear EV6 by setting again the PE bit */
I2C_Cmd(ENABLE);
/* Send the MPU6050's internal address to write to */
I2C_SendData(readAddr);
/* Test on EV8 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send STRAT condition a second time */
I2C_GenerateSTART(ENABLE);
/* Test on EV5 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
/* Send MPU6050 address for read */
I2C_Send7bitAddress(slaveAddr, I2C_DIRECTION_RX);
/* Test on EV6 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
volatile u8 t;
/* While there is data to be read */
while (NumByteToRead)
{
if (NumByteToRead == 1)
{
/* Disable Acknowledgement */
I2C_AcknowledgeConfig(I2C_ACK_NONE);
/* Send STOP Condition */
I2C_GenerateSTOP(ENABLE);
t=0;
}
/* Test on EV7 and clear it */
if (I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED))
{
/* Read a byte from the MPU6050 */
*pBuffer = I2C_ReceiveData();
/* Point to the next location where the byte read will be saved */
pBuffer++;
/* Decrement the read bytes counter */
NumByteToRead--;
}
}
/* Enable Acknowledgement to be ready for another reception */
I2C_AcknowledgeConfig(I2C_ACK_CURR);
// EXT_CRT_SECTION();
}
{
// ENTR_CRT_SECTION();
/* While the bus is busy */
//while (I2C_GetFlagStatus(I2C_FLAG_BUSBUSY));
/* Send START condition */
I2C_GenerateSTART(ENABLE);
/* Test on EV5 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
/* Send MPU6050 address for write */
I2C_Send7bitAddress(slaveAddr, I2C_DIRECTION_TX);
/* Test on EV6 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
/* Clear EV6 by setting again the PE bit */
I2C_Cmd(ENABLE);
/* Send the MPU6050's internal address to write to */
I2C_SendData(readAddr);
/* Test on EV8 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send STRAT condition a second time */
I2C_GenerateSTART(ENABLE);
/* Test on EV5 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_MODE_SELECT));
/* Send MPU6050 address for read */
I2C_Send7bitAddress(slaveAddr, I2C_DIRECTION_RX);
/* Test on EV6 and clear it */
while (!I2C_CheckEvent(I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
volatile u8 t;
/* While there is data to be read */
while (NumByteToRead)
{
if (NumByteToRead == 1)
{
/* Disable Acknowledgement */
I2C_AcknowledgeConfig(I2C_ACK_NONE);
/* Send STOP Condition */
I2C_GenerateSTOP(ENABLE);
t=0;
}
/* Test on EV7 and clear it */
if (I2C_CheckEvent(I2C_EVENT_MASTER_BYTE_RECEIVED))
{
/* Read a byte from the MPU6050 */
*pBuffer = I2C_ReceiveData();
/* Point to the next location where the byte read will be saved */
pBuffer++;
/* Decrement the read bytes counter */
NumByteToRead--;
}
}
/* Enable Acknowledgement to be ready for another reception */
I2C_AcknowledgeConfig(I2C_ACK_CURR);
// EXT_CRT_SECTION();
}
t=0; чтобы отладчиком туда попасть после STOP

Анализатором на щине i2c всё правильно - все байты приняты, последний NACK и STOP.
По коду же после STOP событие I2C_EVENT_MASTER_BYTE_RECEIVED не выставляется, но при 1 байте всё работает. Что я делаю не так? Да и код-то из примера STMовского...