在线时间0 小时
UID94345
ST金币0
蝴蝶豆0
注册时间2008-11-26
新手上路
- 最后登录
- 1970-1-1
|
a0a.1 0b0c
万利的EK-STM32F板子,MDK3.22a调试,下面这段程序:
void DMA_I2C1Reception(I2C_RWTypeDef* I2C_DataStruct)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
CPU_SR cpu_sr;
#endif
u8 err;
DMA_I2C1RxStructure.DMA_MemoryBaseAddr = I2C_DataStruct->DataBuffer;
DMA_I2C1RxStructure.DMA_BufferSize = (u32)I2C_DataStruct->DataCount;
DMA_Init(DMA1_Channel7, &DMA_I2C1RxStructure);
OSSemPend(I2C1Sem, 0, &err);
CPU_CRITICAL_ENTER();
/*----- Transmission Phase -----*/
/* While the bus is busy */
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY));
/* Send I2C1 START condition */
I2C_GenerateSTART(I2C1, ENABLE);
/* Test on I2C1 EV5 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
/* Send I2C2 slave Address for write */
I2C_Send7bitAddress(I2C1, I2C_DataStruct->DeviceAddr, I2C_Direction_Transmitter);
/* Test on I2C1 EV6 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
/* Clear EV6 by setting again the PE bit */
I2C_Cmd(I2C1, ENABLE);
/* Send the EEPROM's internal address to write to */
I2C_SendData(I2C1, I2C_DataStruct->DataAddr);
/* Test on EV8 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send STRAT condition a second time */
I2C_GenerateSTART(I2C1, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
/* Send EEPROM address for read */
I2C_Send7bitAddress(I2C1, I2C_DataStruct->DeviceAddr, I2C_Direction_Receiver);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
/* Specifies that the next DMA transfer is the last one */
I2C_DMALastTransferCmd(I2C1, ENABLE);
/* Enable I2C1 DMA */
I2C_DMACmd(I2C1, ENABLE);
CPU_CRITICAL_EXIT();
/* Enable DMA1 Channel7, Start I2C1_DMA reception */
DMA_Cmd(DMA1_Channel7, ENABLE);
}
全速执行时程序在第三个的while死循环了,于是我这样试了一下:全速执行到这一行while(这一行还没执行,Run to Cursor line),查看SR1=0x0400,SR2=0x0003,出现了AF失败。试了第二种结果,全速执行到I2C_Send7bitAddress(I2C1, I2C_DataStruct->DeviceAddr, I2C_Direction_Transmitter);(Run to Cursor line)再F10(Step Over)执行这行,又出现了AF失败。又试了第三种结果,全速执行到I2C_GenerateSTART(I2C1, ENABLE);(这一行还没执行),查看SR1=SR2=0x0000,再全速执行到I2C_Cmd(I2C1, ENABLE);(这一行还没被执行,Run to Cursor line),正常。
这都是ST官方的操作流程,现在有点不明白I2C该如何操作了? |
|