uM2(+): data logging - cheap fast & easy


Author Message
matherp
Guru

Joined: 11/12/2012
Location: United Kingdom
Posts: 11980
Posted: 06:36am 27 Mar 2016      

UPDATE

I should have mentioned in the original post that the spare pad on the back of many TFT displays will take one of the 25Q series chips and, at least on the displays I've checked, is correctly wired. The only additional connection is to the F_CS chip select pin on the display.

To improve logging speed by a factor of 2 please substitute this CFunction

CFunction getnextfreepage
00000000
27BDFEC8 AFB7012C AFBF0134 AFBE0130 AFB60128 AFB50124 AFB40120 AFB3011C
AFB20118 AFB10114 AFB00110 8C820004 8C830000 000227C3 308407FF 00831821
0064B82B 02E2B821 0017BD40 00031AC2 02E3B825 1AE00049 8CB60000 0000A021
3C159D00 3C10BF80 241E0003 27B20110 24130020 8EA2001C 02C02021 0040F809
24050005 00141A00 AE1E5820 8E025810 30420080 1040FFFD 7C623C00 8E045820
AE025820 8E025810 30420080 1040FFFD 7C623A00 8E045820 AE025820 8E025810
30420080 1040FFFD 00000000 306300FF 8E025820 AE035820 8E025810 30420080
1040FFFD 00000000 8E025820 27A30010 AE115820 8E025810 30420080 1040FFFD
00000000 8E115820 7C118C20 A0710000 24630001 1472FFF6 02C02021 8EA2001C
0040F809 24050006 8FA20010 8FA30014 00431025 14400013 00002021 27A20018
24040001 8C430000 8C450004 00651825 1460000C 24420008 24840001 5493FFFA
8C430000 26940001 0297102A 5440FFC2 8EA2001C 10000003 24040100 0000A021
00002021 27A30010 000410C0 00621021 8C460000 8C450004 30C30001 14600011
00001021 24020001 00055840 240A0040 00024827 00461806 012B4804 30480020
00453807 01231825 00E8180B 30630001 54600005 0014A140 24420001 144AFFF5
00024827 0014A140 02842021 8FBF0134 00042180 00441021 00021FC3 8FBE0130
8FB7012C 8FB60128 8FB50124 8FB40120 8FB3011C 8FB20118 8FB10114 8FB00110
03E00008 27BD0138
End CFunction


for this Basic code

function getnextfreepage(pagecount as integer, cspin as integer) as integer 'gets the page number of the next completely unused page
local integer i,j,r(31),p=0,found=0,indexsize=pagecount\2048
for i=0 to indexsize-1 'potentially look at all pages
readpage(i,r(),cspin)
for j=0 to 31
if r(j) then
p=j 'there must be at least one spare page if not zero
found=1
exit for
endif
next j
if found then exit for
next i
for j=0 to 63
if (r(p)>>j) and 1 then exit for
next j
getnextfreepage=i*2048+p*64+j
end function


C source


long long getnextfreepage(long long *pagecount, long long *cspin){
long i,j,k=0,found=0,indexsize=*pagecount/2048,add,pin=*cspin ;
union ftype{
long long a[32];
char b[256];
}r;
for (i=0; i< indexsize;i++){ //potentially look at all pages
char m;
add=i<<8; //convert page number to byte number
PinSetBit(pin,LATCLR);
SPIsend(readdata);
SPIsend((add>>16) & 0xFF);
SPIsend((add>>8) & 0xFF);
SPIsend(add & 0xFF);
for(k=0;k<256;k++){
SPIread(m);
r.b[k]=m;
}
PinSetBit(pin,LATSET);
for(j=0 ;j<32;j++){
if (r.a[j]) {
k=j; //there must be at least one spare page if not zero
found=1 ;
break;
}
}
if (found) break;
}
for (j=0 ;j<64;j++) if ((r.a[k]>>j) & 1) break;
return i*2048+k*64+j ;
}



For those learning C note how the union ftype allows me to treat a 256-byte area of memory as either an array of bytes (8-bit) or an array of long longs (64-bit)Edited by matherp 2016-03-28