I2C的DMA查询模式下读取24C32数据,只能读到第一个数据,不用DMA模式读取数据正常255个数字是1~255,用DMA模式来读取数据全是1了。 找不到原因 void I2Cx_EE_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; I2C_InitTypeDef I2C_Initstucture; RCC_APB2PeriphClockCmd(I2Cx_GPIO_CLK,ENABLE); RCC_APB1PeriphClockCmd(I2Cx_CLK, ENABLE); RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE); GPIO_InitStructure.GPIO_Mode=GPIO_Mode_AF_OD; GPIO_InitStructure.GPIO_Pin=I2Cx_SCL_PIN|I2Cx_SDA_PIN; GPIO_InitStructure.GPIO_Speed=GPIO_Speed_50MHz; GPIO_Init(I2Cx_SCL_PORT, &GPIO_InitStructure); I2C_Initstucture.I2C_Ack=I2C_Ack_Enable; I2C_Initstucture.I2C_AcknowledgedAddress=I2C_AcknowledgedAddress_7bit; I2C_Initstucture.I2C_ClockSpeed=I2Cx_Speed; I2C_Initstucture.I2C_DutyCycle=I2C_DutyCycle_2;//I2C_DutyCycle_16_9; I2C_Initstucture.I2C_Mode=I2C_Mode_I2C; I2C_Initstucture.I2C_OwnAddress1=I2Cx_OWN_ADDRESS7; I2C_Init(I2Cx_EEPROM, &I2C_Initstucture); I2C_Cmd(I2Cx_EEPROM, ENABLE); I2C_DMACmd(I2Cx_EEPROM, ENABLE);/* Enable I2C1 DMA */ I2Cx_AcknowledgeConfig(I2Cx_EEPROM,1); } void I2Cx_DMA_RX_init(u8* pBuffer,u32 addr,u16 len) { DMA_InitTypeDef DMA_InitStructure; DMA_DeInit(I2Cx_DMA_RX_Channel); /* DMA1 channel7 I2C1_RX configuration */ DMA_InitStructure.DMA_PeripheralBaseAddr =I2C1->DR;// (uint32_t)addr; DMA_InitStructure.DMA_MemoryBaseAddr = (uint32_t)pBuffer; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralSRC; DMA_InitStructure.DMA_BufferSize = 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(I2Cx_DMA_RX_Channel, &DMA_InitStructure); } void ee_dma_read(void) { I2Cx_HardwareBus_BusyCheck(I2Cx_EEPROM); I2C_GenerateSTART(I2Cx_EEPROM, ENABLE);/* Send I2C1 START condition */ while(!I2C_CheckEvent(I2Cx_EEPROM, I2C_EVENT_MASTER_MODE_SELECT)); /* Test on I2C1 EV5 and clear it */ I2C_Send7bitAddress(I2Cx_EEPROM, EEPROM_ADDRESS, I2C_Direction_Transmitter);/* Send I2C2 slave Address for write */ while(!I2C_CheckEvent(I2Cx_EEPROM, I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED)); /* Test on I2C1 EV6 and clear it */ I2C_SendData(I2Cx_EEPROM, 0x00); while(!I2C_CheckEvent(I2Cx_EEPROM, I2C_EVENT_MASTER_BYTE_TRANSMITTING)); /* Test on I2C1 EV8 and clear it */ I2C_SendData(I2Cx_EEPROM, 0x00); while(!I2C_CheckEvent(I2Cx_EEPROM, I2C_EVENT_MASTER_BYTE_TRANSMITTING )); /* Test on I2C1 EV8 and clear it */ I2C_GenerateSTART(I2Cx_EEPROM, ENABLE); while(!I2C_CheckEvent(I2Cx_EEPROM, I2C_EVENT_MASTER_MODE_SELECT)); I2C_Send7bitAddress(I2Cx_EEPROM, EEPROM_ADDRESS, I2C_Direction_Receiver); while(!I2C_CheckEvent(I2Cx_EEPROM, I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED)); I2Cx_DMA_RX_init(buf,I2Cx_EEPROM->DR,255); I2C_DMALastTransferCmd(I2Cx_EEPROM, ENABLE); DMA_Cmd(I2Cx_DMA_RX_Channel, ENABLE);/* Enable DMA1 Channel7 */ while(!DMA_GetFlagStatus(DMA1_FLAG_TC7));/* DMA1 Channel7 transfer complete test */ DMA_Cmd(I2Cx_DMA_RX_Channel, DISABLE);/* Enable DMA1 Channel7 */ I2C_GenerateSTOP(I2Cx_EEPROM, ENABLE);/* Send I2C1 STOP Condition */ I2Cx_AcknowledgeConfig(I2Cx_EEPROM,1); for(u16 i=0; i<256; i++ ) { printf("0x%02X ", buf); if(i%16 == 15) printf("\n\r"); } } |
读åæ°æ®ä¸å¯¹
读åæ°æ®æ£å¸¸
【MCU实战经验】基于STM32F103C8T6的hart总线调试器设计
求教STM32F103进入STOP模式后用外部中断唤醒的问题
基于STM32F103RCT6的无源蜂鸣器音乐播放(生日快乐歌)
STM32F103c8t6有没有DAC 功能?
STM32F103x中文数据手册
新手求教,为何在我电脑上找不到STM32F1Xx.h文件
金龙107例程汇总(STM32F107)
万利STM32F107VC 原理图
STM32F103 ADC多通道检测必须要DMA吗?
【官方例程】STM32F107以太网官方例程
评分
查看全部评分