Author Topic: Moteino M0 + RFM95W + microSD  (Read 1746 times)

adam.g

  • NewMember
  • *
  • Posts: 21
Moteino M0 + RFM95W + microSD
« on: December 10, 2020, 06:11:29 PM »
Hey Felix,

Hope you're doing well.

Could you point me to information on the forum or website that offer guidance on using both the microSD breakout and the RFM95W at the same time? I haven't yet been able to find any code examples.

I am aware that the SPI chip select pins will need to be managed, but I've been having mixed results with setting the RFM95W A2 pin HIGH and microSD CS (pin 10) LOW in order to allow the microSD to operate. The microSD breakout is soldered directly to the Moteino using the castellated pin grooves.

Curious if there are any general best practices.

Cheers,
Adam

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Moteino M0 + RFM95W + microSD
« Reply #1 on: December 11, 2020, 10:01:54 AM »
I do not have a specific example for that combination, but they are simply 2 SPI devices and you'd work with them like with any others (ex: radio + FLASH memory).
You would take your radio code and add in the SD card code, I provided an example for the SD card here:
https://lowpowerlab.com/guide/moteino/m0-sensor-shields/

adam.g

  • NewMember
  • *
  • Posts: 21
Re: Moteino M0 + RFM95W + microSD
« Reply #2 on: December 11, 2020, 12:11:46 PM »
Thanks, Felix!

I spent a few more hours developing the code and things are working much more smoothly. Timing is everything with the microSD, which requires a certain amount of time to initialize once power is re-established using the P-MOSFET.

I wrote a few functions to handle the enabling/disabling of the RFM95W and microSD that seem to work well.

Now working on lowering the sleep current further, which is currently sitting at about 66 uA.

Cheers,
Adam

Code: [Select]
// Enable microSD power and SPI CS
void enableSd() {
  digitalWrite(PIN_RFM95W_CS, HIGH);  // Disable LoRa SPI CS pin
  delay(1);
  digitalWrite(PIN_MICROSD_EN, LOW);  // Enable power to microSD
  digitalWrite(PIN_MICROSD_CS, LOW);  // Enable microSD SPI CS pin
  delay(250);
}

// Disable power to microSD
void disableSd() {
  digitalWrite(PIN_RFM95W_CS, HIGH);  // Disable LoRa SPI CS pin
  digitalWrite(PIN_MICROSD_EN, HIGH);  // Enable power to microSD
}

// Enable LoRa
void enableLora() {
  digitalWrite(PIN_MICROSD_EN, HIGH); // Disable microSD power
  digitalWrite(PIN_MICROSD_CS, HIGH); // Disable microSD SPI CS pin
  delay(1);
  digitalWrite(PIN_RFM95W_CS, LOW);   // Enable LoRa SPI CS pin
  delay(1);
}

// Disable LoRa
void disableLora() {
  driver.sleep();                     // Enable RFM95W sleep mode
}


Uncle Buzz

  • Full Member
  • ***
  • Posts: 146
  • Country: fr
Re: Moteino M0 + RFM95W + microSD
« Reply #3 on: December 13, 2020, 05:31:48 AM »
once power is re-established using the P-MOSFET.

Do you power your microSD through a mosfet ? the enable pin in your code is the gate of the mosfet and not an enable pin on the miscroSD ? If yes, you could still have some current consumption from your microSD through the SPI pins who are still powered while you use them with other SPI devices. You would have better sleep current by putting your microSD in sleep mode instead of cutting off the power input while SPI bus is still powered. Or add mosfets on SPI bus as well.

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Moteino M0 + RFM95W + microSD
« Reply #4 on: December 14, 2020, 09:23:50 AM »
Or if you really need to, just disable the SPI port and set those GPIO to high impedance...

adam.g

  • NewMember
  • *
  • Posts: 21
Re: Moteino M0 + RFM95W + microSD
« Reply #5 on: December 14, 2020, 11:24:56 AM »
Hi,

Thanks to you both for the suggestions regarding SPI. I created a couple of functions to disable SPI and set all the pins to high impedance, but this only decreased the current consumption in sleep mode to ~55 uA. This is acceptable, but still a bit puzzling.

The second Moteino M0 board I have with an RFM95W and Flash chip is happily sitting at ~12 uA in deep sleep.

Code: [Select]

void goToSleep() {

  // Disable SPI
  SPI.end();

  // Set SPI pins to high impedance state
  pinMode(PIN_MOSI, INPUT);
  pinMode(PIN_SCK, INPUT);
  pinMode(PIN_MISO, INPUT);
  pinMode(PIN_MICROSD_CS, INPUT);
  pinMode(PIN_RF95_CS, INPUT);
  digitalWrite(PIN_MOSI, LOW);
  digitalWrite(PIN_SCK, LOW);
  digitalWrite(PIN_MISO, LOW);
  digitalWrite(PIN_MICROSD_CS, LOW);
  digitalWrite(PIN_RF95_CS, LOW);

  // Enter deep sleep and wait for WDT or RTC alarm interrupt
  LowPower.deepSleep();
}

void wakeUp() {

  // Set SPI pins to low impedance state
  pinMode(PIN_MOSI, OUTPUT);
  pinMode(PIN_SCK, OUTPUT);
  pinMode(PIN_MISO, OUTPUT);
  pinMode(PIN_MICROSD_CS, OUTPUT);
  pinMode(PIN_RF95_CS, OUTPUT);
  digitalWrite(PIN_MOSI, HIGH);
  digitalWrite(PIN_SCK, HIGH);
  digitalWrite(PIN_MISO, HIGH);
  digitalWrite(PIN_MICROSD_CS, HIGH);
  digitalWrite(PIN_RF95_CS, HIGH);

  // Enable SPI
  SPI.begin();
}


Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Moteino M0 + RFM95W + microSD
« Reply #6 on: December 14, 2020, 09:16:50 PM »
The RFM module is still powered so why would you set its CS to low?

adam.g

  • NewMember
  • *
  • Posts: 21
Re: Moteino M0 + RFM95W + microSD
« Reply #7 on: December 15, 2020, 10:22:04 AM »
Thanks Felix,

I'm still getting the hang of managing multiple SPI devices, so I was just testing different combinations of pin states to determine their effect on current consumption.

To clarify, should I be expecting a quiescent draw of ~65 uA with the microSD shield power disabled using the P-MOSFET and the RFM95W placed in sleep mode?

I also tested your example code to reduce drainage, but it appears to achieve the same draw.
Code: [Select]
  //reset SD CS direction to ensure there is no drainage
  PORT->Group[SD_CS_PORT].OUTCLR.reg = (1<<SD_CS_PIN);
  PORT->Group[SD_CS_PORT].DIRCLR.reg = (1<<SD_CS_PIN);
  PORT->Group[BOARD_MOSI_PORT].PINCFG[BOARD_MOSI_PIN].reg = 0;
Cheers,
Adam

Felix

  • Administrator
  • Hero Member
  • *****
  • Posts: 6867
  • Country: us
    • LowPowerLab
Re: Moteino M0 + RFM95W + microSD
« Reply #8 on: December 15, 2020, 03:05:48 PM »
I can't be sure since I haven't done extensive testing but I made that breakout in such a way to make it possible to cutoff power to it completely. Now of course the other non power lines can drain or source some current through the device but given they are GPIO they should be handled differently, and not using discrete mosfets for this purpose, it makes no sense.
The only way to really know or get a very definite answer is to probe each individual GPIO (SPI and anything else) and see where the extra current is coming from.