def readStatusRegister(self,statReg): """ Read the contents of the status register. :param statReg: Address of one of the status registers :returns stat: Status register contents """ self.CE_SELECT() spi.writebytes([statReg]) # send RDSR command byte = spi.readbytes(1) # receive byte self.CE_DESELECT() return byte
def jedec_ID_Read(self): """ Flash memory chip class. :param none: :returns: none """ self.CE_SELECT() spi.writebytes([JEDEC]) #Send JEDEC ID command (9Fh) jedec = spi.readbytes(3) self.CE_DESELECT() jedid = int((jedec[0] << 16) | (jedec[1] << 8) | jedec[2]) return jedid
def readStatusRegister(self, statReg): """ Read the contents of the status register. :param statReg: Address of one of the status registers :returns: stat - Status register contents """ self.CE_SELECT() spi.writebytes([statReg]) # send RDSR command byte = spi.readbytes(1) # receive byte self.CE_DESELECT() return byte
def readByte(self,address): """ Read one byte from the given memory address. :param address: Address of data in memory. :returns: none """ self.CE_SELECT() spi.writebytes([CMD_READ_DATA]) spi.writebytes([(address&0xFF0000)>>16,(address&0xFF00)>>8,address&0xFF,0]) #Read command,Send 3 address bytes mybyte = spi.readbytes(1) self.CE_DESELECT() return mybyte #Return one byte read
def readID(self): """ Flash memory chip class. :param none: :returns: none """ self.CE_SELECT() spi.writebytes([CMD_RDID]) #Send read ID command (90h or ABh) spi.writebytes([0x00]) #Send dummy byte spi.writebytes([0x00]) #Send dummy byte spi.writebytes([0x00]) #Send 0x00 id = spi.readbytes(2) #Send either manufacturer ID or device ID self.CE_DESELECT() return ((id[1] << 8) | id[0])
def readArray(self,address, arrayLength): """ Flash memory chip class. :param address: Starting address of array :param arrayLength: Array length in bytes :returns: none """ pData = [] self.CE_SELECT() spi.writebytes([CMD_READ_DATA,(address&0xFF0000)>>16,(address&0xFF00)>>8,address&0xFF,0]) #Read command pData = spi.readbytes(arrayLength) self.CE_DESELECT() return pData
def readByte(self, address): """ Read one byte from the given memory address. :param address: Address of data in memory. :returns: none """ self.CE_SELECT() spi.writebytes([CMD_READ_DATA]) spi.writebytes([(address & 0xFF0000) >> 16, (address & 0xFF00) >> 8, address & 0xFF, 0]) #Read command,Send 3 address bytes mybyte = spi.readbytes(1) self.CE_DESELECT() return mybyte #Return one byte read
def readArray(self, address, arrayLength): """ Flash memory chip class. :param address: Starting address of array :param arrayLength: Array length in bytes :returns: none """ pData = [] self.CE_SELECT() spi.writebytes([ CMD_READ_DATA, (address & 0xFF0000) >> 16, (address & 0xFF00) >> 8, address & 0xFF, 0 ]) #Read command pData = spi.readbytes(arrayLength) self.CE_DESELECT() return pData