简体   繁体   English

STM32-I2C-写入顺序数据

[英]STM32 - I2C - Write Sequential Data

I'm using AT24C512 EEPROM which is 512KB along with my STM32 我正在使用512KB的AT24C512 EEPROM和我的STM32

I'm able to write 128bytes of data at once using 我可以使用一次写入128字节的数据

HAL_I2C_Mem_Write(&_EEPROM24XX_I2C,0xa0,Address,I2C_MEMADD_SIZE_16BIT,(uint8_t*)data,size_of_data,100)

but the issue is that i want to write more data after the data that was just wrote, but the EEPROM will replace the data as the Address is the same 但是问题是我想在刚刚写入的数据之后写入更多数据,但是EEPROM将替换数据,因为地址相同

so how can i skip the written address ? 那我该如何跳过书面地址?

This answer is not about using HAL with I2C, but hope it will point you 这个答案不是关于将HAL与I2C一起使用,但希望它能对您有所帮助

Just check datasheet (I looking into STM32F0) and you can see that the limit is 255 bytes (register CR2:NBYTES), I'm not sure if there is another limitation in HAL, but using direct access to registers you can sent 255 bytes at once or fragment it and sent how much you want. 只需检查数据表(我查看STM32F0),您就会看到限制为255个字节(寄存器CR2:NBYTES),我不确定HAL中是否还有其他限制,但是使用直接访问寄存器可以发送255个字节立即或将其分段,然后发送您想要的数量。

For fragmenting there is bit CR2:RELOAD, if you set this, then at the end will be not transfer stopped, and you can update next NBYTES, .. when you will set last block of bytes (which will fit into NBYTES) then clear bit CR2:RELOAD. 对于分段,有CR2:RELOAD位,如果设置了该位,则最后不会停止传输,并且可以更新下一个NBYTES,..当您设置最后一个字节块(将适合NBYTES)然后清除位CR2:RELOAD。

This has one disadvantage, that every 255 bytes, you will be interrupted. 这有一个缺点,即每255个字节将中断您的访问。

i think you should check the AT24C512 datasheet page 7. 我认为您应该查看AT24C512数据表第7页。

If more than 128 data words are transmitted to the EEPROM, the data word address will “ roll over ” and previous data will be overwritten. 如果将超过128个数据字发送到EEPROM,则数据字地址将“翻转”,并且先前的数据将被覆盖。 The address “ roll over ” during write is from the last byte of the current page to the first byte of the same page. 写入期间的地址“翻转”是从当前页面的最后一个字节到同一页面的第一个字节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM