【翌创ET6001测评】AT24CXX系列器件测试中的问题
本帖最后由 jinglixixi 于 2024-12-4 21:28 编辑<p>先前已完成了W25QXX系列器件的读写测试,尽管例程是针对W25X40所准备的,但对于W25Q16来说依然有效。</p>
<p>为此打算也对AT24CXX系列器件进行一下读写测试,虽然厂家提供的例程是针对AT24C64的,由于手头仅有AT24C02,且2个芯片同属于一个系列,直至是在容量有所差异,通过测试的可能性还是有的。</p>
<p>例程所指定的引脚连接关系为:</p>
<p>I2C0_IC_SCL----(J9-4)</p>
<p>I2C0_IC_SDA---(J9-3)</p>
<p> </p>
<p> </p>
<p>图1 实物连接</p>
<p> </p>
<p>测试的主程序为:</p>
<pre>
<code class="language-cpp">int main(void)
{
I2C_InitTypeDef init;
uint32_t i, j;
uint32_t cnt;
uint32_t len;
uint32_t chipaddr;
I2C0_Type *I2Cx = I2C0;//use I2C0
UNUSED(len);
//initial UART0
UART0_printInit();
printf("\n\rI2C at24c64d demo start.\n\r");
I2C0_pinmux_init();
I2C_DeInit(I2Cx);
I2C_StructInit(&init);
I2C_Init(I2Cx, &init);
I2C_SetMasterTargetAddress(I2Cx, AT24_ADDRESS);
I2C_SetRXTL(I2Cx, 1);
I2C_SetTXTL(I2Cx, 0);
I2C_Enable(I2Cx);
//page write&read for all chip
cnt = AT24C64_ALL_SIZE / AT24C64_PAGE_SIZE;
for(i=0; i<cnt; i++){
//initial tx buffer
for(j=0; j<AT24C64_PAGE_SIZE; j++)
txBuf = (uint8_t)(AT24C64_PAGE_SIZE*i+j+0x22);
memset(rxBuf, 0, AT24C64_PAGE_SIZE);
//write one page
len = at24_writepage(I2Cx, txBuf, AT24C64_PAGE_SIZE*i);
//read back one page
len = at24_readpage(I2Cx, rxBuf, AT24C64_PAGE_SIZE*i);
//do check txbuffer and rxbuffer
if(memcmp(txBuf, rxBuf, AT24C64_PAGE_SIZE)){
printf("read page check error!\n\r");
break;
}
}
//AT24C64D write byte
at24_writebyte(I2Cx, (uint8_t *)"d", 0x102);
at24_writebyte(I2Cx, (uint8_t *)"a", 0x103);
memset(rxBuf, 0, sizeof(rxBuf));
//AT24C64D read byte start 0x100
at24_readbyte(I2Cx, &(rxBuf), 0x100);
//AT24C64D seqence read for continue data read
at24_readbytes_seq(I2Cx, &(rxBuf), 12);
//print and check write&read
printf("Receive data(offset:0x%04x) : %02x %02x %02x %02x %02x %02x %02x %02x "\
"%02x %02x %02x %02x %02x %02x %02x %02x\n\r", 0x100,
rxBuf, rxBuf, rxBuf, rxBuf,
rxBuf, rxBuf, rxBuf, rxBuf,
rxBuf, rxBuf, rxBuf, rxBuf,
rxBuf, rxBuf, rxBuf, rxBuf);
for(j=0; j<AT24C64_ALL_SIZE; j++)
g_txBuf = (uint8_t)(j+0x88);
memset(g_rxBuf, 0, AT24C64_PAGE_SIZE);
//write all
chipaddr = 0x10;
len = AT24C64_ALL_SIZE-chipaddr;
at24_writebytes(I2Cx, g_txBuf, len, chipaddr);
at24_readbytes(I2Cx, g_rxBuf, len, chipaddr);
//do check txbuffer and rxbuffer
if(memcmp(g_txBuf, g_rxBuf, len)){
printf("all chip check error!\n\r");
}
I2C_Disable(I2Cx);
I2C_DeInit(I2Cx);
do {
__asm volatile ("nop");
}while(1);
}
</code></pre>
<p> </p>
<p>在完成模块连接后,经程序的编译与运行,其测试结果如图2所示,说明尝试失败。</p>
<p> </p>
<p>图2 测试结果</p>
<p> </p>
<p>由于AT24C64与AT24C02在存储容量上有较大的差异,自然在一些参数上会有所差异,但相对来讲,AT24CXX系列器件的读写要比W25QXX系列器件的容易,因为W25QXX系列器件在写入前,必须对待写单元进行擦除,而AT24CXX系列器件则无需此操作。</p>
<p>为增加测试的成功率,又将程序改为对指定单元的读写测试,经测试其结果如图2所示,至此说明尝试无效。</p>
<p> </p>
<p>指定单元读写测试程序:</p>
<pre>
<code class="language-cpp"> for(j=0; j<8; j++)
txBuf = (uint8_t) (j+0x30);
g=at24_writebytes(I2Cx, txBuf, 8, 0x08);
printf("%d \n\r",g);
printf("write data: %02x %02x %02x %02x %02x %02x %02x %02x "\
"\n\r",
txBuf, txBuf, txBuf, txBuf,
txBuf, txBuf, txBuf, txBuf);
g=at24_readbytes(I2Cx, rxBuf, 8, 0x08);
printf("%d \n\r",g);
printf("readdata: %02x %02x %02x %02x %02x %02x %02x %02x "\
"\n\r",
rxBuf, rxBuf, rxBuf, rxBuf,
rxBuf, rxBuf, rxBuf, rxBuf); </code></pre>
<p> </p>
<p> </p>
<p>图3 测试结果</p>
<p> </p>
<p>由此可知,用例程是无法对AT24C02进行读写的,至于对AT24C64是否有效,只有留待具备其测试条件者来完成了。</p>
页:
[1]