The following code (long-hand version with lots of comments) provides a quick way to test a uDrive and uSD card. The 5-pin uDrive module from 4D Systems provides a very compact and inexpensive way to exploit the huge amount of memory available on uSD cards. Only six serial commands are needed to communicate with the uDrive and it appears to be relatively easy to use.
However, my initial impression is that the uDrive is only suitable for a limited number of PICAXE based applications. For example, with only a PICAXE and uDrive connected to a 5 volt supply the current draw was in the order of 50mA whilst writing continuously and the data rate is quite slow using the single byte mode. It takes about six seconds to write 256 bytes at 9600 baud. The data rate could be significantly increased by using the uDrives 512-byte block mode. However, for my logging application, I can’t think of a simple way for the PICAXE to store and output 512 blocks of data to the uDrive, whilst sampling a number of ADC input channels at a constant rate?
'UDrive memory test for first 256 memory locations, using 40-X1 at 8MHz.
high 1 'Reset must start high
high 0 'Serial output must start high
pause 2000 'Allow drive to boot
serout 0, T9600_8,("U") 'Set drive baud rate
serin 7, T9600_8, b13 'Wait for ack or nak from drive
for b0 = 0 to 255
serout 0, T9600_8, ("@w",b0) 'Write test byte
serin 7, T9600_8, b13 'Wait for ack or nak from drive
next b0
low 1 'Start reset
pause 100 'Hold reset low
high 1 'End reset
pause 2000 'Reboots drive & resets address counter
b0 = 0 'Reset loop counter
serout 0, T4800_8,("U") 'Set drive baud rate
serin 7, T4800_8, b13 'Wait for ack or nak from drive
for b0 = 0 to 255
serout 0, T4800_8,("@r") 'Request data
serin 7, T4800_8, b1 'Read byte
if b1 <> b0 then Fail 'Check for error
next b0 'Next address location
sertxd ("Pass ",cr) 'Send pass message
end
Fail:
sertxd ("Fail at address ",#b0,": returned ",#b1,CR) 'Send error message
However, my initial impression is that the uDrive is only suitable for a limited number of PICAXE based applications. For example, with only a PICAXE and uDrive connected to a 5 volt supply the current draw was in the order of 50mA whilst writing continuously and the data rate is quite slow using the single byte mode. It takes about six seconds to write 256 bytes at 9600 baud. The data rate could be significantly increased by using the uDrives 512-byte block mode. However, for my logging application, I can’t think of a simple way for the PICAXE to store and output 512 blocks of data to the uDrive, whilst sampling a number of ADC input channels at a constant rate?
'UDrive memory test for first 256 memory locations, using 40-X1 at 8MHz.
high 1 'Reset must start high
high 0 'Serial output must start high
pause 2000 'Allow drive to boot
serout 0, T9600_8,("U") 'Set drive baud rate
serin 7, T9600_8, b13 'Wait for ack or nak from drive
for b0 = 0 to 255
serout 0, T9600_8, ("@w",b0) 'Write test byte
serin 7, T9600_8, b13 'Wait for ack or nak from drive
next b0
low 1 'Start reset
pause 100 'Hold reset low
high 1 'End reset
pause 2000 'Reboots drive & resets address counter
b0 = 0 'Reset loop counter
serout 0, T4800_8,("U") 'Set drive baud rate
serin 7, T4800_8, b13 'Wait for ack or nak from drive
for b0 = 0 to 255
serout 0, T4800_8,("@r") 'Request data
serin 7, T4800_8, b1 'Read byte
if b1 <> b0 then Fail 'Check for error
next b0 'Next address location
sertxd ("Pass ",cr) 'Send pass message
end
Fail:
sertxd ("Fail at address ",#b0,": returned ",#b1,CR) 'Send error message