Miles,
Your code seems to just read serin at startup. It doesn't sleep after the serin from the xbee.
My issue is the xbee is not sleeping when it should. This can only be observed by measuring the current drawn right from initial power up.
pseudo code :
power on
wake up xbee
wait for 1 second
sleep xbee
sleep picaxe for 6 seconds
goto wake up xbee
That code should take 7 seconds to run a loop. It does not have to read any data from serin. But on my circuit, the very first time it runs it takes 15 seconds before you see the evidence of the first "sleep xbee" . It should theoretically take only 1 second. During those 15 seconds, the xbee is pulling its normal idle current (50mA).
That is my issue. I'm not seeing a delay waking the xbee, I'm seeing a delay "sleeping" the xbee on the first run through.
The RSSI is wired because it is the only way of checking for RF activity without reading serin. That is why the xbee wakes for 1 second, to check for RF activity. If you open serin and there is nothing to read, the code hangs (waits for serin to complete) and the xbee remains awake. However, if you check for a high on the RSSI pin, then you're assured that there is RF activity, and so it is worth checking for data via serin. If the RSSI pin is low then there is no RF activity, the code should skip serin and then carry on and sleep the xbee. This has no bearing on the initial sleep issues I'm seeing, as far as I can make out. If there were an erroneous reading from the RSSI pin, it would trigger a serin and the code would hang and never reach xbee sleep. This is not happening, as after 15 seconds the xbee
does sleep, ergo serin is not hanging. It is not reading a signal either, as this happens whether or not the transmitter is powered up. I also have a third xbee permanently awake and connected to a pc which reads any data "in the air" so to speak, and prints it out in hyper terminal. This is seeing nothing.
For what it's worth, I also see a similar problem on my transmitting device. The code for that should hibernate the xbee immediately on power up, yet it takes 15 seconds (or so) to see a decrease from xbee current levels.
I have reset both modules to default firmware settings, tried other modules at default settings, and even measured for time differences at lower baud rates, all to no avail.
I'm virtually convinced that these modules cannot be forced to sleep within 10 seconds of power up. Not by using pin sleep anyway. I can get the time down from 15 to 10 by powering up with the reset held down, but if I were to use reset instead of pin sleep during normal runtime, I end up using more power on average overall. Increased overall battery life is what I'm aiming at. To lose the initial 10 seconds at 50mA would be great, but not at the expense of using more power over the course of a day. That is cutting my nose off to spite my face.
Here's the way I'm calculating the average current :
my loop is 7 seconds long, and of that 7 seconds -
1 second = 50 mA
6 seconds = 0.2 mA per second = 1.2 mA
overall current for 7 seconds = 51.2 mA
normal average 1 second current = 51.2 / 7 = 7.31 mA
My circuit shows a 10 second current (at power up) of 50 mA
10 seconds = 50 mA per second = 500 mA
initial average current for 1 second = 50 mA
This only happens once, so if the circuit is powered for 60 seconds -
10 seconds = 500 mA (50 mA x 10 seconds)
50 seconds = 365.5 mA (7.31 mA x 50 seconds)
overall current for 60 seconds = 865.5 mA
average 1 second current = 14.43 mA
if the circuit is powered for 1 hour -
10 seconds = 500 mA
3590 seconds = 26242.9 mA (7.31 mA x 3590 seconds)
overall current for 1 hour = 26742.9 mA
average 1 second current = 26742.9 / 3600 seconds = 7.42 mA
I realise those numbers look screwy, it looks as if a 1Ah battery should only last just over a minute based on the current drawn overall, but I think the average is what counts. If I draw 100 mA (average) the 1000 mA battery lasts 10 hours, if I draw 10 mA the battery lasts 100 hours, if I draw 7.42 mA the battery should last 134.77 hours. Maths isn't my strongest point though, so feel free to criticise
(Furthermore, if I were using pin reset the average per second (measured over 7 seconds) would rise to 11.43 mA due to the circuit drawing 5 mA while asleep. Measured over an hour it would be a 1 second average of 11.53 mA, and over more than 1 hour, it would keep rising.)
So you can see that if I power the circuit for an hour or more then I am virtually at the minimum average current I can get to for my coded xbee wake time of 1 second per 7 seconds, sleep issues not withstanding.
It's not really worth worrying about, other than to be pedantic. I'm just being a control freak, and if I tell it to sleep, there has to be a good reason why it doesn't.
I can't find that reason.
cheers
Alan
ps. just saw your latest post - no, I'm not using any AT commands. I posted the code I'm using a
couple of pages back.