Fixed a read bug in BASpiMemory for transfer16()

pull/1/head
Steve Lascos 7 years ago
parent 9db94f24c0
commit 3498d548a9
  1. 65
      src/BASpiMemory.cpp
  2. 3
      src/BASpiMemory.h

@ -132,6 +132,36 @@ void BASpiMemory::write(int address, int data)
digitalWrite(m_csPin, HIGH);
}
void BASpiMemory::write16(int address, uint16_t data)
{
switch (m_memDeviceId) {
case SpiDeviceId::SPI_DEVICE0 :
SPI.beginTransaction(m_settings);
digitalWrite(m_csPin, LOW);
SPI.transfer16((SPI_WRITE_CMD << 8) | (address >> 16) );
SPI.transfer16(address & 0xFFFF);
SPI.transfer16(data);
SPI.endTransaction();
break;
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
case SpiDeviceId::SPI_DEVICE1 :
SPI1.beginTransaction(m_settings);
digitalWrite(m_csPin, LOW);
SPI1.transfer16((SPI_WRITE_CMD << 8) | (address >> 16) );
SPI1.transfer16(address & 0xFFFF);
SPI1.transfer16(data);
SPI1.endTransaction();
break;
#endif
default :
break;
// unreachable
}
digitalWrite(m_csPin, HIGH);
}
// single address read
int BASpiMemory::read(int address)
{
@ -172,4 +202,39 @@ int BASpiMemory::read(int address)
return data;
}
uint16_t BASpiMemory::read16(int address)
{
uint16_t data=0;
switch (m_memDeviceId) {
case SpiDeviceId::SPI_DEVICE0 :
SPI.beginTransaction(m_settings);
digitalWrite(m_csPin, LOW);
SPI.transfer16((SPI_READ_CMD << 8) | (address >> 16) );
SPI.transfer16(address & 0xFFFF);
data = SPI.transfer16(0);
SPI.endTransaction();
break;
#if defined(__MK64FX512__) || defined(__MK66FX1M0__)
case SpiDeviceId::SPI_DEVICE1 :
SPI1.beginTransaction(m_settings);
digitalWrite(m_csPin, LOW);
SPI1.transfer16((SPI_READ_CMD << 8) | (address >> 16) );
SPI1.transfer16(address & 0xFFFF);
data = SPI1.transfer16(0);
SPI1.endTransaction();
break;
#endif
default:
break;
// unreachable
}
digitalWrite(m_csPin, HIGH);
return data;
}
} /* namespace BAGuitar */

@ -60,10 +60,13 @@ public:
/// @param data the value to write
void write(int address, int data);
void write16(int address, uint16_t data);
/// read a single data word from the specified address
/// @param address the address in the SPI RAM to read from
/// @return the data that was read
int read(int address);
uint16_t read16(int address);
private:
SpiDeviceId m_memDeviceId; // the MEM device being control with this instance

Loading…
Cancel
Save