Example 4 – writing to external memory chip

Let's review an example where we write to a flash memory chip on the Sensorian add-on hardware via the SPI interface. The drivers for the SPI interface and the memory chip are available from the same GitHub repository.

Since we already have the drivers downloaded, let's review an example available with drivers:

import sys 
import time
import S25FL204K as Memory

Let's initialize and write the message hello to the memory:

Flash_memory = Memory.S25FL204K() 
Flash_memory.writeStatusRegister(0x00)
message = "hello"
flash_memory.writeArray(0x000000,list(message), message.len())

Now, let's try to read the data we just wrote to the external memory:

data = flash_memory.readArray(0x000000, message.len()) 
print("Data Read from memory: ")
print(''.join(data))

The code sample is available for download with this chapter (memory_test.py).

We were able to demonstrate using the SPI to read/write to an external memory chip.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.116.8.110