-->
Page 1 of 1

SPI Slave mode

PostPosted: Mon Jan 26, 2015 5:50 am
by Adraen
Hi !

So I got at the end of last week on the esp bbs (http://bbs.espressif.com/viewtopic.php?f=7&t=85) some code to play with (H)SPI, I just noticed that the ~same piece of code is now part of the SDK 0.9.5 (IoT_Demo\driver\spi.c). Not sure if anyone here got the code working to use the ESP as an SPI slave if so I'm curious to have a look at the code :).

What I've done is hook up an mbed with a simple counter spitting out the value on the SPI port (as master). If I just run spi_test_init() nothing is printed out on the serial line of the ESP, however the ISR is triggered so I tried to play a bit with the code, I can see some of the data received by inspecting the SPI_W0 register by adding a print statement: However it's just a subset of the values and quite often goes wrong.

Code: Select allif(regvalue & SPI_SLV_WR_BUF_DONE) {
    uint8* data = (uint8*)SPI_W0(HSPI);
    os_printf("%d %d %d %d\n", data[0], data[1], data[2], data[3]);
}


Few things I'm wondering about, the first one being the use of the chip select line; from what I got the CS pin is GPIO15 (HSPICS) but I have to pull it low for the ESP to boot (is it used by the flash ?). Secondly, few registers are defined from SPI_W0 to SPI_W15 , however the code only uses SPI_W0 to SPI_W8 any idea why ? Are those registers multiplexed with the Flash read/write ? and finally how do you keep track of the last register used for writing the last received byte, should we just keep track of it in the code starting from 0 on boot ?

Thanks,
Simon

EDIT1: Going through the code once more I've noticed the code below, it fairly clearly stated that C8-C15 are for the slave output data
Code: Select allSET_PERI_REG_MASK(SPI_USER(spi_no),SPI_USR_MISO_HIGHPART);//SLAVE SEND DATA BUFFER IN C8-C15


EDIT2: Okay so kind of got something working, on line ~385 in spi.c after the comment I added
Code: Select allsystem_os_post(USER_TASK_PRIO_1,MOSI,regvalue);
so the task now print on the uart line the content of the array. it's progress however some data are missing, in the code below that part of the output the first column is the first value in the array and the second the last as you can see it jumps from 0x1b to 0x20.

Code: Select all0xfc 0x1b
0x20 0x3f
0x64 0x83
0x88 0xa7
0xcc 0xeb
0xf0 0x0f
0x34 0x53

Re: SPI Slave mode

PostPosted: Sat Jan 31, 2015 4:18 pm
by aep
That missing data is eaten by the 'address phase' and 'command phase'. I haven't figured out yet how to get rid of those during MISO, but if all you want is MOSI, you can disable the buffer phase and get every byte in the 'address phase' in the SPI_ADDR register.