这个例程用 I01扩展板插到EXT1
本程分两个阶段,第一一些参数往AT30TSE75x里写,并读出看写得正确否。
第二阶段,温度每秒采样一次。
在Atmel Studio6.2 环境下插入板子,这时可快速打开例程:
往EEPROM中写数据及读出代码如下:
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");
其中TWI_SUCCESS在 twi.h中定义
#define TWI_SUCCESS 0
#define TWI_INVALID_ARGUMENT 1
#define TWI_ARBITRATION_LOST 2
#define TWI_NO_CHIP_FOUND 3
#define TWI_RECEIVE_OVERRUN 4
#define TWI_RECEIVE_NACK 5
#define TWI_SEND_OVERRUN 6
#define TWI_SEND_NACK 7
#define TWI_BUSY 8
#define TWI_ERROR_TIMEOUT 9
/**
而读温度是如下代码:
/* 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);
}
运行截图如下:
|