本帖最后由 smartdog_1 于 2014-7-3 21:12 编辑
目前的代码如下:
#defined CPAL_I2C_DMA_PROGMODEL
//初始化I2C 数据结构
CPAL_I2C_DeInit(I2C_DevStructures[0]);
CPAL_I2C_StructInit(I2C_DevStructures[0]);
#ifdef CPAL_I2C_DMA_PROGMODEL
I2C_DevStructures[0]->wCPAL_Options = CPAL_OPT_I2C_NACK_ADD | CPAL_OPT_I2C_WAKEUP_STOP | CPAL_OPT_DMARX_TCIT;
I2C_DevStructures[0]->CPAL_ProgModel = CPAL_PROGMODEL_DMA;
#elif defined (CPAL_I2C_IT_PROGMODEL)
SLAVESTRUCTURE.wCPAL_Options = CPAL_OPT_I2C_NACK_ADD | CPAL_OPT_I2C_WAKEUP_STOP;
SLAVESTRUCTURE.CPAL_ProgModel = CPAL_PROGMODEL_INTERRUPT;
#else
#error "Please select one of the programming model (in main.h)"
#endif
/* Configure Own address 1 */
I2C_DevStructures[0]->pCPAL_I2C_Struct->I2C_OwnAddress1 = OWNADDRESS;
/* Set I2C Speed */
I2C_DevStructures[0]->pCPAL_I2C_Struct->I2C_Timing = SLAVE_I2C_TIMING;
/* Select Slave Mode */
I2C_DevStructures[0]->CPAL_Mode = CPAL_MODE_SLAVE;
/* Initialize I2Cx Device*/
CPAL_I2C_Init(I2C_DevStructures[0]);
/* Infinite loop */
while (1)
{
/* Reset BufferRX value */
memset(BufferRX, 0, (uint16_t)BufferSize);
/* Initialize Transfer parameters */
I2C_DevStructures[0]->pCPAL_TransferRx = &sRxStructure;
sRxStructure.wNumData = BufferSize;
sRxStructure.pbBuffer = (uint8_t*)BufferRX;
delay(10);
/* Read operation */
CPAL_I2C_Read(I2C_DevStructures[0]);
/* Enter Stop Mode and wait for interrupt to wake up */
//PWR_EnterSTOPMode(PWR_Regulator_LowPower, PWR_STOPEntry_WFI);
__WFI();
/* Wait until communication finishes */
while ((I2C_DevStructures[0]->CPAL_State != CPAL_STATE_READY)
&& (I2C_DevStructures[0]->CPAL_State != CPAL_STATE_ERROR));
/* Configure SystemClock*/
Restore_Configuration();
/* Configure and enable the systick timer to generate an interrupt each 1 ms */
SysTick_Config((SystemCoreClock / 1000));
/* If are received correctly */
if (Compare_bBuffer((uint8_t*)BufferTX, BufferRX, BufferSize) == PASSED )
{
/* Update LCD Display */
//LCD_DisplayStringLine(Line9, MESSAGE6);
}
else
{
/* Update LCD Display */
//LCD_DisplayStringLine(Line9, MESSAGE10);
}
delay(50);
}
在第九个时钟周期之后,SCL SDA都被托低,即使关闭了NOSTRETCH 也是一样。
|