bug in TWIHS_TWIHS_MASTER_EXAMPLE on SAME70-XPLD AT24MAC402

1 post / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

I had problems with the example. On page 14 of the AT24MAC402 datasheet at http://www.atmel.com/images/Atmel-8807-SEEPROM-AT24MAC402-602-Datasheet.pdf, it says that the page write is 16 bytes. The string of the example code was much larger than that. I checked the I2C data with a Saleae logic analyzer and saw that the buffer read produced the strings with parts of continuous characters that were correct, just it got re-segmented into a few blocks with different order. ( the middle of the string was in the beginning).

 

I shortened the string:

 

//WRITE IS 16 BYTES MAX. THE ORIGINAL EXAMPLE HAS MORE THAN 16

static const uint8_t test_data_tx[] = {

/** SAM TWI EEPROM EXAMPLE */

'1', '2', '3', '4', '5', '6', '7', '8',

'9', 'A', 'B', 'C', 'D', 'E', 'F'

};

 

I also changed the quantity of address bytes to 1 which agrees with the data sheet at page 19.

void test_AT24MAC402(void){
	twihs_packet_t packet_tx, packet_rx;
		
	/* Configure the data packet to be transmitted */
	packet_tx.chip        = 0xAE>>1;
	packet_tx.addr[0]     = 96 ;
	packet_tx.addr[1]     = 0;
	packet_tx.addr_length = 1; //IT MUST BE 1. THE ORIGINAL CODE SAID 2, WHICH IS WRONG.
	packet_tx.buffer      = (uint8_t *) test_data_tx;
	packet_tx.length      = TEST_DATA_LENGTH;

	/* Configure the data packet to be received */
	packet_rx.chip        = packet_tx.chip;
	packet_rx.addr[0]     = packet_tx.addr[0];
	packet_rx.addr[1]     = packet_tx.addr[1];
	packet_rx.addr_length = packet_tx.addr_length;
	packet_rx.buffer      = gs_uc_test_data_rx;
	packet_rx.length      = packet_tx.length;

	

	/* Send test pattern to EEPROM */
	if (twihs_master_write(BOARD_BASE_TWIHS_EEPROM, &packet_tx) != TWIHS_SUCCESS) {
		puts("-E-\tTWI master write packet failed.\r");
		while (1) {
			/* Capture error */
		}
	}
	puts("Write:\tOK!\n\r");

	/* Wait at least 10 ms */
	mdelay(WAIT_TIME);

	/* Get memory from EEPROM*/
	if (twihs_master_read(BOARD_BASE_TWIHS_EEPROM, &packet_rx) != TWIHS_SUCCESS) {
		puts("-E-\tTWI master read packet failed.\r");
		while (1) {
			/* Capture error */
		}
	}
	puts("Read:\tOK!\r");

	/* Compare the sent and the received */
	for (int i = 0; i < TEST_DATA_LENGTH; i++) {
		if (test_data_tx[i] != gs_uc_test_data_rx[i]) {
			/* No match */
			puts("Data comparison:\tUnmatched!\r");
			while (1) {
				/* Capture error */
			}
		}
	}
	/* Match */
	puts("Data comparison:\tMatched!\r");
	LED_On(LED0);
}

 

Frank