Skip to content

Clock line of SPIF is dipping when you use manual chip select and you mounted an SD #226

Open
@lefebvresam

Description

@lefebvresam

When you mount/unmount an SD with following config:

"sd.SPI_CS": "SD_CS",
"sd.SPI_MOSI": "SD_MOSI",
"sd.SPI_MISO": "SD_MISO",
"sd.SPI_CLK": "SD_CLK",
"sd.TRX_FREQUENCY": 40000000,
/**** SD card pins ****/ //SPI2
SD_MOSI = PB_15,
SD_MISO = PB_14,
SD_CLK = PB_13,
SD_CS = PB_12,
SDBlockDevice sd;
FATFileSystem fs("fs");
fs.mount(&sd);
fs.unmount();

And you use SPIF with this config:

"spif-driver.SPI_CS": "SPIF_CS",
"spif-driver.SPI_MOSI": "SPIF_MOSI",
"spif-driver.SPI_MISO": "SPIF_MISO",
"spif-driver.SPI_CLK": "SPIF_CLK",            
"spif-driver.SPI_FREQ": 40000000   
/**** SPIF pins ****/ //SPI3
SPIF_MOSI = PC_12,
SPIF_MISO = PC_11,
SPIF_CLK = PC_10,
SPIF_CS = PA_15_ALT0,

And you use legacy code which is not using HW chipselect:

_select(true); // set CS 0
_spiwrite(0x80);            // RS:1 (Cmd/Status), RW:0 (Write)
_spiwrite(command);
if (data <= 0xFF) {   // only if in the valid range
    _spiwrite(0x00);
    _spiwrite(data);
}
_select(false); // set CS 1

During the first SPI cycle there is a unwanted dip in the clock which misconfigures the slave device. This has as result that all the following data that you want to read will be read as zero.

New15

If you remove the lines:

//  fs.mount(&sd);
//  fs.unmount();

Then you have a correct start cycle and the SPI slave is readout correctly:

New16

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDis is broken

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions