本文整理汇总了C++中I2C_DMACmd函数的典型用法代码示例。如果您正苦于以下问题:C++ I2C_DMACmd函数的具体用法?C++ I2C_DMACmd怎么用?C++ I2C_DMACmd使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了I2C_DMACmd函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SendDataBy_I2C1
void SendDataBy_I2C1()
{
DMA_ConfigForI2C1Send();
I2C_AcknowledgeConfig(I2C1, ENABLE);
I2C_ITConfig(I2C1, I2C_IT_BUF , DISABLE);
while(I2C_GetFlagStatus(CODEC_I2C, I2C_FLAG_BUSY)) //wait for bus is not busy
{
}
/* Start the config sequence */
I2C_GenerateSTART(CODEC_I2C, ENABLE);
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT)) // EV5
{
}
/* Transmit the slave address and enable writing operation */
I2C_Send7bitAddress(CODEC_I2C, CODEC_ADDRESS, I2C_Direction_Transmitter);
DMA_Cmd(DMA1_Stream6, ENABLE);
I2C_DMACmd(I2C2, ENABLE);
/* DMA1 Channel6 transfer complete test */
while(DMA_GetFlagStatus(DMA1_Stream6,DMA_FLAG_TCIF6)==RESET)
{
}
I2C_DMACmd(I2C1, DISABLE);
DMA_Cmd(DMA1_Stream6, DISABLE);
// wait until BTF
while (!(I2C1->SR1 & 0x04));
I2C_GenerateSTOP(I2C1, ENABLE);
// wait until BUSY clear
while (I2C1->SR2 & 0x02);
if(I2C1->CR1 & 0x200)
I2C1->CR1 &= 0xFDFF;
}
示例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: GPIO_Configuration
void GPIO_Configuration(void)
{
/* Disable the Serial Wire Jtag Debug Port SWJ-DP */
GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable, ENABLE);
/* Enable GPIOA, GPIOB, GPIOC, GPIOD, GPIOE and AFIO clocks */
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOA | RCC_APB2Periph_GPIOB |RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE | RCC_APB2Periph_AFIO, ENABLE);
/* COnfigure All*/
SetIoMode(GPIOA,GPIO_Pin_All,GPIO_Mode_Out_PP);
SetIoMode(GPIOB,GPIO_Pin_All,GPIO_Mode_Out_PP);
SetIoMode(GPIOC,GPIO_Pin_All,GPIO_Mode_Out_PP);
SetIoMode(GPIOD,GPIO_Pin_All,GPIO_Mode_Out_PP);
SetIoMode(GPIOE,GPIO_Pin_All,GPIO_Mode_Out_PP);
/* Configure USART1*/
SetIoMode(GPIOA,GPIO_Pin_9,GPIO_Mode_AF_PP);
SetIoMode(GPIOA,GPIO_Pin_10,GPIO_Mode_IN_FLOATING);
/* Configure USART2*/
SetIoMode(GPIOA,GPIO_Pin_2,GPIO_Mode_AF_PP);
SetIoMode(GPIOA,GPIO_Pin_3,GPIO_Mode_IN_FLOATING);
/* Configure USART3*/
SetIoMode(GPIOB,GPIO_Pin_10,GPIO_Mode_AF_PP);
SetIoMode(GPIOB,GPIO_Pin_11,GPIO_Mode_IN_FLOATING);
/* Configure CAN1 pin*/
SetIoMode(GPIOA,GPIO_Pin_11,GPIO_Mode_IPU);
SetIoMode(GPIOA,GPIO_Pin_12,GPIO_Mode_AF_PP);
/* Configure CAN2 pin*/
SetIoMode(GPIOB,GPIO_Pin_8,GPIO_Mode_IPU);
SetIoMode(GPIOB,GPIO_Pin_9,GPIO_Mode_AF_PP);
/* Configure ADC NISSAN*/
SetIoMode(GPIOA,GPIO_Pin_0,GPIO_Mode_AIN);
/* Configure BOOT1*/
SetIoMode(GPIOB,GPIO_Pin_2,GPIO_Mode_IN_FLOATING);
I2C_DMACmd(I2C2,DISABLE);
}
示例4: 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);
}
示例5: sEE_Init
/**
* @brief Initializes peripherals used by the I2C EEPROM driver.
* @param None
* @retval None
*/
void sEE_Init(void)
{
I2C_InitTypeDef I2C_InitStructure;
sEE_LowLevel_Init();
/* If the I2C peripheral is already enabled, don't reconfigure it */
if ((sEE_I2C->CR1 & I2C_CR1_PE) == 0)
{
/*!< I2C configuration */
/* sEE_I2C configuration */
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = 0x00;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED;
/* Apply sEE_I2C configuration after enabling it */
I2C_Init(sEE_I2C, &I2C_InitStructure);
/* sEE_I2C Peripheral Enable */
I2C_Cmd(sEE_I2C, ENABLE);
}
/* Enable the sEE_I2C peripheral DMA requests */
I2C_DMACmd(sEE_I2C, ENABLE);
/*!< Select the EEPROM address */
sEEAddress = sEE_HW_ADDRESS;
}
示例6: sEE_Init
/**
* @brief Initializes peripherals used by the I2C EEPROM driver.
* @param None
* @retval None
*/
void sEE_Init(void)
{
I2C_InitTypeDef I2C_InitStructure;
sEE_LowLevel_Init();
/*!< I2C configuration */
/* sEE_I2C configuration */
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = I2C_SLAVE_ADDRESS7;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED;
/* sEE_I2C Peripheral Enable */
I2C_Cmd(sEE_I2C, ENABLE);
/* Apply sEE_I2C configuration after enabling it */
I2C_Init(sEE_I2C, &I2C_InitStructure);
/* Enable the sEE_I2C peripheral DMA requests */
I2C_DMACmd(sEE_I2C, ENABLE);
#if 0
#if defined (sEE_M24C64_32)
/*!< Select the EEPROM address according to the state of E0, E1, E2 pins */
sEEAddress = sEE_HW_ADDRESS;
#elif defined (sEE_M24C08)
/*!< depending on the sEE Address selected in the stm322xg_eval_i2c_ee.h file */
#ifdef sEE_Block0_ADDRESS
/*!< Select the sEE Block0 to write on */
sEEAddress = sEE_Block0_ADDRESS;
#elif defined (sEE_AT24C02)
sEEAddress = 0xA0;
#endif
#ifdef sEE_Block1_ADDRESS
/*!< Select the sEE Block1 to write on */
sEEAddress = sEE_Block1_ADDRESS;
#endif
#ifdef sEE_Block2_ADDRESS
/*!< Select the sEE Block2 to write on */
sEEAddress = sEE_Block2_ADDRESS;
#endif
#ifdef sEE_Block3_ADDRESS
/*!< Select the sEE Block3 to write on */
sEEAddress = sEE_Block3_ADDRESS;
#endif
#endif /*!< sEE_M24C64_32 */
#endif
sEEAddress = 0xA0;
}
示例7: SENSOR_I2C_BUS_Configuration
/********************
- I2C2初始化
*********************/
void SENSOR_I2C_BUS_Configuration(void)
{
I2C_InitTypeDef I2C_InitStructure;
GPIO_InitTypeDef GPIO_InitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
// I2C Periph clock enable
RCC_APB1PeriphClockCmd(RCC_APB1Periph_I2C2, ENABLE);
// GPIO Periph clock enable
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOB | RCC_APB2Periph_AFIO, ENABLE);
// I2C configuration
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = 0xa0;
I2C_InitStructure.I2C_Ack = I2C_Ack_Disable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = I2C2_Speed;
// Configure I2C2 SCL as alternate function Open-drain output
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_10;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// Configure I2C2 SDA as alternate function Open-drain output
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_11;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AF_OD;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOB, &GPIO_InitStructure);
// Apply I2C configuration after enabling it
//I2C_AcknowledgeConfig(SENSOR_I2C_BUS, ENABLE);
I2C_Init(SENSOR_I2C_BUS, &I2C_InitStructure);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = I2C2_EV_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
NVIC_InitStructure.NVIC_IRQChannel = I2C2_ER_IRQn;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 5;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
// I2C Peripheral Enable
I2C_ITConfig(SENSOR_I2C_BUS, I2C_IT_EVT|I2C_IT_ERR, ENABLE);
I2C_DMACmd(SENSOR_I2C_BUS, DISABLE);
I2C_Cmd(SENSOR_I2C_BUS, ENABLE);
}
示例8: 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
}
示例9: 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.
}
示例10: I2C_Init_Func
void I2C_Init_Func(void)
{
I2C_InitTypeDef I2C_InitStructure;
I2C_InitStructure.I2C_Mode = I2C_Mode_I2C;
I2C_InitStructure.I2C_DutyCycle = I2C_DutyCycle_2;
I2C_InitStructure.I2C_OwnAddress1 = I2C_SLAVE_ADDRESS7;
I2C_InitStructure.I2C_Ack = I2C_Ack_Enable;
I2C_InitStructure.I2C_AcknowledgedAddress = I2C_AcknowledgedAddress_7bit;
I2C_InitStructure.I2C_ClockSpeed = I2C_SPEED;
I2C_Cmd(sEE_I2C, ENABLE);
I2C_Init(sEE_I2C, &I2C_InitStructure);
I2C_DMACmd(sEE_I2C, ENABLE);
}
示例11: sendData
void sendData() {
while(I2C_GetFlagStatus( I2C2, I2C_FLAG_BUSY ));
I2C_GenerateSTART( I2C2, ENABLE );
while( !I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_MODE_SELECT) );
I2C_Send7bitAddress( I2C2, FM_WRITE_ADDRESS, I2C_Direction_Transmitter );
while( !I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED) );
I2C_SendData( I2C2, out_buf[0] );
while( !I2C_CheckEvent(I2C2, I2C_EVENT_MASTER_BYTE_TRANSMITTED) );
/* Enable the DMA Channel4 Transfer Complete IT */
DMA_ITConfig(DMA1_Channel4, DMA_IT_TC | DMA_IT_TE, ENABLE);
I2C_DMACmd(I2C2, ENABLE);
DMA_Cmd( DMA1_Channel4, ENABLE );
}
示例12: I2C_Master_BufferWrite
/**
* @brief Send a buffer of bytes to the slave.
* @param pBuffer: Buffer of bytes to be sent to the slave.
* @param NumByteToRead: Number of bytes to be sent to the slave.
* @retval : None.
*/
void I2C_Master_BufferWrite(uint8_t* pBuffer, uint16_t NumByteToWrite)
{
#ifdef DMA_Master_Transmit
DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)pBuffer;
DMA_InitStructure.DMA_BufferSize = NumByteToWrite;
DMA_Init(DMA1_Channel6, &DMA_InitStructure);
I2C_ITConfig(I2C1, I2C_IT_EVT, ENABLE);
I2C_DMACmd(I2C1, ENABLE);
I2C_GenerateSTART(I2C1, ENABLE);
DMA_ITConfig(DMA1_Channel6, DMA_IT_TC, ENABLE);
#endif
#ifdef Polling_Master_Transmit
/* Send START condition */
I2C_GenerateSTART(I2C1, ENABLE);
/* Test on EV5 and clear it */
while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT));
/* Send slave address for write */
I2C_Send7bitAddress(I2C1,SLAVE_ADDRESS, I2C_Direction_Transmitter);
/* Test on EV6 and clear it */
while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED));
I2C_SendData(I2C1, *pBuffer);
pBuffer++;
NumByteToWrite--;
/* While there is data to be written */
while (NumByteToWrite--)
{
while ((I2C_GetLastEvent(I2C1) & 0x04) != 0x04); /* Poll on BTF */
/* Send the current byte */
I2C_SendData(I2C1, *pBuffer);
/* Point to the next byte to be written */
pBuffer++;
}
/* Test on EV8_2 and clear it, BTF = TxE = 1, DR and shift registers are
empty */
while (!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_BYTE_TRANSMITTED));
/* Send STOP condition */
I2C_GenerateSTOP(I2C1, ENABLE);
#endif
}
示例13: I2C2_EV_IRQHandler
/**
* @brief This function handles I2C2 Event interrupt request.
* @param None
* @retval : None
*/
void I2C2_EV_IRQHandler(void)
{
#ifdef slave2
uint8_t j=0;
#endif
#if defined(DMA_Slave_Transmit) || defined(DMA_Slave_Receive)
__IO uint32_t temp;
__IO int32_t temp1;
if (I2C_GetFlagStatus(I2C2, I2C_FLAG_ADDR))
{
DMA_Cmd(DMA1_Channel1, ENABLE);
ADC_SoftwareStartConvCmd(ADC1, ENABLE);
if (DMA1_Channel1->CNDTR == 0)
{
DMA_Cmd(DMA1_Channel4, DISABLE);
DMA_Cmd(DMA1_Channel1, DISABLE);
#ifdef slave2
/* Calculate the Temperature values */
for (j=0; j<BufferSize; j++)
{
temp1 = Buffer[j];
temp1 = ( temp1 * 3300 ) / 0x1000; /* Finds mV */
temp1 = ((((1430-temp1)*100000)/430)+25000)/1000;
Slave_Buffer_Tx[j] = temp1;
}
#endif
DMA1_Channel4->CNDTR = 255;
DMA1_Channel1->CNDTR = BufferSize;
I2C_DMACmd(I2C2, ENABLE);
DMA_Cmd(DMA1_Channel4, ENABLE);
/* clear ADDR by reading SR2 */
temp = I2C2->SR2 ;
}
}
if (I2C_GetFlagStatus(I2C2, I2C_FLAG_STOPF))
{
I2C_Cmd(I2C2, ENABLE);
}
#endif
}
示例14: sEE_Init
/**
* @brief Initializes peripherals used by the I2C EEPROM driver.
* @param None
* @retval None
*/
void sEE_Init(void)
{
sEE_LowLevel_Init();
/*!< I2C configuration */
/* sEE_I2C Peripheral Enable */
I2C_Cmd(sEE_I2C, ENABLE);
/* sEE_I2C configuration after enabling it */
I2C_Init(sEE_I2C, I2C_SPEED, I2C_SLAVE_ADDRESS7, I2C_Mode_I2C, I2C_DutyCycle_2,
I2C_Ack_Enable, I2C_AcknowledgedAddress_7bit);
/* Enable the sEE_I2C peripheral DMA requests */
I2C_DMACmd(sEE_I2C, ENABLE);
#if defined (sEE_M24C64_32)
/*!< Select the EEPROM address according to the state of E0, E1, E2 pins */
sEEAddress = sEE_HW_ADDRESS;
#endif /*!< sEE_M24C64_32 */
}
示例15: 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;
}