Skip to content

Fix for 1.80 SD.h  #5805

Closed
arduino-libraries/SD
#29
@greiman

Description

@greiman

Using transfer(data, size) in this new function causes SD.h to fail with some cards.

void spiRec(uint8_t* data, int size) {
#ifdef USE_SPI_LIB
  SDCARD_SPI.transfer(data, size);
#else
  while (size) {
    *data++ = spiRec();
    size--;
  }
#endif
}

The problem is that transfer(data, size) sends the content of the 'data' buffer to the card and stores received bytes in the 'data' buffer.

Some SD cards may interpret the data sent over MOSI as a command. Commands start with a byte that has bit-7 low and bit-6 high. the command index is bits 0-5.

My original version sent all 0XFF bytes on MOSI to avoid this possibility.

Here is an idea for a addition to the SPI library.

It would be nice if SPI had a function like many RTOS HAL libraries with three arguments:

void transfer(const void* txbuf, void* rxbuf, size_t n);

It's like the current transfer if both txbuf and rxbuf are non-null.

If txbuf is null, 0XFF bytes are sent. If rxbuf is null, receive data is discarded.

This allows every possible option, send from one buffer and receive to another buffer, exchange data in a single buffer, send with no receive buffer, and receive with no send buffer.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions