Загрузил Alexandr F

Новый текстовый документ (3)

реклама
case WRITE:
if (chip == NONE) {
mode = WAIT;
break;
}
message("Write mode");
/*for (int i = start_address; i <= end_address; i++) {
Serial.println(i, HEX);
write_byte(i, 0x89);
}*/
for (uint16_t i = start_address; i <= end_address; i += BUF_LEN) {
Serial.print("Write block ");
Serial.println(i);
uint8_t count = Serial.readBytes((char*)buf, BUF_LEN);
if (count != BUF_LEN) {
Serial.print("Error on block");
Serial.println(i);
Serial.print("Received ");
Serial.println(count);
break;
}
for (uint16_t j = 0; j < BUF_LEN; j++) {
// Write byte
write_mode();
program_voltage_set(true);
write_byte((i + j), buf[j]);
program_voltage_set(false);
// Verify byte
read_mode();
if (chip == C16) digitalWrite(readVoltageEnable, LOW);
digitalWrite(chipEnable, LOW);
digitalWrite(outputEnable, LOW);
uint8_t verify = get_data();
digitalWrite(outputEnable, HIGH);
digitalWrite(chipEnable, HIGH);
if (chip == C16) digitalWrite(readVoltageEnable, HIGH);
if (buf[j] != virify){
Serial.print("Error on address ");
Serial.println(i + j);
mode = WAIT;
}
}
Serial.print("Complete block ");
Serial.println(i);
if (i == end_address) break;
}
message("Write success.");
mode = WAIT;
break;
Скачать