HAL库I2C一次只能写入16个字节,求助!!!读出的数据是正确的。
#define ADDR_24LCxx_Write 0xA0
#define ADDR_24LCxx_Read 0xA1
#define BufferSize 250
uint8_t WriteBuffer[BufferSize],ReadBuffer[BufferSize];
uint16_t i;
int main(void)
{
HAL_Init();
SystemClock_Config();
MX_GPIO_Init();
MX_USART1_UART_Init();
MX_USART2_UART_Init();
MX_USART3_UART_Init();
MX_
tiM2_Init();
MX_I2C1_Init();
/* USER CODE BEGIN 2 */
HAL_TIM_Base_Start_IT(&htim2);
for(i=0; i<BufferSize; i++)
WriteBuffer
=22; /* WriteBuffer init */
if(HAL_I2C_Mem_Write(&hi2c1, ADDR_24LCxx_Write, 0, I2C_MEMADD_SIZE_8BIT,WriteBuffer,BufferSize, 0x10) == HAL_OK)
HAL_Delay(1000);
else
HAL_Delay(2000); //写EEPROM时出错,只能执行到此条。
/* read date from EEPROM */ //读正常
HAL_I2C_Mem_Read(&hi2c1, ADDR_24LCxx_Read, 0, I2C_MEMADD_SIZE_8BIT,ReadBuffer,BufferSize, 0x10);
HAL_Delay(1000);
/* USER CODE END 2 */
/* Infinite loop */
/* USER CODE BEGIN WHILE */
while (1)
{
/* USER CODE END WHILE */
/* USER CODE BEGIN 3 */
}
/* USER CODE END 3 */
}
一周热门 更多>