Author Topic: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?  (Read 14614 times)

WhiteHare

  • Hero Member
  • *****
  • Posts: 1300
  • Country: us
Re: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?
« Reply #30 on: April 28, 2016, 09:40:08 AM »
Excerpted directly from the RFM69 library:
Code: [Select]
    virtual bool sendWithRetry(uint8_t toAddress, const void* buffer, uint8_t bufferSize, uint8_t retries=2, uint8_t retryWaitTime=40); // 40ms roundtrip req for 61byte packets

OSBSS

  • NewMember
  • *
  • Posts: 29
  • Country: us
    • OSBSS - Open Source Building Science Sensors
Re: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?
« Reply #31 on: April 28, 2016, 03:57:31 PM »
@WhiteHare thanks, looks good enough actually.
@perky I have a similar setup when I first created this post.. since I'm using an accurate clock anyway (~2ppm), it should work fine. But now I'm questioning the need of putting a crystal on the node at all. If the idea is to check where in the sequence a node is and go to sleep till its time slot, then it becomes dependent on the accuracy of the crystal on the node itself. Then you end up adding extra logic to account for drift or constantly adjust the time. Instead, might as well just put all nodes permanently in listen mode and wait till the gateway sends a wake packet to each node individually. Not sure yet how the nodes react to "sniffing" for packets and find one that's meant for them, but will see.

OSBSS

  • NewMember
  • *
  • Posts: 29
  • Country: us
    • OSBSS - Open Source Building Science Sensors
Re: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?
« Reply #32 on: April 28, 2016, 04:06:19 PM »
Just thought I'd share my current setup:

I made two shields for each node: An RTC shield (with a DS3234 clock) and a sensor shield that measures temp, RH, light intensity and can attach a thermistor probe for measuring air stream temps in an HVAC duct or surface temps or wherever needed. Here are the individual shields:



And here's one node:



I have two gateways, but I'll just share the one with WiFi:





Not the best, but all these were initial prototypes that I assembled a couple of months back. The gateway I use now has an RTC, uses Ethernet as opposed to shitty WiFi and I'm experimenting with listen mode on each node. I would be able to save $10 on each node if I can get rid of that clock and just leave it on the gateway instead.
« Last Edit: April 28, 2016, 04:10:14 PM by OSBSS »

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?
« Reply #33 on: April 28, 2016, 04:23:57 PM »
Nice kit! Do you fit the the battery on the RTC? I guess there's not much need with a LiPo.

Actually there's a fundamental misunderstanding of listen mode I think. You can't just send a packet to wake it up, listen mode is basically a sleep mode with an internal timer that wakes it up periodically, so it's a question of whether you use the radio's internal timer, or the MCU or RTC as the timer. I think you'd get better accuracy with the MCU than the radio, and potentially even better with an external RTC with temperature compensated oscillator on board.
Mark.

OSBSS

  • NewMember
  • *
  • Posts: 29
  • Country: us
    • OSBSS - Open Source Building Science Sensors
Re: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?
« Reply #34 on: April 28, 2016, 04:42:11 PM »
@perky - Thanks! Yeah, the LiPo was supposed to be the main power source. I was using CR1225 coin cells for time-keeping only, since I didn't want the clocks to die because of any error in code that would make the node stay on till I realized they're all dead. But these are early prototypes and I am constantly upgrading the design and components each time I learn something new.

Ah - that was what I was looking for. I am not really well-versed on the listen mode yet. I think that makes sense - so the radio is made to periodically "pulse" in RX mode for a very short duration and sleeping in between. Then when it actually receives anything, it wakes the MCU up with an interrupt. Am I saying that correctly? If that's the case, then how would you make the radio rely on an external oscillator rather than its internal timer? Sounds like that setup won't work even with my temp. compensated oscillator as the timing precision can only go down to 1 second. It does have 32 kHz SQW output as well though, so might be able to use that.

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?
« Reply #35 on: April 28, 2016, 05:21:28 PM »
Unfortunately whenever the radio is in receive mode it consumes 16mA, so yes - the radio in listen mode periodically wakes up, if it get a packet within a timeout priod will receive it and interrupt the MCU with a payloadready interrupt otherwise it goes back to sleep until the next wakeup time. That in turn wakes up the MCU which can then read the received packet out of the radio via SPI. With the MCU as the timer it gets a wakeup interrupt from it's on-board, constantly running, timer and wakes up the radio by putting it into RX mode via the SPI interface. An external RTC has 2 options, generate an interrupt at a known time (better for power as the MCU can be put into deep sleep mode), or generate a clock out. If you want resolution you'll either need to find a RTC with the ability to program an interrupt time to that resolution, or use its square wave output and drive your MCU's internal timer clock from that. The RTC's oscillator could be much more accurate than a crystal on the MCU.

Mark.

TomWS

  • Hero Member
  • *****
  • Posts: 1929
Re: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?
« Reply #36 on: April 28, 2016, 05:29:29 PM »
Actually there's a fundamental misunderstanding of listen mode I think. You can't just send a packet to wake it up, listen mode is basically a sleep mode with an internal timer that wakes it up periodically, so it's a question of whether you use the radio's internal timer, or the MCU or RTC as the timer. I think you'd get better accuracy with the MCU than the radio, and potentially even better with an external RTC with temperature compensated oscillator on board.
Mark.
Actually, you can send a packet and wake up a listen mode node IFF the packet arrives when the listen mode cycle is in RX Mode, not Idle mode.  That is why Joe's ListenMode code sends a burst of packets that it slightly longer than the full listen mode cycle (IDLE+RX times).

