26 / 30
iSense Ethernet Gateway User Guide
coalesenses
research to innovate
net10_ -> set_led( 0, false );
}
if
(
led_value_
&
0x02
){
net10_ -> set_led( 1, true );
}
else
{
net10_ -> set_led( 1, false );
}
if
(
sd_card_ != NULL && sd_card
->
is_ready()
){
//Increment the button counter by one
button_co+;
char
write_data[39];
//Write value of button_counter_ to write_data
uint8 bytes = snprintf( write_data, 39, “button_counter_ =
%lld”, button_counter_ );
//Try to write write_data to SD-Card at address 0, and check if
//writing was successful
uint8 result = sd_card_->access( 0, bytes, (uint8*) write_data,
true
);
if
(
(result & 0x1F) == RESPONSE_DATA_ACCEPTED
){
os_.debug(“Writing to SDCard successful”);
memset( write_data, 0, 39 );
//Try to read the written data and verify if reading was
//successful
result = sd_card_->access( 0, bytes, (uint8*) write_data,
false
);
if
(
result == 0
){
//If reading was successful, print the read data
os_.debug(“\”%s\” read”, write_data );
}
else
{
os_.fatal( “reading failed” );
}
}
else
{
os_.fatal( “ERROR! Code: %d”, (result & 0x1F) );
}
}
When the button of the Ethernet Gateway Module is pressed the
led_value_
variable modified and
takes a value between 0 and 3 which represent one of the four possible combinations the two LEDs
can be stated in. After the LEDs have been switched the value of the
button_counter_
is
incremented and written to the SD-Card. To verify that writing was successful, the previously written
data is read from the SD-Card and outputted to the iShell Serial Monitor . Any error is printed as well.
NOTE:
To be able to benefit from the SD-Card features without using a file system there are
several tools for the PC which allows for reading and writing from and to the SD-Card.
The simplest way to do so is to use Linux. To completely reset your card open a
Terminal window and figure out the device name of you your SD Card reader in the
/dev/
directory. Use
DiskDump (dd)
to reset your card. Type in
dd if=/dev/zero of=/dev/<SD Card reader device name>
To read all data from a SD Card use