-->
Page 1 of 1

no data coming out from SPI MOSI line

PostPosted: Thu Dec 10, 2015 10:44 am
by menuzzu
Hi folks, I'm trying to interface a nodemcu board (v1) with several SPI slave devices using SDK 1.4 and MetalPhreak's SPI driver (https://github.com/MetalPhreak/ESP8266_SPI_Driver).
I originally tried making the board talking to an RC522 NFC reader but in order to debug I'm decided to use something simpler, specifically an arduino running as SPI slave using the arduino code provided here http://www.gammon.com.au/forum/?id=10892&reply=1.

My problem is that I cannot see anything coming out from MOSI line, so I was wondering if someone has experienced the same issue or perhaps has some suggestion.

My connection looks like this:
CS: GPIO15 (nodemcu D8) -> PIN10 (arduino)
CLK: GPIO14 (nodemcu D5) -> PIN13 (arduino)
MOSI: GPIO13 (nodemcu D7) -> PIN11 (arduiono)
MISO: GPIO12 (nodemcu D6) -> PIN12 (arduino, using voltage divider)

This is how the transaction appears in the logic analyzer (zoomed out and in).
[img]spi1.png[/img]
[img]spi2.png[/img]

The code I'm testing is the following:
Code: Select all#include "ets_sys.h"
#include "osapi.h"
#include "gpio.h"
#include "os_type.h"
#include "user_interface.h"
#include "user_config.h"
#include "spi.h"

#define user_procTaskPrio        0
#define user_procTaskQueueLen    1

os_event_t    user_procTaskQueue[user_procTaskQueueLen];
static volatile os_timer_t spi_timer;

static void loop(os_event_t *events);

static void ICACHE_FLASH_ATTR  loop(os_event_t *events)
{
        os_delay_us(1000);
        // turn again
        system_os_post(user_procTaskPrio, 0, 0 );
}

static void ICACHE_FLASH_ATTR spi(void)
{
        char str[6] = {'h', 'e', 'l', 'l', 'o'};
        char *p = str;
        gpio_output_set(0, BIT15, BIT15, 0); // gpio15 low
        while (*p) {
                os_delay_us(10000);
                spi_transaction(HSPI, 0, 0, 0, 0, 8, *p++, 0, 0);
        }
        spi_transaction(HSPI, 0, 0, 0, 0, 8, '\n', 0, 0);
        gpio_output_set(BIT15, 0, BIT15, 0); // gpio15 high
}

void user_init(void)
{
        uart_div_modify(0, UART_CLK_FREQ / 115200);

        gpio_init();
        spi_init_gpio(HSPI, SPI_CLK_USE_DIV);
        spi_clock(HSPI, 4, 10); //2MHz
        spi_tx_byte_order(HSPI, SPI_BYTE_ORDER_HIGH_TO_LOW);
        spi_rx_byte_order(HSPI, SPI_BYTE_ORDER_HIGH_TO_LOW);
        SET_PERI_REG_MASK(SPI_USER(HSPI), SPI_CS_SETUP|SPI_CS_HOLD);
        CLEAR_PERI_REG_MASK(SPI_USER(HSPI), SPI_FLASH_MODE);

        PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, FUNC_GPIO15);
        gpio_output_set(BIT15, 0, BIT15, 0); // gpio15 high

        os_timer_disarm(&spi_timer);
        os_timer_setfn(&spi_timer, (os_timer_func_t *)spi, NULL);
        os_timer_arm(&spi_timer, 1000, 1);

        //Start os task
        system_os_task(loop, user_procTaskPrio,user_procTaskQueue,
                       user_procTaskQueueLen);
        system_os_post(user_procTaskPrio, 0, 0 );
}


Thanks for any eventual advice!