Using two seperate SPI devices on a MEGA

Hello forum,

I built an irrigation monitor / controller that uses LoRa (RA-02) to send pressure and other data to other devices that make up a automation framework on our farm.

I have been using EEPROM to continually save all critcal data so that whenever the system is restarted by the watch dog timer or it is manually reset, it grabs this data and continues seemlessly with its operations. This specific unit controls a centre pivot so it is quite important to continue with the current program after resets.

With the dependability of EEPROM declining with extended use I wrote the code to continually move where I save data into the EEPROM, to spread usage over the whole block, apparently 4kb worth on the MEGA.

I have one device set up elsewhere that has started reading garbage from the EEPROM after restart, I'm assuming some of the blocks have reached the limit of reading writing. This device writes pressure and other data into the EEPROM every second or so, so its heavy traffic and has been working for some months.

NOW - I'm attempting to change from writing to EEPROM to an SD logger. Problem is that the LoRa module already uses the SPI bus, so as soon as I connect the SD logger, the logger works, but LoRa stops working.

Currently the LoRa unit is connected like so:
MOSI - 51
MISO - 50
SCK - 52
CS - 10

Then I connected the SD logger to the ICSP header pins with the CS lead connected to 53.

The SD logger always works, regardless if the LoRa is connected or not. But the LoRa never works while the SD logger is powered up.

Question: Is it possible to get both working at the same time? Or is there another (better / easier) way to save fast coming data that is needed after each reboot?

Question: Is it possible to get both working at the same time?

Yes.

Or is there another (better / easier) way to save fast coming data that is needed after each reboot?

Yes, use a FRAM, there are SPI and I2C versions, their write endurance is 1,000,000,000 times greater than the EEPROM on a Mega.

The SD logger always works, regardless if the LoRa is connected or not. But the LoRa never works while the SD logger is powered up.

Sounds like a cheap Chinese SD card reader that doesn't put MISO to tri-state if CS goes high. Dispose that one and buy a bit higher quality.

Then I connected the SD logger to the ICSP header pins with the CS lead connected to 53

Did you actually change the state of CS?

Post the code, using code tags.

How are you connecting the LoRa device ?

That requires 3.3V logic levels, not sure what your 'SD Logger' requires and the Mega is 5V logic.

I did not change the state - first time messing with SPI in this way. Which one of the two should I change, and to high or low, before or after accessing the device?

srnet:
Yes.

Yes, use a FRAM, there are SPI and I2C versions, their write endurance is 1,000,000,000 times greater than the EEPROM on a Mega.

I'm getting a few of these right now. Thanks.

Looking at Adafruit's version ($10!) it's a bit steep. Do you know where I can the same thing a bit cheaper?

heinburgh:
Do you know where I can the same thing a bit cheaper?

Most Electronic suppliers should have them, Farnell\Element14 etc.

I did not change the state - first time messing with SPI in this way.

CS = "chip select".

It is essential that only one device is active at any one time. You do that by changing the appropriate CS pins on both devices, every time you switch between them. Usually the libraries do this for you.

Consult the device documentation to determine whether HIGH or LOW selects and activates the device.

I'm looking at something like this:

Can these be connected directly or do I need to add other components to make it compatible with Arduino?

That Cypress FRAM is an I2C 5V device, so assuming your Arduino board has the I2C pullups in place, you can connect it directly.

Use an SOIC to DIP adapter if you want to plugh it into a breadboard or stripboard etc.

On the Arduino Mega 2560 board are pull-up resistors of 10k for SDA and SCL. Is this enough for what I need?

heinburgh:
On the Arduino Mega 2560 board are pull-up resistors of 10k for SDA and SCL. Is this enough for what I need?

You would think so, although lower value resistors may be needed depending on the wiring. You need to test it.