You can use it as a low power timer, but you can also use it for wake on demand.

Tom

TomWS

  • Hero Member
  • *****
  • Posts: 1929
Re: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?
« Reply #37 on: April 28, 2016, 05:36:33 PM »
@OSBSS, I'll echo perky's comment.  Very nice job!  Good work!

I do have one question, I didn't realize that you were using SD card along with the DS3234, Radio, and display(?) all on the same SPI link.  I have had problems using SD card with other SPI devices, where I had an open SD file that contained a log and I'd alternate between device and SD card access.  I haven't had a problem sharing when the IO operation was 'atomic', ie, open the file, write, close it  and then use SPI on a different device.  Have you had any issues?  What SD library are you using?

Tom

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?
« Reply #38 on: April 28, 2016, 05:46:07 PM »
Quote
Actually, you can send a packet and wake up a listen mode node IFF the packet arrives when the listen mode cycle is in RX Mode, not Idle mode.  That is why Joe's ListenMode code sends a burst of packets that it slightly longer than the full listen mode cycle (IDLE+RX times)

Not sure that works well for longer cycle times. If it's 5 mins per cycle, do you transmit constantly for the full 5 minutes?

Just had a thought, in theory you could use listen mode as a wakeup timer by programming the RSSI threshold register to 0xFF. the MCU would wake up (on noise), send a packet, and it's ACK it gets back could contain the next timeslot time for that node. The gateway would be in receive mode constantly during that initial phase, then go into receive on just the timeslots if power was an issue. Is that how it works?
« Last Edit: April 28, 2016, 06:06:46 PM by perky »

OSBSS

  • NewMember
  • *
  • Posts: 29
  • Country: us
    • OSBSS - Open Source Building Science Sensors
Re: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?
« Reply #39 on: April 28, 2016, 05:59:30 PM »
@Tom thanks!

Yes, all of them share the same SPI bus. I'm using SdFat by William Greiman: https://github.com/greiman/SdFat. I've noticed SPI issues with the latest version of the library along with latest IDE. I'm using a late 2014 commit of the library, which for all intents and purposes isn't recommended by Greiman himself, but it works for my setup. It's not necessary, but if you add external 10K pullups to the data lines, you can force the SD card into sleep mode between communications. I get time from the DS3234 while the file is open on the SD card, so I don't see why it wouldn't work.

TomWS

  • Hero Member
  • *****
  • Posts: 1929
Re: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?
« Reply #40 on: April 28, 2016, 06:05:34 PM »
Quote
Actually, you can send a packet and wake up a listen mode node IFF the packet arrives when the listen mode cycle is in RX Mode, not Idle mode.  That is why Joe's ListenMode code sends a burst of packets that it slightly longer than the full listen mode cycle (IDLE+RX times)

Not sure that works well for longer cycle times. If it's 5 mins per cycle, do you transmit constantly for the full 5 minutes?
The implementation included in the ATC library is 2.882 seconds total time with a sendBurst method that sends packets for 3 seconds.  The RX window is very narrow (256uS) giving a duty cycle of around 0.089%.  The RX power is not terribly burdensome in this case  ;)

Tom

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?
« Reply #41 on: April 28, 2016, 06:10:25 PM »
That is short! I wasn't expecting such a short RX time. OK, maybe it's usable then ;-)

TomWS

  • Hero Member
  • *****
  • Posts: 1929
Re: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?
« Reply #42 on: April 28, 2016, 06:15:11 PM »
Yes, all of them share the same SPI bus. I'm using SdFat by William Greiman: https://github.com/greiman/SdFat. I've noticed SPI issues with the latest version of the library along with latest IDE. I'm using a late 2014 commit of the library, which for all intents and purposes isn't recommended by Greiman himself, but it works for my setup. It's not necessary, but if you add external 10K pullups to the data lines, you can force the SD card into sleep mode between communications. I get time from the DS3234 while the file is open on the SD card, so I don't see why it wouldn't work.
The SD card breakout board I'm using does have 10K pullups.  I haven't mounted my own socket yet (although I need to for the project I'm working on).  This was one of the reasons I'm thinking about the 328PB with its two SPI channels so I can totally isolate the SD card, but I'm not sure I want to enter the quicksand of trying to build 328PB support for the IDE and port the libraries I need.  I just might switch over to ARM for this project...  OTOH, the SD Fat library I'm using is the Feb 2016 version so maybe I should try to go back to an older one...

Thanks for the info.

Tom

TomWS

  • Hero Member
  • *****
  • Posts: 1929
Re: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?
« Reply #43 on: April 28, 2016, 06:18:59 PM »
That is short! I wasn't expecting such a short RX time. OK, maybe it's usable then ;-)
We can move this to another thread if you want to continue this, but the short answer is that the data rate is stepped up to 200Kb with the original thought being there didn't need to be 'useful' content.  As it turned out the content is pretty reliable and I use it for signalling the purpose of the wake up burst.

Tom

perky

  • Hero Member
  • *****
  • Posts: 873
  • Country: gb
Re: Moteinos + DS3234 RTC sharing SPI - require hard reset each time?
« Reply #44 on: April 28, 2016, 06:20:32 PM »
I was just curious, OT for this thread as you say.