This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Writing/reading data to external flash on the nRF9160DK

Hello Nordic!

I have connected a sensor to the DK via SPI. It outputs a lot of data, a lot... for 1 second of data I get 4096 entries. Each entry is 10 bytes in length.


I want to store 20 seconds of sensor data on the flash memory, that is a total of about 0,8 MB if my calculations are correct.

The sensor has a FIFO-queue so if the write operation is quick enough there shouldn't be any data loss.
Once 20 seconds worth of data is recorded I then want to send this via LTE to server, I'm guessing in chunks.

Questions:
* How do I go about this? Is there a binary write example available?

* What size should the chunks be for this example?

* Once a file is written and done, before going in to the LTE-part of the design, is there any way to extract the bin file for data validation from the DK?


Thank you!

Parents Reply Children
  • Hi! Thanks Håkon! I'm already using SPI3 for a sensor, can I just add an arbitrary number to the SPI interface? Like SPI4? Are there any examples writing to the external flash? I'd like to create numerous .bin or .hex files which I then send via LTE to server, once acknowledged that they are recieved, I want to free up that memory for other sensor data.

  • Hi,

     

    nWre said:
    I'm already using SPI3 for a sensor, can I just add an arbitrary number to the SPI interface? Like SPI4?

    No, do not do that. This will then point the hardware to a non-existing SPI instance. nRF9160 has from 0 to 3:

    https://infocenter.nordicsemi.com/topic/ps_nrf9160/spim.html?cp=2_0_0_5_12_5#topic

    If you want to setup more than one sensor, you should do it similar to how it is done on the thingy91:

    https://github.com/nrfconnect/sdk-nrf/blob/main/boards/arm/thingy91_nrf9160/thingy91_nrf9160_common.dts#L128-L151

     

    nWre said:
    Are there any examples writing to the external flash? I'd like to create numerous .bin or .hex files which I then send via LTE to server, once acknowledged that they are recieved, I want to free up that memory for other sensor data.

    Once you have setup the external flash area, you can address it directly to the flash-backend that you're using (NVS, littlefs or which ever you chose). The logic you require needs to be added manually in your application.

     

    Kind regards,

    Håkon

  • Hi! I have it setup like this in an overlay file:

    &spi3 {
    	compatible = "nordic,nrf-spim";
    	status = "okay";
    	sck-pin = <19>;
    	mosi-pin = <18>; 
    	miso-pin = <17>; 
    	cs-gpios = <&gpio0 23 0>,<&gpio0 22 0>,<&gpio0 21 0>; 
    	clock-frequency = <10000000>;
    	label = "SENSORARRAY";
    	sensor8: sensor8@0 {
    		compatible = "adi,adxl355";
    		status = "okay";
    		label = "sensor8";
    		spi-max-frequency = <10000000>;
    		reg = <0>;
    	};
    
    	sensor40: sensor40@1 {
    		compatible = "adi,adxl357";
    		status = "okay";
    		label = "sensor40";
    		spi-max-frequency = <10000000>;
    		reg = <1>;
    	};
    	sensor200: sensor200@2 {
    		compatible = "adi,adxl375";
    		status = "okay";
    		label = "sensor200";
    		spi-max-frequency = <10000000>;
    		reg = <2>;
    	};
    };


    I can communicate with the sensors but they do interfere with each other even when their corresponding cs-pin is set to high(blocking). I don't really understand why but one question I have about this is if

    spi_dev = device_get_binding("SENSORARRAY");

    Instead should be separated by child nodes, like this
    spi_dev8 = device_get_binding("sensor8");
    spi_dev40 = device_get_binding("sensor40");
    spi_dev200 = device_get_binding("sensor200");


    I've tried this all day but couldn't get any other value from this but null. I've tried aliases, node_label, node_path but nothing. Maybe I'm misunderstanding this and that the master is the dev, not the slaves.

    I'm using the same MISO,MOSI and SCLK lines for all three. They also share 3V-input and GRND. Apart from this they have different CS-pins. I've tried them one by one and they're all working, however when I connect more than one sensor, there is interference.

    I hope you can clear some of this up for me, I'll keep banging my head against your fine hardware in the meantime ;)

    Snowy, gothenburgian regards!

    Edit: It appears as though I am not the solderer I thought I was. The interference came from shoddy soldering. I would still like to know the answer to the device binding question though, as of now, it works with getting the spi binding for all three sensors.

  • Hi,

    nWre said:
    Snowy, gothenburgian regards!

    Close to 15 below, and around 20 cm of snow here as well!

     

    nWre said:
    Edit: It appears as though I am not the solderer I thought I was. The interference came from shoddy soldering. I would still like to know the answer to the device binding question though, as of now, it works with getting the spi binding for all three sensors.

    Glad to hear that you found the root cause of the hardware-wise connections.

    I have some bad news for you. The sensors that you configure for are not compatible with any sources (note: dts "compatible = "vendor,component"" maps to source files, which are then included in your project):

    https://github.com/nrfconnect/sdk-zephyr/tree/main/dts/bindings/sensor

     

    adxl345, 362 and 372 are supported by zephyr. I'm not sure that your sensors are compatible 1-to-1 with those drivers, so you might have to interface them manually, using the spi driver directly. Here's a sample a colleague of mine wrote:

    https://github.com/sigurdnev/ncs-playground/tree/master/samples/spi_test

     

    Snowy regards from Trondheim,

    Håkon

  • It is a rare treat for us to get snow down here and even though the entire community and infrastructure shuts down, I really enjoy it. I miss living in the north.

    Ontopic: Yes, I realized that too, so I've written my own drivers by studying the datasheet of the respective component. They are included in my main.c-file. The compatible part is really just a copy paste of the adxl362 and doesn't contain any functionality. The drivers are working flawlessly for 2 of the 3 sensors. I am yet to figure out what causes problem with the third one. I handle the cs-pins manually, putting them high or low before reads/write. On these sensors, a high cs pin blocks data. So reading from 1 sensor, keeping the other two cs pins high, should only give me data stream from that sensor, however, there is a strange interference when doing this. Sorry for rambling, I understand this is impossible for you to help with.

    Off to spend the weekend in the woods in a tent, with a stove and multiple beers.
    Take care Håkon, I'll return with more rambling questions about writing to external memory in a bit

Related