本文整理汇总了C++中I2C_DMALastTransferCmd函数的典型用法代码示例。如果您正苦于以下问题:C++ I2C_DMALastTransferCmd函数的具体用法?C++ I2C_DMALastTransferCmd怎么用?C++ I2C_DMALastTransferCmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了I2C_DMALastTransferCmd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: I2C_AcknowledgeConfig
void i2cMgr_t::ReadMany() {
// Enable Acknowledgement
I2C_AcknowledgeConfig(I2C1, ENABLE);
// Prepare DMA
DMA_DeInit(I2C_DMA_CHNL_RX);
DMA_InitTypeDef DMA_InitStructure;
//DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t) &I2C1->DR;
DMA_InitStructure.DMA_PeripheralBaseAddr = 0x40005410;
// Decide where to read data to
if(CmdToRead->DataToRead.Buf == 0) { // no need in this data
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) &CmdToRead->DataToRead.InnerBuf[0]; // dummy place
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; // Do not move pointer
}
else {
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t) &CmdToRead->DataToRead.Buf[0];
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
}
DMA_InitStructure.DMA_BufferSize = CmdToRead->DataToRead.Length;
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; // From I2C to memory
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_Medium;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(I2C_DMA_CHNL_RX, &DMA_InitStructure);
//Inform the DMA that the next End Of Transfer Signal will be the last one, need to send NACK after last byte
I2C_DMALastTransferCmd(I2C1, ENABLE);
// Start transmission
I2C_DMACmd(I2C1, ENABLE); // Enable DMA
DMA_Cmd(I2C_DMA_CHNL_RX, ENABLE); // Enable DMA channel
Delay.Reset(&Timer);
}
示例2: I2C1_Write
int16_t I2C1_Write(uint8_t * buffer, uint8_t address, uint16_t length)
{
int16_t return_code = pdTRUE;
uint16_t bytes_sent = 0;
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY)) {} /*TODO: Timeout*/
I2C_GenerateSTART(I2C1, ENABLE);
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) {}
I2C_Send7bitAddress(I2C1, address, I2C_Direction_Transmitter);
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)) {}
I2C1_DMA_TX_Semaphore = 0;
if (length < 2)
{
while (bytes_sent < length)
{
I2C_SendData(I2C1, buffer[bytes_sent]);
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BTF) == RESET) {}
bytes_sent++;
}
I2C_GenerateSTOP(I2C1, ENABLE);
while(I2C1->CR1 & I2C_CR1_STOP) {}
}
else
{
I2C1_DMAConfig((uint32_t)buffer, length, DIR_TX);
I2C_DMALastTransferCmd(I2C1, ENABLE);
DMA_Cmd(I2C1_DMA_STREAM_TX, ENABLE);
I2C_DMACmd(I2C1, ENABLE);
/* Wait for DMA interrupt */
while (I2C1_DMA_TX_Semaphore == 0) {}
}
return return_code;
}
示例3: I2C_DMA_Read
void I2C_DMA_Read(u8 slaveAddr, u8 readAddr)
{
/* Disable DMA channel*/
DMA_Cmd(DMA1_Channel7, DISABLE);
/* Set current data number again to 14 for MPu6050, only possible after disabling the DMA channel */
DMA_SetCurrDataCounter(DMA1_Channel7, 14);
/* While the bus is busy */
while(I2C_GetFlagStatus(MPU6050_I2C, I2C_FLAG_BUSY));
/* Enable DMA NACK automatic generation */
I2C_DMALastTransferCmd(MPU6050_I2C, ENABLE); //Note this one, very important
/* Send START condition */
I2C_GenerateSTART(MPU6050_I2C, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(MPU6050_I2C, I2C_EVENT_MASTER_MODE_SELECT));
/* Send MPU6050 address for write */
I2C_Send7bitAddress(MPU6050_I2C, slaveAddr, I2C_Direction_Transmitter);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(MPU6050_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
/* Clear EV6 by setting again the PE bit */
I2C_Cmd(MPU6050_I2C, ENABLE);
/* Send the MPU6050's internal address to write to */
I2C_SendData(MPU6050_I2C, readAddr);
/* Test on EV8 and clear it */
while(!I2C_CheckEvent(MPU6050_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send STRAT condition a second time */
I2C_GenerateSTART(MPU6050_I2C, ENABLE);
/* Test on EV5 and clear it */
while(!I2C_CheckEvent(MPU6050_I2C, I2C_EVENT_MASTER_MODE_SELECT));
/* Send MPU6050 address for read */
I2C_Send7bitAddress(MPU6050_I2C, slaveAddr, I2C_Direction_Receiver);
/* Test on EV6 and clear it */
while(!I2C_CheckEvent(MPU6050_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
/* Start DMA to receive data from I2C */
DMA_Cmd(DMA1_Channel7, ENABLE);
I2C_DMACmd(MPU6050_I2C, ENABLE);
// When the data transmission is complete, it will automatically jump to DMA interrupt routine to finish the rest.
//now go back to the main routine
}
示例4: i2c_dma_read
void i2c_dma_read( u8 read_addr)
{
// read_addr +=1;
//disable dma channel
DMA_Cmd( MPU6050_DMA_CHANNEL, DISABLE);
//? set current data number again to 14
DMA_SetCurrDataCounter(MPU6050_DMA_CHANNEL, 14);
//while the bus is busy
while( I2C_GetFlagStatus( MPU6050_I2C,I2C_FLAG_BUSY));
//enable dma nack automatic generation.....
I2C_DMALastTransferCmd( MPU6050_I2C, ENABLE);
//send start condition
I2C_GenerateSTART( MPU6050_I2C, ENABLE);
//test on ev5 and clear it
while( !I2C_CheckEvent( MPU6050_I2C, I2C_EVENT_MASTER_MODE_SELECT));
//send mpu6050 address for write
I2C_Send7bitAddress( MPU6050_I2C, I2C1_MPU6050, I2C_Direction_Transmitter );
//test on ev6 and clear it
while( !I2C_CheckEvent(MPU6050_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
//clear ev6 by setting again the PE bit
I2C_Cmd( MPU6050_I2C,ENABLE);
//send the mpu6050 internal address to write to
I2C_SendData( MPU6050_I2C, read_addr);
//test on ev8 and clear it
while(!I2C_CheckEvent( MPU6050_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
//send start condition a second time
I2C_GenerateSTART(MPU6050_I2C, ENABLE);
//test on ev5 and clear it
while( !I2C_CheckEvent(MPU6050_I2C, I2C_EVENT_MASTER_MODE_SELECT));
//send mpu6050 address for read
I2C_Send7bitAddress(MPU6050_I2C,I2C1_MPU6050, I2C_Direction_Receiver);
//test on ev6 and clear it
while( !I2C_CheckEvent( MPU6050_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED));
//start dma to receive data from i2c
DMA_Cmd(MPU6050_DMA_CHANNEL, ENABLE);
I2C_DMACmd(MPU6050_I2C, ENABLE);
//when the data transmission is complete, it will automatically jump to dma interrupt routine
//to finish the rest.
}
示例5: I2C_ReadBytes
/*=====================================================================================================*/
u32 I2C_ReadBytes(u8 SlaveAddr, u8 *ReadBuf, u8 NumByte)
{
I2C_ReadPtr = &NumByte;
I2C_GenerateSTART(I2Cx, ENABLE);
I2C_TimeCnt = I2C_TIMEOUT;
while (!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT))
if ((I2C_TimeCnt--) == 0) return I2C_TimeOut();
I2C_Send7bitAddress(I2Cx, SlaveAddr, I2C_Direction_Receiver);
I2C_TimeCnt = I2C_TIMEOUT;
while (!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
if ((I2C_TimeCnt--) == 0) return I2C_TimeOut();
DMA_InitStruct.DMA_Channel = DMAx_RX_CHANNEL;
DMA_InitStruct.DMA_PeripheralBaseAddr = (u32)I2Cx_DR_ADDR;
DMA_InitStruct.DMA_Memory0BaseAddr = (u32)ReadBuf;
DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStruct.DMA_BufferSize = (u32)(NumByte);
DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStruct.DMA_Mode = DMA_Mode_Normal;
DMA_InitStruct.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStruct.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStruct.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStruct.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStruct.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMAx_RX_STREAM, &DMA_InitStruct);
I2C_DMALastTransferCmd(I2Cx, ENABLE);
DMA_Cmd(DMAx_RX_STREAM, ENABLE);
I2C_TimeCnt = I2C_TIMEOUT;
while (NumByte > 0)
if ((I2C_TimeCnt--) == 0) return I2C_TimeOut();
return SUCCESS;
}
示例6: i2c1_recv_bytes
static rt_size_t i2c1_recv_bytes(struct rt_i2c_msg *msg)
{
rt_size_t bytes = 0;
rt_size_t len = msg->len;
DMA_InitTypeDef DMA_InitStructure;
if (len < 2)
{
I2C_AcknowledgeConfig(I2Cx,
msg->flags & RT_I2C_NO_READ_ACK?DISABLE:ENABLE);
(void)I2Cx->SR2;
I2C_GenerateSTOP(I2Cx, ENABLE);
while (I2C_GetFlagStatus(I2Cx, I2C_FLAG_RXNE) == RESET);
msg->buf[bytes++] = I2C_ReceiveData(I2Cx);
while (I2Cx->CR1 & I2C_CR1_STOP);
I2C_AcknowledgeConfig(I2Cx, ENABLE);
return 1;
}
else
{
DMA_InitStructure.DMA_PeripheralBaseAddr = (u32)I2Cx_DR_ADDR;
DMA_InitStructure.DMA_MemoryBaseAddr = (u32)(msg->buf);
DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC;
DMA_InitStructure.DMA_BufferSize = msg->len;
DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStructure.DMA_Mode = DMA_Mode_Normal;
DMA_InitStructure.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStructure.DMA_M2M = DMA_M2M_Disable;
DMA_Init(DMAx_RX_CHANNEL, &DMA_InitStructure);
I2C_DMALastTransferCmd(I2Cx, ENABLE);
DMA_Cmd(DMAx_RX_CHANNEL, ENABLE);
//Check finshed
if(rt_sem_take(&DMA_RX_Sem,20)!=RT_EOK)
return 0;
}
return len;
}
示例7: I2C1_Read
int16_t I2C1_Read(uint8_t * buffer, uint8_t address, uint16_t length)
{
int16_t return_code = pdTRUE;
uint16_t bytes_received = 0;
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_BUSY)) {} /*TODO: Timeout*/
I2C_GenerateSTART(I2C1, ENABLE);
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) {}
I2C_Send7bitAddress(I2C1, address, I2C_Direction_Receiver);
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_ADDR) == RESET) {}
I2C1_DMA_RX_Semaphore = 0;
if (length < 2)
{
I2C_AcknowledgeConfig(I2C1, DISABLE);
(void)I2C1->SR2;
I2C_GenerateSTOP(I2C1, ENABLE);
while(I2C_GetFlagStatus(I2C1, I2C_FLAG_RXNE) == RESET) {}
if (length > 0)
{
buffer[bytes_received] = I2C_ReceiveData(I2C1);
}
while(I2C1->CR1 & I2C_CR1_STOP) {}
I2C_AcknowledgeConfig(I2C1, ENABLE);
}
else
{
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)) {}
I2C1_DMAConfig((uint32_t)buffer, length, DIR_RX);
I2C_DMALastTransferCmd(I2C1, ENABLE);
DMA_Cmd(I2C1_DMA_STREAM_RX, ENABLE);
I2C_DMACmd(I2C1, ENABLE);
/* Wait for DMA interrupt */
while (I2C1_DMA_RX_Semaphore == 0) {}
}
return return_code;
}
示例8: LM75_ReadConfReg
/**
* @brief Read the configuration register from the LM75.
* @param None
* @retval LM75 configuration register value.
*/
uint8_t LM75_ReadConfReg(void)
{
uint8_t LM75_BufferRX[2] ={0,0};
/* Test on BUSY Flag */
LM75_Timeout = LM75_LONG_TIMEOUT;
while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Configure DMA Peripheral */
LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2);
/* Enable DMA NACK automatic generation */
I2C_DMALastTransferCmd(LM75_I2C, ENABLE);
/* Enable the I2C peripheral */
I2C_GenerateSTART(LM75_I2C, ENABLE);
/* Test on SB Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send device address for write */
I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
/* Test on ADDR Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send the device's internal address to write to */
I2C_SendData(LM75_I2C, LM75_REG_CONF);
/* Test on TXE FLag (data sent) */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send START condition a second time */
I2C_GenerateSTART(LM75_I2C, ENABLE);
/* Test on SB Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send LM75 address for read */
I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
/* Test on ADDR Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Enable I2C DMA request */
I2C_DMACmd(LM75_I2C,ENABLE);
/* Enable DMA RX Channel */
DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);
/* Wait until DMA Transfer Complete */
LM75_Timeout = LM75_LONG_TIMEOUT;
while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send STOP Condition */
I2C_GenerateSTOP(LM75_I2C, ENABLE);
/* Disable DMA RX Channel */
DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);
/* Disable I2C DMA request */
I2C_DMACmd(LM75_I2C,DISABLE);
/* Clear DMA RX Transfer Complete Flag */
DMA_ClearFlag(LM75_DMA_RX_TCFLAG);
/*!< Return Temperature value */
return (uint8_t)LM75_BufferRX[0];
}
示例9: I2C_ReadDataBuffer
/**
* @brief Reads a buffer of 2 bytes from the device registers.
* @param DeviceAddr: The address of the device, could be : IOE_1_ADDR
* or IOE_2_ADDR.
* @param RegisterAddr: The target register adress (between 00x and 0x24)
* @retval A pointer to the buffer containing the two returned bytes (in halfword).
*/
uint16_t I2C_ReadDataBuffer(uint8_t DeviceAddr, uint32_t RegisterAddr)
{
uint8_t tmp= 0;
uint8_t IOE_BufferRX[2] = {0x00, 0x00};
/* Configure DMA Peripheral */
IOE_DMA_Config(IOE_DMA_RX, (uint8_t*)IOE_BufferRX);
/* Enable DMA NACK automatic generation */
I2C_DMALastTransferCmd(IOE_I2C, ENABLE);
/* Enable the I2C peripheral */
I2C_GenerateSTART(IOE_I2C, ENABLE);
/* Test on SB Flag */
IOE_TimeOut = TIMEOUT_MAX;
while (!I2C_GetFlagStatus(IOE_I2C,I2C_FLAG_SB))
{
if (IOE_TimeOut-- == 0) return(IOE_TimeoutUserCallback());
}
/* Send device address for write */
I2C_Send7bitAddress(IOE_I2C, DeviceAddr, I2C_Direction_Transmitter);
/* Test on ADDR Flag */
IOE_TimeOut = TIMEOUT_MAX;
while (!I2C_CheckEvent(IOE_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
{
if (IOE_TimeOut-- == 0) return(IOE_TimeoutUserCallback());
}
/* Send the device's internal address to write to */
I2C_SendData(IOE_I2C, RegisterAddr);
/* Test on TXE FLag (data dent) */
IOE_TimeOut = TIMEOUT_MAX;
while ((!I2C_GetFlagStatus(IOE_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(IOE_I2C,I2C_FLAG_BTF)))
{
if (IOE_TimeOut-- == 0) return(IOE_TimeoutUserCallback());
}
/* Send START condition a second time */
I2C_GenerateSTART(IOE_I2C, ENABLE);
/* Test on SB Flag */
IOE_TimeOut = TIMEOUT_MAX;
while (!I2C_GetFlagStatus(IOE_I2C,I2C_FLAG_SB))
{
if (IOE_TimeOut-- == 0) return(IOE_TimeoutUserCallback());
}
/* Send IOExpander address for read */
I2C_Send7bitAddress(IOE_I2C, DeviceAddr, I2C_Direction_Receiver);
/* Test on ADDR Flag */
IOE_TimeOut = TIMEOUT_MAX;
while (!I2C_CheckEvent(IOE_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
{
if (IOE_TimeOut-- == 0) return(IOE_TimeoutUserCallback());
}
/* Enable I2C DMA request */
I2C_DMACmd(IOE_I2C,ENABLE);
/* Enable DMA RX Channel */
DMA_Cmd(IOE_DMA_RX_CHANNEL, ENABLE);
/* Wait until DMA Transfer Complete */
IOE_TimeOut = 2 * TIMEOUT_MAX;
while (!DMA_GetFlagStatus(IOE_DMA_RX_TCFLAG))
{
if (IOE_TimeOut-- == 0) return(IOE_TimeoutUserCallback());
}
/* Send STOP Condition */
I2C_GenerateSTOP(IOE_I2C, ENABLE);
/* Disable DMA RX Channel */
DMA_Cmd(IOE_DMA_RX_CHANNEL, DISABLE);
/* Disable I2C DMA request */
I2C_DMACmd(IOE_I2C,DISABLE);
/* Clear DMA RX Transfer Complete Flag */
DMA_ClearFlag(IOE_DMA_RX_TCFLAG);
/* Reorganize received data */
tmp = IOE_BufferRX[0];
IOE_BufferRX[0] = IOE_BufferRX[1];
IOE_BufferRX[1] = tmp;
/* return a pointer to the IOE_Buffer */
return *(uint16_t *)IOE_BufferRX;
//.........这里部分代码省略.........
示例10: main
//.........这里部分代码省略.........
I2C_DMACmd(I2Cx, DISABLE);
/* Wait until BTF Flag is set before generating STOP or time out */
TimeOut = USER_TIMEOUT;
while ((!I2C_GetFlagStatus(I2Cx,I2C_FLAG_BTF))&&(TimeOut != 0x00))
{}
if(TimeOut == 0)
{
TimeOut_UserCallback();
}
/* Send I2Cx STOP Condition */
I2C_GenerateSTOP(I2Cx, ENABLE);
/* Disable DMA TX Channel */
DMA_Cmd(I2Cx_DMA_STREAM_TX, DISABLE);
/* Wait until I2Cx_DMA_STREAM_TX disabled or time out */
TimeOut = USER_TIMEOUT;
while ((DMA_GetCmdStatus(I2Cx_DMA_STREAM_TX)!= DISABLE)&&(TimeOut != 0x00))
{}
if(TimeOut == 0)
{
TimeOut_UserCallback();
}
/* Clear any pending flag on Tx Stream */
DMA_ClearFlag(I2Cx_DMA_STREAM_TX, I2Cx_TX_DMA_TCFLAG | I2Cx_TX_DMA_FEIFLAG | I2Cx_TX_DMA_DMEIFLAG | \
I2Cx_TX_DMA_TEIFLAG | I2Cx_TX_DMA_HTIFLAG);
/* Master Receiver -----------------------------------------------------------*/
/* Enable DMA NACK automatic generation */
I2C_DMALastTransferCmd(I2Cx, ENABLE);
/* Send I2Cx START condition */
I2C_GenerateSTART(I2Cx, ENABLE);
#ifdef I2C_10BITS_ADDRESS
/* Test on EV5 and clear it or time out */
TimeOut = USER_TIMEOUT;
while ((!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT))&&(TimeOut != 0x00))
{}
if(TimeOut == 0)
{
TimeOut_UserCallback();
}
/* Send Header to Slave for write */
I2C_SendData(I2Cx, HEADER_ADDRESS_Write);
/* Test on EV9 and clear it or time out */
TimeOut = USER_TIMEOUT;
while ((!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_ADDRESS10))&&(TimeOut != 0x00))
{}
if(TimeOut == 0)
{
TimeOut_UserCallback();
}
/* Send slave Address */
I2C_Send7bitAddress(I2Cx, (uint8_t)SLAVE_ADDRESS, I2C_Direction_Transmitter);
/* Test on I2Cx EV6 and clear it or time out*/
TimeOut = USER_TIMEOUT;
while ((!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))&&(TimeOut != 0x00))
{}
if(TimeOut == 0)
示例11: sEE_ReadBuffer
//.........这里部分代码省略.........
sEEDataReadPointer = NumByteToRead;
/*!< While the bus is busy */
while(I2C_GetFlagStatus(sEE_I2C, I2C_FLAG_BUSY))
{
}
/*!< Send START condition */
I2C_GenerateSTART(sEE_I2C, ENABLE);
/*!< Test on EV5 and clear it */
while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT))
{
}
/*!< Send EEPROM address for write */
I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Transmitter);
/*!< Test on EV6 and clear it */
while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
{
}
#ifdef sEE_M24C08
/*!< Send the EEPROM's internal address to read from: Only one byte address */
I2C_SendData(sEE_I2C, ReadAddr);
#elif defined (sEE_M24C64_32)
/*!< Send the EEPROM's internal address to read from: MSB of the address first */
I2C_SendData(sEE_I2C, (uint8_t)((ReadAddr & 0xFF00) >> 8));
/*!< Test on EV8 and clear it */
while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
{
}
/*!< Send the EEPROM's internal address to read from: LSB of the address */
I2C_SendData(sEE_I2C, (uint8_t)(ReadAddr & 0x00FF));
#endif /*!< sEE_M24C08 */
/*!< Test on EV8 and clear it */
while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_TRANSMITTED))
{
}
/*!< Send STRAT condition a second time */
I2C_GenerateSTART(sEE_I2C, ENABLE);
/*!< Test on EV5 and clear it */
while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_MODE_SELECT))
{
}
/*!< Send EEPROM address for read */
I2C_Send7bitAddress(sEE_I2C, sEEAddress, I2C_Direction_Receiver);
/*!< Test on EV6 and clear it */
while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
{
}
/* If number of data to be read is 1, then DMA couldn't be used */
if ((uint16_t)(*NumByteToRead) < 2)
{
/*!< Disable Acknowledgement */
I2C_AcknowledgeConfig(sEE_I2C, DISABLE);
/*!< Send STOP Condition */
I2C_GenerateSTOP(sEE_I2C, ENABLE);
/*!< Test on EV7 and clear it */
while(!I2C_CheckEvent(sEE_I2C, I2C_EVENT_MASTER_BYTE_RECEIVED))
{
}
/*!< Read a byte from the EEPROM */
*pBuffer = I2C_ReceiveData(sEE_I2C);
/*!< Decrement the read bytes counter */
(uint16_t)(*NumByteToRead)--;
/*!< Enable Acknowledgement to be ready for another reception */
I2C_AcknowledgeConfig(sEE_I2C, ENABLE);
}
/* DMA could be used for number of data higher than 1 */
else
{
/* Configure the DMA Rx Channel with the buffer address and the buffer size */
sEE_LowLevel_DMAConfig((uint32_t)pBuffer, (uint16_t)(*NumByteToRead), sEE_DIRECTION_RX);
/* Inform the DMA that the next End Of Transfer Signal will be the last one */
I2C_DMALastTransferCmd(sEE_I2C, ENABLE);
/* Enable the DMA Rx Channel */
DMA_Cmd(sEE_I2C_DMA_CHANNEL_RX, ENABLE);
}
}
示例12: I2C_readBytes
/**
* @brief Read the data from the chip.
* @param RegName: specifies the register to be read.
* This member can be one of the following values:
* @retval status communication.
*/
I2C_Status_TypeDef I2C_readBytes(uint8_t devAddr, uint8_t RegName,uint8_t length,uint8_t *buffer, uint32_t timeout)
{
uint32_t zero_time;
/* Configure DMA Peripheral */
I2C_DMA_Config(I2C_DMA_RX, buffer, length);
/* Enable DMA NACK automatic generation */
I2C_DMALastTransferCmd(I2C_USE, ENABLE);
//Start condition
I2C_GenerateSTART(I2C_USE, ENABLE);
zero_time = GetTickCount();
while (!I2C_GetFlagStatus(I2C_USE,I2C_FLAG_SB))
{
if(CheckTick(zero_time,timeout) == TRUE)
{
return I2C_STATUS_TIMEOUT;
}
}
//Send device address for write
I2C_Send7bitAddress(I2C_USE, devAddr, I2C_Direction_Transmitter);
zero_time = GetTickCount();
while (!I2C_CheckEvent(I2C_USE, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
{
if(CheckTick(zero_time,timeout) == TRUE) return I2C_STATUS_TIMEOUT;
}
/* Send the device's internal address to write to */
I2C_SendData(I2C_USE, RegName);
zero_time = GetTickCount();
while ((!I2C_GetFlagStatus(I2C_USE,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(I2C_USE,I2C_FLAG_BTF)))
{
if(CheckTick(zero_time,timeout) == TRUE) return I2C_STATUS_TIMEOUT;
}
/* Send START condition a second time */
I2C_GenerateSTART(I2C_USE, ENABLE);
/* Test on SB Flag */
zero_time = GetTickCount();
while (!I2C_GetFlagStatus(I2C_USE,I2C_FLAG_SB))
{
if(CheckTick(zero_time,timeout) == TRUE) return I2C_STATUS_TIMEOUT;
}
/* Send address for read */
I2C_Send7bitAddress(I2C_USE, devAddr, I2C_Direction_Receiver);
/* Test on ADDR Flag */
zero_time = GetTickCount();
while (!I2C_CheckEvent(I2C_USE, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
{
if(CheckTick(zero_time,timeout) == TRUE) return I2C_STATUS_TIMEOUT;
}
/* Enable I2C DMA request */
I2C_DMACmd(I2C_USE,ENABLE);
/* Enable DMA RX Channel */
DMA_Cmd(I2C_DMA_RX_CHANNEL, ENABLE);
/* Wait until DMA Transfer Complete */
zero_time = GetTickCount();
while (!DMA_GetFlagStatus(I2C_DMA_RX_TCFLAG))
{
if(CheckTick(zero_time,timeout) == TRUE) return I2C_STATUS_TIMEOUT;
}
/* Send STOP Condition */
I2C_GenerateSTOP(I2C_USE, ENABLE);
/* Disable DMA RX Channel */
DMA_Cmd(I2C_DMA_RX_CHANNEL, DISABLE);
/* Disable I2C DMA request */
I2C_DMACmd(I2C_USE,DISABLE);
/* Clear DMA RX Transfer Complete Flag */
DMA_ClearFlag(I2C_DMA_RX_TCFLAG);
/* return a Reg value */
return I2C_STATUS_SUCCESS;
}
示例13: I2C_DMA_ReadReg
/*=====================================================================================================*/
u32 I2C_DMA_ReadReg(u8 SlaveAddr, u8 ReadAddr, u8 *ReadBuf, u8 NumByte)
{
I2C_ReadPtr = &NumByte;
I2C_TimeCnt = I2C_TIMEOUT;
while (I2C_GetFlagStatus(I2Cx, I2C_FLAG_BUSY))
if ((I2C_TimeCnt--) == 0) return I2C_TimeOut();
I2C_GenerateSTART(I2Cx, ENABLE);
I2C_TimeCnt = I2C_TIMEOUT;
while (!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT))
if ((I2C_TimeCnt--) == 0) return I2C_TimeOut();
I2C_Send7bitAddress(I2Cx, SlaveAddr, I2C_Direction_Transmitter);
I2C_TimeCnt = I2C_TIMEOUT;
while (!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
if ((I2C_TimeCnt--) == 0) return I2C_TimeOut();
I2C_SendData(I2Cx, ReadAddr);
I2C_TimeCnt = I2C_TIMEOUT;
while (I2C_GetFlagStatus(I2Cx, I2C_FLAG_BTF) == RESET)
if ((I2C_TimeCnt--) == 0) return I2C_TimeOut();
I2C_GenerateSTART(I2Cx, ENABLE);
I2C_TimeCnt = I2C_TIMEOUT;
while (!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_MODE_SELECT))
if ((I2C_TimeCnt--) == 0) return I2C_TimeOut();
I2C_Send7bitAddress(I2Cx, SlaveAddr, I2C_Direction_Receiver);
if (NumByte < 2) {
I2C_TimeCnt = I2C_TIMEOUT;
while (I2C_GetFlagStatus(I2Cx, I2C_FLAG_ADDR) == RESET)
if ((I2C_TimeCnt--) == 0) return I2C_TimeOut();
I2C_AcknowledgeConfig(I2Cx, DISABLE);
(void)I2Cx->SR2;
I2C_GenerateSTOP(I2Cx, ENABLE);
I2C_TimeCnt = I2C_TIMEOUT;
while (I2C_GetFlagStatus(I2Cx, I2C_FLAG_RXNE) == RESET)
if ((I2C_TimeCnt--) == 0) return I2C_TimeOut();
*ReadBuf = I2C_ReceiveData(I2Cx);
NumByte--;
I2C_TimeCnt = I2C_TIMEOUT;
while (I2Cx->CR1 & I2C_CR1_STOP)
if ((I2C_TimeCnt--) == 0) return I2C_TimeOut();
I2C_AcknowledgeConfig(I2Cx, ENABLE);
} else {
I2C_TimeCnt = I2C_TIMEOUT;
while (!I2C_CheckEvent(I2Cx, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
if ((I2C_TimeCnt--) == 0) return I2C_TimeOut();
DMA_InitStruct.DMA_Channel = DMAx_RX_CHANNEL;
DMA_InitStruct.DMA_PeripheralBaseAddr = (u32)I2Cx_DR_ADDR;
DMA_InitStruct.DMA_Memory0BaseAddr = (u32)ReadBuf;
DMA_InitStruct.DMA_DIR = DMA_DIR_PeripheralToMemory;
DMA_InitStruct.DMA_BufferSize = (u32)(NumByte);
DMA_InitStruct.DMA_PeripheralInc = DMA_PeripheralInc_Disable;
DMA_InitStruct.DMA_MemoryInc = DMA_MemoryInc_Enable;
DMA_InitStruct.DMA_PeripheralDataSize = DMA_PeripheralDataSize_Byte;
DMA_InitStruct.DMA_MemoryDataSize = DMA_MemoryDataSize_Byte;
DMA_InitStruct.DMA_Mode = DMA_Mode_Normal;
DMA_InitStruct.DMA_Priority = DMA_Priority_VeryHigh;
DMA_InitStruct.DMA_FIFOMode = DMA_FIFOMode_Enable;
DMA_InitStruct.DMA_FIFOThreshold = DMA_FIFOThreshold_Full;
DMA_InitStruct.DMA_MemoryBurst = DMA_MemoryBurst_Single;
DMA_InitStruct.DMA_PeripheralBurst = DMA_PeripheralBurst_Single;
DMA_Init(DMAx_RX_STREAM, &DMA_InitStruct);
I2C_DMALastTransferCmd(I2Cx, ENABLE);
DMA_Cmd(DMAx_RX_STREAM, ENABLE);
}
I2C_TimeCnt = I2C_TIMEOUT;
while (NumByte > 0)
if ((I2C_TimeCnt--) == 0) return I2C_TimeOut();
//.........这里部分代码省略.........
示例14: i2c_read
//.........这里部分代码省略.........
{
if ((dev->timeout--) == 0)
return I2C_ERROR;
}
I2C_SendData(dev->I2Cx, *tx_buff++);
// Test on EV8 and clear it
dev->timeout = sEE_FLAG_TIMEOUT;
while (I2C_GetFlagStatus(dev->I2Cx, I2C_FLAG_BTF ) == RESET)
{
if ((dev->timeout--) == 0)
return I2C_ERROR;
}
// Send STRAT condition a second time
I2C_GenerateSTART(dev->I2Cx, ENABLE);
// Test on EV5 and clear it (cleared by reading SR1 then writing to DR)
dev->timeout = sEE_FLAG_TIMEOUT;
while (!I2C_CheckEvent(dev->I2Cx, I2C_EVENT_MASTER_MODE_SELECT ))
{
if ((dev->timeout--) == 0)
return I2C_ERROR;
}
// Send address for read
I2C_Send7bitAddress(dev->I2Cx, addr, I2C_Direction_Receiver );
if ((uint16_t)(*rxlen) < 2)
{
dev->timeout = sEE_FLAG_TIMEOUT;
while (I2C_GetFlagStatus(dev->I2Cx, I2C_FLAG_ADDR ) == RESET)
{
if ((dev->timeout--) == 0)
return I2C_ERROR;
}
// Disable Acknowledgement
I2C_AcknowledgeConfig(dev->I2Cx, DISABLE);
/* Clear ADDR register by reading SR1 then SR2 register (SR1 has already been read) */
(void) dev->I2Cx->SR2;
/*!< STOP condition */
I2C_GenerateSTOP(dev->I2Cx, DISABLE);
I2C_ClearFlag(dev->I2Cx, I2C_FLAG_STOPF );
/* Send STOP condition */
I2C_GenerateSTOP(dev->I2Cx, ENABLE);
/* Wait for the byte to be received */
dev->timeout = sEE_FLAG_TIMEOUT;
while (I2C_GetFlagStatus(dev->I2Cx, I2C_FLAG_RXNE ) == RESET)
{
if ((dev->timeout--) == 0)
return I2C_ERROR;
}
/*!< Read the byte received from the EEPROM */
*buffer8 = I2C_ReceiveData(dev->I2Cx);
(uint16_t)(*rxlen)--;
/* Wait to make sure that STOP control bit has been cleared */
dev->timeout = sEE_FLAG_TIMEOUT;
while (dev->I2Cx->CR1 & I2C_CR1_STOP )
{
if ((dev->timeout--) == 0)
return I2C_ERROR;
}
// Re-Enable Acknowledgement to be ready for another reception
I2C_AcknowledgeConfig(dev->I2Cx, ENABLE);
}
else/* More than one Byte Master Reception procedure (DMA) -----------------*/
{
/*!< Test on EV6 and clear it */
dev->timeout = sEE_FLAG_TIMEOUT;
while (!I2C_CheckEvent(dev->I2Cx,
I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED ))
{
if ((dev->timeout--) == 0)
return I2C_ERROR;
}
/* Configure the DMA Rx Channel with the buffer address and the buffer size */
sEE_LowLevel_DMAConfig(dev, (uint32_t) buffer8, (uint16_t)(*rxlen),
sEE_DIRECTION_RX);
/* Inform the DMA that the next End Of Transfer Signal will be the last one */
I2C_DMALastTransferCmd(dev->I2Cx, ENABLE);
/* Enable the DMA Rx Stream */
if (dev->I2Cx == I2C1){
DMA_Cmd(sEE_I2C1_DMA_STREAM_RX, ENABLE);
} else if(dev->I2Cx == I2C2){
DMA_Cmd(sEE_I2C2_DMA_STREAM_RX, ENABLE);
}
/* Enable the sEE_I2C peripheral DMA requests */
I2C_DMACmd(dev->I2Cx, ENABLE);
}
return I2C_OK;
}
示例15: LM75_ShutDown
/**
* @brief Enables or disables the LM75.
* @param NewState: specifies the LM75 new status. This parameter can be ENABLE
* or DISABLE.
* @retval None
*/
uint8_t LM75_ShutDown(FunctionalState NewState)
{
uint8_t LM75_BufferRX[2] ={0,0};
uint8_t LM75_BufferTX = 0;
__IO uint8_t RegValue = 0;
/* Test on BUSY Flag */
LM75_Timeout = LM75_LONG_TIMEOUT;
while (I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BUSY))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Configure DMA Peripheral */
LM75_DMA_Config(LM75_DMA_RX, (uint8_t*)LM75_BufferRX, 2);
/* Enable DMA NACK automatic generation */
I2C_DMALastTransferCmd(LM75_I2C, ENABLE);
/* Enable the I2C peripheral */
I2C_GenerateSTART(LM75_I2C, ENABLE);
/* Test on SB Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send device address for write */
I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Transmitter);
/* Test on ADDR Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send the device's internal address to write to */
I2C_SendData(LM75_I2C, LM75_REG_CONF);
/* Test on TXE FLag (data sent) */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while ((!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_TXE)) && (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_BTF)))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send START condition a second time */
I2C_GenerateSTART(LM75_I2C, ENABLE);
/* Test on SB Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_GetFlagStatus(LM75_I2C,I2C_FLAG_SB))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send LM75 address for read */
I2C_Send7bitAddress(LM75_I2C, LM75_ADDR, I2C_Direction_Receiver);
/* Test on ADDR Flag */
LM75_Timeout = LM75_FLAG_TIMEOUT;
while (!I2C_CheckEvent(LM75_I2C, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Enable I2C DMA request */
I2C_DMACmd(LM75_I2C,ENABLE);
/* Enable DMA RX Channel */
DMA_Cmd(LM75_DMA_RX_CHANNEL, ENABLE);
/* Wait until DMA Transfer Complete */
LM75_Timeout = LM75_LONG_TIMEOUT;
while (!DMA_GetFlagStatus(LM75_DMA_RX_TCFLAG))
{
if((LM75_Timeout--) == 0) return LM75_TIMEOUT_UserCallback();
}
/* Send STOP Condition */
I2C_GenerateSTOP(LM75_I2C, ENABLE);
/* Disable DMA RX Channel */
DMA_Cmd(LM75_DMA_RX_CHANNEL, DISABLE);
/* Disable I2C DMA request */
I2C_DMACmd(LM75_I2C,DISABLE);
/* Clear DMA RX Transfer Complete Flag */
DMA_ClearFlag(LM75_DMA_RX_TCFLAG);
//.........这里部分代码省略.........