Contiki 2.5
Files | Macros | Functions
MicroSD Card Interface

Files

file  flash-microSD.c
 
 MicroSD Card interface implementation

 
file  flash-microSD.h
 
    MicroSD Card interface definitions

 

Macros

#define MICRO_SD_CS   5
 

Functions

uint8_t microSD_init (void)
 Powers on and initialize the microSD / SD-Card. More...
 
uint8_t microSD_read_block (uint32_t addr, uint8_t *buffer)
 This function will read one block (512Byte) of the SD-Card. More...
 
uint8_t microSD_write_block (uint32_t addr, uint8_t *buffer)
 This function will write one block (512Byte) of the SD-Card. More...
 
uint8_t microSD_write_cmd (uint8_t *cmd)
 This function sends a command via SPI to the SD-Card. More...
 

Detailed Description

Note
This sd-card interface is based on the work of Ulrich Radig "Connect AVR to MMC/SD" and was a little bit modified plus adapted to the mspi-drv

Huge memory space is always nice to have, because you don't have to decide which data has to be stored, just store everything! Furthermore you can buffer your data, whenever wireless connection breaks down. An easy and modular way is a SD card. For smaller applications (like sensor nodes), the tiny version "microSD" would be the best choice. Both, the "big" SD-Cards and the microSD-Cards can be interfaced by SPI and use the same Instruction set, so this interface can be used for both SD-Card types.

Macro Definition Documentation

#define MICRO_SD_CS   5

SPI device order. The chip select number where the microSD-Card is connected to the BCD-decimal decoder

Definition at line 68 of file flash-microSD.h.

Referenced by microSD_init(), microSD_read_block(), microSD_write_block(), and microSD_write_cmd().

Function Documentation

uint8_t microSD_init ( void  )

Powers on and initialize the microSD / SD-Card.

Returns
  • 0 : SD-Card was initialized without an error
  • 1 : CMD0 failure!
  • 2 : CMD1 failure!

Definition at line 45 of file flash-microSD.c.

References MICRO_SD_CS, microSD_write_cmd(), MSPI_BAUD_MAX, mspi_chip_release(), mspi_chip_select(), mspi_init(), MSPI_MODE_0, and mspi_transceive().

uint8_t microSD_read_block ( uint32_t  addr,
uint8_t *  buffer 
)

This function will read one block (512Byte) of the SD-Card.

Parameters
addrBlock address
*bufferPointer to a block buffer
Returns
  • 0 : SD-Card block read was successful
  • 1 : CMD17 failure!

Definition at line 95 of file flash-microSD.c.

References MICRO_SD_CS, microSD_write_cmd(), mspi_chip_release(), and mspi_transceive().

uint8_t microSD_write_block ( uint32_t  addr,
uint8_t *  buffer 
)

This function will write one block (512Byte) of the SD-Card.

Parameters
addrBlock address
*bufferPointer to a block buffer
Returns
  • 0 : SD-Card block write was successful
  • 1 : CMD24 failure!

Definition at line 137 of file flash-microSD.c.

References MICRO_SD_CS, microSD_write_cmd(), mspi_chip_release(), and mspi_transceive().

uint8_t microSD_write_cmd ( uint8_t *  cmd)

This function sends a command via SPI to the SD-Card.

An SPI command consists off 6 bytes

Parameters
*cmdPointer to the command array
Returns
  • 1 : Acknowledge
  • other failure code

Definition at line 191 of file flash-microSD.c.

References MICRO_SD_CS, mspi_chip_release(), mspi_chip_select(), and mspi_transceive().

Referenced by microSD_init(), microSD_read_block(), and microSD_write_block().