/** * \brief Application entry point for AT30TS(E)75x Component Example. * * \return Unused (ANSI-C compatibility). */ int main(void) { double temp = 0; /* Initialize the SAM system */ sysclk_init(); /* Initialize the board */ board_init(); /* Initialize the console UART */ configure_console(); /* Output example information */ puts(STRING_HEADER); memset(tx, 0xFF, NB_BYTE); /* Initialize AT30TS(E)75x */ at30tse_init(); #if BOARD_USING_AT30TSE != AT30TS75 uint32_t i; /* Write pages in EEPROM */ for (i = 0; i < NB_PAGE; i++) { tx[NB_PAGE - 1] = i; if (at30tse_eeprom_write(tx, NB_BYTE, 0, i) != TWI_SUCCESS) { puts("Write EEPROM error\r"); return 0; } delay_ms(5); } puts("Write EEPROM OK\r"); /* Read each page in EEPROM and compare them */ for (i = 0; i < NB_PAGE; i++) { memset(rx, 0, NB_BYTE); if (at30tse_eeprom_read(rx, NB_BYTE, 0, i) != TWI_SUCCESS) { puts("Read EEPROM error\r"); return 0; } else { if (memcmp(tx, rx, NB_BYTE - 1) && (rx[NB_PAGE - 1] != i)) { puts("Comparison error\r"); return 0; } } } puts("Read EEPROM & Compare OK\r"); #endif /* Read temperature every second */ while (1) { if (at30tse_read_temperature(&temp) != TWI_SUCCESS) { puts("Read temperature error\r"); return 0; } printf("Read temperature:\t%d\r\n", (int)temp); delay_ms(1000); } }
/** * \brief AT30TS(E)75x read and comparison EEPROM test. * * \param test Current test case. */ static void run_test_read_compare_data(const struct test_case *test) { memset(rx, 0, NB_BYTE); test_assert_true(test, at30tse_eeprom_read(rx, NB_BYTE, 0, (int)temp % NB_PAGE) == TWI_SUCCESS, "Error: AT30TS(E)75x read failed\n\r"); test_assert_true(test, !memcmp(tx, rx, NB_BYTE), "Error: AT30TS(E)75x comparison failed\n\r"); }
int main(void) { volatile double temper_value; volatile bool data_check_status1 = true, data_check_status2 = true; uint32_t i; system_clock_config(CLOCK_RESOURCE_XO_26_MHZ, CLOCK_FREQ_26_MHZ); /* Initialize AT30TS(E)75x */ at30tse_init(); /* First round data check */ for (i = 0; i < NB_BYTE; i++) { tx_buffer[i] = i; } /* Write pages in EEPROM */ for (i = 0; i < NB_PAGE; i++) { at30tse_eeprom_write(tx_buffer, NB_BYTE, 0, i); delay(200); } /* Read each page in EEPROM and compare them */ for (i = 0; i < NB_PAGE; i++) { memset(rx_buffer, 0, NB_BYTE); at30tse_eeprom_read(rx_buffer, NB_BYTE, 0, i); if (memcmp(tx_buffer, rx_buffer, NB_BYTE)) { data_check_status1 = false; break; } } /* Second round data check */ for (i = 0; i < NB_BYTE; i++) { tx_buffer[i] = NB_BYTE - i; } /* Write pages in EEPROM */ for (i = 0; i < NB_PAGE; i++) { at30tse_eeprom_write(tx_buffer, NB_BYTE, 0, i); delay(200); } /* Read each page in EEPROM and compare them */ for (i = 0; i < NB_PAGE; i++) { memset(rx_buffer, 0, NB_BYTE); at30tse_eeprom_read(rx_buffer, NB_BYTE, 0, i); if (memcmp(tx_buffer, rx_buffer, NB_BYTE)) { data_check_status2 = false; break; } } /* Read thigh and tlow */ volatile uint16_t thigh = 0; thigh = at30tse_read_register(AT30TSE_THIGH_REG, AT30TSE_NON_VOLATILE_REG, AT30TSE_THIGH_REG_SIZE); volatile uint16_t tlow = 0; tlow = at30tse_read_register(AT30TSE_TLOW_REG, AT30TSE_NON_VOLATILE_REG, AT30TSE_TLOW_REG_SIZE); /* Set 12-bit resolution mode. */ at30tse_write_config_register( AT30TSE_CONFIG_RES(AT30TSE_CONFIG_RES_12_bit)); while (1) { /* Read current temperature. */ temper_value = at30tse_read_temperature(); } UNUSED(data_check_status1); UNUSED(data_check_status2); UNUSED(temper_value); UNUSED(tlow); UNUSED(thigh); }