求:想用存入一组数据32位;然后相对应的位置读出相关内容; 只存16个的时候可以存入但大于16的时候数据就没法存入;还请教给完大神。
部分代码;如何把这组数据全部存入和相对应的读出来
I2C_WriteBuffer[0]= 0;
I2C_WriteBuffer[1] = 1;
I2C_WriteBuffer[2]= 2;
I2C_WriteBuffer[3] = 3;
I2C_WriteBuffer[4]= 4;
I2C_WriteBuffer[5] = 5;
I2C_WriteBuffer[6]= 6;
I2C_WriteBuffer[7] = 7;
I2C_WriteBuffer[8]= 8;
I2C_WriteBuffer[9] = 9;
I2C_WriteBuffer[10]= 10;
I2C_WriteBuffer[11] = 11;
I2C_WriteBuffer[12]= 12;
I2C_WriteBuffer[13] = 13;
I2C_WriteBuffer[14]= 14;
I2C_WriteBuffer[15] = 15;
//5通道
I2C_WriteBuffer[16]= 16;
I2C_WriteBuffer[17] = 17;
I2C_WriteBuffer[18]= 18;
I2C_WriteBuffer[19] = 19;
I2C_WriteBuffer[20]= 20;
I2C_WriteBuffer[21] = 21;
I2C_WriteBuffer[22]= 22;
I2C_WriteBuffer[23] =23;
I2C_WriteBuffer[24]= 24;
I2C_WriteBuffer[25] = 25;
I2C_WriteBuffer[26]= 26;
I2C_WriteBuffer[27] = 27;
I2C_WriteBuffer[28]= 28;
I2C_WriteBuffer[29] = 29;
I2C_WriteBuffer[30]= 30;
I2C_WriteBuffer[31] = 31;
for(i = 0; i<32; i+=8){
HAL_I2C_Mem_Write(&hi2c2, ADDR_24LCxx_Write, i, I2C_MEMADD_SIZE_8BIT,&I2C_WriteBuffer,8,0xff);
}
//读
HAL_I2C_Mem_Read(&hi2c2, ADDR_24LCxx_Read, 0, I2C_MEMADD_SIZE_8BIT,&I2C_ReadBuffer[0],32, 0xff);
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);
printf("I2C_ReadBuffer ");
HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_5);
for(i=0; i<32; i++)
{
printf("0x%02X ",I2C_ReadBuffer);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
我这样存 老是存不了后面的16个数组 下面是我存入和读取方法 是哪里不正确;存入我加入延时就读取不了
//存入EEprom
if(HAL_I2C_Mem_Write(&hi2c2, ADDR_24LCxx_Write, 0, I2C_MEMADD_SIZE_8BIT,&I2C_WriteBuffer[0],16, 0x10) == HAL_OK)
{
}
else
{
}
//HAL_Delay(500);
if(HAL_I2C_Mem_Write(&hi2c2, ADDR_24LCxx_Write, 2, I2C_MEMADD_SIZE_8BIT,&I2C_WriteBuffer[16],16, 0x10) == HAL_OK)
{
}
else
{
//
}
//读------------------------------
if( HAL_I2C_Mem_Read(&hi2c2, ADDR_24LCxx_Read, 0, I2C_MEMADD_SIZE_8BIT,I2C_ReadBuffer,32,0xFF) == HAL_OK){
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);
printf(" EEPROM 24C02 READ0 ");
HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_5);
for(i = 0;i<32;i++){
HAL_GPIO_WritePin(GPIOB, GPIO_PIN_5, GPIO_PIN_SET);
printf("0x%02X ",I2C_ReadBuffer);
HAL_GPIO_TogglePin(GPIOB,GPIO_PIN_5);
}
谢谢; 还想请教下 IIC_TX_BUSY 和 IIC_TX_FREE 这两个是如何定义的
一周热门 更多>