0
\$\begingroup\$

I'm trying to interface an mcu (tm4c123) with external SPI flash memory SST25VF010A. I execute the Read-ID instruction, but instead of gettting BF and 49 (manufacturer and device ids) - I get BC and 41.

Reading the status register also gives weird results - on startup I get 0x8 and after executing the write enable instruction, I get 0xC. Looking at the datasheet and boot up values, I would expect it to be more like the opposite - 0xC on startup and perhaps 0x0 after write enable...

Here is my code:

void ConfigureSPIFlash()
{
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
    MAP_SysCtlPeripheralEnable(SYSCTL_PERIPH_SSI1);

    // Enable pin PD2 for SSI1 SSI1RX
    MAP_GPIOPinConfigure(GPIO_PD2_SSI1RX);
    MAP_GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_2);

    // Enable pin PD0 for SSI1 SSI1CLK
    MAP_GPIOPinConfigure(GPIO_PD0_SSI1CLK);
    MAP_GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_0);

    // Enable pin PD1 for Chip Enable
    MAP_GPIOPinTypeGPIOOutput(GPIO_PORTD_BASE, GPIO_PIN_1);
    MAP_GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, GPIO_PIN_1);

    // Enable pin PD3 for SSI1 SSI1TX
    MAP_GPIOPinConfigure(GPIO_PD3_SSI1TX);
    MAP_GPIOPinTypeSSI(GPIO_PORTD_BASE, GPIO_PIN_3);

    MAP_SSIConfigSetExpClk(SSI1_BASE, MAP_SysCtlClockGet(), SSI_FRF_MOTO_MODE_0, SSI_MODE_MASTER, 125000, 8);

    MAP_SSIEnable(SSI1_BASE);

    uint32_t r;
    while(SSIDataGetNonBlocking(SSI1_BASE, &r)){}
}


unsigned char SPI_transmit(unsigned char data)
{
    SSIDataPut(SSI1_BASE, data);
    uint32_t r;
    SSIDataGet(SSI1_BASE, &r);

    return (unsigned char)r;
}

void main(void)
{
    ROM_FPUEnable();
    ROM_FPULazyStackingEnable();

    SysCtlClockSet(SYSCTL_SYSDIV_4| SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ |SYSCTL_OSC_MAIN);

    ConfigureUART();

    ConfigureSPIFlash();
    UARTprintf("spi flash ready\n");

    uint8_t res;

    // send Read-ID command
    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, ~GPIO_PIN_1); // CE low
    SPI_transmit(0x90);
    SPI_transmit(0x00);
    SPI_transmit(0x00);
    SPI_transmit(0x01);

    // get response
    res = SPI_transmit(0xff);
    UARTprintf("received: 0x%x\n", res);

    GPIOPinWrite(GPIO_PORTD_BASE, GPIO_PIN_1, GPIO_PIN_1);  // CE high
}

Any idea what I'm doing wrong? Thanks!

\$\endgroup\$
  • \$\begingroup\$ My first suspect would be an incorrect SPI mode; try clocking data in on falling edges rather than rising, or vice versa. Also, get a scope or logic analyser on the signals to make sure that they're doing what you intended at the physical layer. \$\endgroup\$ – markt Nov 22 '14 at 12:14
  • \$\begingroup\$ Thanks, in the datasheet it says mode 0 and mode 3 are supported - tried both - still the same result. Other modes don't return any data. I'm also checking with an analyzer - the signals look ok to me... Could it be because I'm using an smd adapter like this: mcumall.com/support/… I'll try soldering the chip, to see if it makes any difference... \$\endgroup\$ – Lacho Tomov Nov 22 '14 at 12:29
1
\$\begingroup\$

It turns out that my cheap junky logic analyzer was putting some noise on the MISO line, so the received data gets slightly shifted. When I unplugged its MISO line - the data is now fine. Truly unbelievable...

\$\endgroup\$
  • \$\begingroup\$ What logic analyzer should we avoid? :-) \$\endgroup\$ – m.Alin Feb 22 '15 at 11:28
  • \$\begingroup\$ @m.Alin well since I'm no expert, I wouldn't like to place a blame on the company without being 100% sure it's really the LA :) Could be also the breadboard probably... But it's a very cheap analyzer, not a real/professional one, made mostly for learning purposes :) \$\endgroup\$ – Lacho Tomov Feb 23 '15 at 12:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.