diff --git a/src/w25qxx.cpp b/src/w25qxx.cpp index b8ce0f2..5483c4e 100644 --- a/src/w25qxx.cpp +++ b/src/w25qxx.cpp @@ -1,7 +1,9 @@ #include #include + #include +#include namespace sta @@ -30,10 +32,10 @@ namespace sta uint8_t W25Qxx::getManufacturerID() { - Address24 address = {0}; - + uint8_t dummy[3] = {0, 0, 0}; uint8_t id; - busRead(W25QXX_JEDEC_ID, &id, 1, address.buffer, 3); + + busRead(W25QXX_JEDEC_ID, &id, 1, dummy, 3); return id; } @@ -43,9 +45,11 @@ namespace sta uint8_t dummy[4]; uint8_t id[8]; + STA_DEBUG_PRINTLN("Before crash?"); + busRead(W25QXX_READ_UNIQUE_ID, id, 8, dummy, 4); - uint64_t id_complete; + uint64_t id_complete = 0; for (size_t i; i < 8; i++) { @@ -99,11 +103,49 @@ namespace sta uint8_t W25Qxx::busWrite(uint8_t instruction, const uint8_t * data /* = nullptr */, size_t length /* = 0 */, uint8_t * arguments /* = nullptr */, size_t arg_length /* = 0 */) { + device_->beginTransmission(); + + // Send the instruction. + device_->transfer(instruction); + + // If requested, send argument bytes before the actual data. + if (arguments != nullptr && arg_length != 0) + { + device_->transfer(arguments, arg_length); + } + + // Send the actual data bytes. + device_->transfer(data, length); + + device_->endTransmission(); + return 1; } uint8_t W25Qxx::busRead(uint8_t instruction, uint8_t * data, size_t length, uint8_t * arguments /* = nullptr */, size_t arg_length /* = 0 */) { + device_->beginTransmission(); + + STA_DEBUG_PRINTLN("MAYBE HERE?"); + + // Send the instruction. + device_->transfer(instruction); + + STA_DEBUG_PRINTLN("OR HERE?"); + + // If requested, send argument bytes before receiving the actual data. + if (arguments != nullptr && arg_length != 0) + { + device_->transfer(arguments, arg_length); + } + + // Send the actual data bytes. + device_->receive(data, length); + + device_->endTransmission(); + + STA_DEBUG_PRINTLN("STILL ALIVE?"); + return 1; }