When leaving a project running that generates occasional log files /other data out of a serial data port it's nice to have some way of constantly monitoring and collecting this serial data for later readback.
After power-on while and waiting for first input byte = micropower standby mode. No power switch.
First input byte activates the software. Data speed fixed at 9600,8,n
During the input data a timer-controlled interrupt service (ISR) periodically samples the RXD input to receive serial data. Each time the ISR called it builds the incoming byte and when a byte is complete it's then written to the microcontroller's RAM ('Store'). Simultaneously in the ISR process the TXD output pin echoes RXD as a realtime recording monitor.
RAM Store is 80(?) bytes wide and wrapped around into a loop. When end of this Store reached write starts again from the beginning. Old Store data in RAM is continually overwritten as it circulates around. This is the incoming data buffer.
To keep track of the buffered data in Store there is Store Pointer (SP) and a ReadStore Pointer (RSP) which track write and read positions respectively. Each new received input byte increments the SP by one.
When SP (write) overtakes RSP (read) by 64 bytes or more this triggers a read out of a batch of 64 bytes from the Store and written via I2C to the flash memory at the same time as receiving data. Each byte read out from Store increments RSP by one. The E2PROM page write consists of 64 bytes. Total page write processing time of the E2PROM is about 5 ms irrespective of I2C clock speed.
The I2C communications with E2PROM is paused momentarily whenever servicing the ISR while reading incoming RXD input data. The I2C protocol doesn't mind these random wait states as it's static and asynchronous.
After a period of non-activity the device resumes micropower standby.
Pressing the Mode button at any time cancels Record. The recorded data in the E2PROM is played back on the output port, typically to a computer. Pressing the Mode button during playback cancels the process and device returns to Record mode.
Press and hold the Mode button.