[ESP8266] SPI as slave
[ESP8266] SPI as slave
Postby ESP_Faye » Thu Nov 05, 2015 5:11 pm
The attachment is a demo of SPI running as slave based on ESP8266_NONOS_SDK.
If using ESP8266_NONOS_SDK_V1.5.0 or later version, please add "-lcrypto" in 'LINKFLAGS_eagle.app.v6" area of the Makefile.
Documentation about SPI
附件为基于 ESP8266_NONOS_SDK 的 SPI slave 示例。
如果使用 ESP8266_NONOS_SDK_V1.5.0 或之后版本,请在示例的 Makefile 中 'LINKFLAGS_eagle.app.v6" 区域增加 "-lcrypto" 。
SPI 文档下载
Thanks for your interest in ESP8266 !
If using ESP8266_NONOS_SDK_V1.5.0 or later version, please add "-lcrypto" in 'LINKFLAGS_eagle.app.v6" area of the Makefile.
Documentation about SPI
附件为基于 ESP8266_NONOS_SDK 的 SPI slave 示例。
如果使用 ESP8266_NONOS_SDK_V1.5.0 或之后版本,请在示例的 Makefile 中 'LINKFLAGS_eagle.app.v6" 区域增加 "-lcrypto" 。
SPI 文档下载
Thanks for your interest in ESP8266 !
- Attachments
-
- SPI as slave.zip
- (41.49 KiB) Downloaded 1275 times
Re: [ESP8266] SPI as slave,
Postby foxxml » Tue Jun 07, 2016 4:14 pm
i use the code and tested the master mode(sorry, couldn't find a spi master sample)
this is what i got:

yellow line is SPI_SCLK, blue line is MOSI (i changed spi clk to 625khz)
when i zoom into the "mass" of the yellow line:
the freq is happened to match the core clk(80MHZ)
No doubt, with this clock waveform, the slave device won't work!
Lucky for me, i found this post: viewtopic.php?f=7&t=1342&p=7241&hilit=hspi+clock#p7241
I then add this line to my code:
WRITE_PERI_REG(PERIPHS_IO_MUX, 0x005);
IT WORKS!
I read out the original PERIPHS_IO_MUX register:
it is : 0x205.
however I can't find a detail description of this register, especially bit above 7.
can @Espressif_Faye give us a description about this ? does this line is necessary or have other way,do it have any side effect?
we're doing some serious RD on 8266, using unknown code is dangerous!
------------------------
this is what i got:
yellow line is SPI_SCLK, blue line is MOSI (i changed spi clk to 625khz)
when i zoom into the "mass" of the yellow line:
the freq is happened to match the core clk(80MHZ)
No doubt, with this clock waveform, the slave device won't work!
Lucky for me, i found this post: viewtopic.php?f=7&t=1342&p=7241&hilit=hspi+clock#p7241
I then add this line to my code:
WRITE_PERI_REG(PERIPHS_IO_MUX, 0x005);
IT WORKS!
I read out the original PERIPHS_IO_MUX register:
it is : 0x205.
however I can't find a detail description of this register, especially bit above 7.
can @Espressif_Faye give us a description about this ? does this line is necessary or have other way,do it have any side effect?
we're doing some serious RD on 8266, using unknown code is dangerous!
------------------------
Code: Select all
void user_init(void)
{
os_printf("SDK version:%s\n", system_get_sdk_version());
os_printf("------------------start------------------\n\r");
set_data();
spi_master_init(HSPI);
spi_mast_byte_write(HSPI,0xAA);
GPIO_OUTPUT_SET(GPIO_ID_PIN(5), 1);
//spi_byte_write_espslave(HSPI,0xAA);
//spi_WR_espslave(HSPI);
//spi_WR_espslave(HSPI);
os_printf("------------------done!------------------\n\r");
os_printf("\n\r");
os_printf("\n\r");
}
Code: Select all
void ICACHE_FLASH_ATTR
spi_master_init(uint8 spi_no)
{
uint32 regvalue;
if(spi_no>1) {
os_printf("invalid spi number!\n\r");
return;
} //handle invalid input number
else if(spi_no==SPI){
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CLK_U, 1);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_CMD_U, 1);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA0_U, 1);//configure io to spi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_SD_DATA1_U, 1);//configure io to spi mode
}else if(spi_no==HSPI){
os_printf("spi_clk HSPI %08x\r\n",READ_PERI_REG(PERIPHS_IO_MUX));
//WRITE_PERI_REG(PERIPHS_IO_MUX, 0x001);
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDI_U, 2);//configure io to Hspi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTCK_U, 2);//configure io to Hspi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTMS_U, 2);//configure io to Hspi mode
PIN_FUNC_SELECT(PERIPHS_IO_MUX_MTDO_U, 2);//configure io to Hspi mode
}
//SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_CS_SETUP|SPI_CS_HOLD);
//CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_FLASH_MODE|SPI_USR_COMMAND);
SET_PERI_REG_MASK(SPI_USER(spi_no), SPI_CS_SETUP|SPI_CS_HOLD|SPI_USR_COMMAND);
CLEAR_PERI_REG_MASK(SPI_USER(spi_no), SPI_FLASH_MODE);
WRITE_PERI_REG(SPI_CLOCK(spi_no),
((1&SPI_CLKDIV_PRE)<<SPI_CLKDIV_PRE_S)|
((63&SPI_CLKCNT_N)<<SPI_CLKCNT_N_S)|
((31&SPI_CLKCNT_H)<<SPI_CLKCNT_H_S)|
((63&SPI_CLKCNT_L)<<SPI_CLKCNT_L_S)); //clear bit 31,set SPI clock div
os_printf("spi_clk HSPI %08x\r\n",READ_PERI_REG(SPI_CLOCK(spi_no)));
//WRITE_PERI_REG(PERIPHS_IO_MUX_MTDO_U, READ_PERI_REG(PERIPHS_IO_MUX_MTDO_U) & 0x7F);
os_printf("spi_clk SPI %08x\r\n",READ_PERI_REG(SPI_CLOCK(SPI)));
os_printf("MTMO %08x\r\n", READ_PERI_REG(PERIPHS_IO_MUX_MTDO_U));
Re: [ESP8266] SPI as slave
Postby ayurvedam » Fri Jan 20, 2017 6:50 pm
. I really like reading through ideally I'm able to tell various other readers.keep for sharing this type of information.thank you so much.I would really like to visit your website.
Re: [ESP8266] SPI as slave
Postby ritesh » Sat Feb 18, 2017 1:36 am
ESP_Faye wrote:The attachment is a demo of SPI running as slave based on ESP8266_NONOS_SDK.
If using ESP8266_NONOS_SDK_V1.5.0 or later version, please add "-lcrypto" in 'LINKFLAGS_eagle.app.v6" area of the Makefile.
Documentation about SPI
附件为基于 ESP8266_NONOS_SDK 的 SPI slave 示例。
如果使用 ESP8266_NONOS_SDK_V1.5.0 或之后版本,请在示例的 Makefile 中 'LINKFLAGS_eagle.app.v6" 区域增加 "-lcrypto" 。
SPI 文档下载
Thanks for your interest in ESP8266 !
Hi,
I have one requirement in which ESP32 becomes as SPI Slave device for some communication with Master SPI device.
Also, We have e already started Development using ESP8266 RTOS SDK and I have checked in driver folder that Espressif Systems has not released SPI driver officially for RTOS SDK.
So, do you have any idea or sample SPI Slave driver with sample code? Does NONOS SPI driver can be ported and used into RTOS SDK?
Let me know for this ASAP as we have quick requirement for this for our project.
Regards,
Ritesh Prajapati
Regards,
Ritesh Prajapati
Ritesh Prajapati
ESP8266 SPI as slave
Postby RiliyVax » Wed May 03, 2017 12:58 pm
Chould you help me to make SPI comunication betwn 2 orduinoes to monitor value of ACD on Slave... please thank U...
this is my code but its not succes ...
MASTER:
void initSPI_Master
DDRB = 1<<21<<31<<5; // SCK, MOSI dan SS menjadi output
DDRB &= 1<<4; // MISO menjadi input
SPCR = 1<<MSTR; // SPI sebagai master
SPCR = 1<<SPR01<<SPR1; // Pembagi clock = 128
SPCR = 1<<SPE; // Aktifkan SPI
void setup
initSPI_Master;
Serial.begin9600;
pinMode2, INPUT;pinMode3, INPUT; pinMode4, INPUT;
digitalWrite2,HIGH;digitalWrite3, HIGH; digitalWrite4, HIGH;
void loop
//char adc = StringanalogRead0, DEC;
int adc=analogReadA0;
ifdigitalRead2==LOW
kirimData5;
else ifdigitalRead3==LOW
kirimData10;
else ifdigitalRead4==LOW
kirimDataadc;
Serial.printadc;
void kirimDatachar data
SPDR = data; // Kirim data
whileSPSR & 1<<SPIF; // Tunggu sampai pengiriman
delay500;
SLAVE:
unsigned char data;
void initSPI_Slave
DDRB &= 1<<21<<31<<5; // SCK, MOSI dan SS menjadi input
DDRB = 1<<4; // MISO menjadi output
SPCR &= 1<<MSTR; // SPI sebagai slave
SPCR = 1<<SPR01<<SPR1; // Pembagi clock = 128
SPCR = 1<<SPE; // Aktifkan SPI
void setup
initSPI_Slave;
Serial.begin9600;
void loop
whileSPSR & 1<<SPIF; // Tunggu data masuk
data = SPDR;
// Menyimpan isi register SPDR ke variabel data
Serial.println"Data Receive ==> ";
Serial.printlndata,HEX;
delay1000;
<a href=http://sale-discounts.com/>купоны акции</a>
this is my code but its not succes ...
MASTER:
void initSPI_Master
DDRB = 1<<21<<31<<5; // SCK, MOSI dan SS menjadi output
DDRB &= 1<<4; // MISO menjadi input
SPCR = 1<<MSTR; // SPI sebagai master
SPCR = 1<<SPR01<<SPR1; // Pembagi clock = 128
SPCR = 1<<SPE; // Aktifkan SPI
void setup
initSPI_Master;
Serial.begin9600;
pinMode2, INPUT;pinMode3, INPUT; pinMode4, INPUT;
digitalWrite2,HIGH;digitalWrite3, HIGH; digitalWrite4, HIGH;
void loop
//char adc = StringanalogRead0, DEC;
int adc=analogReadA0;
ifdigitalRead2==LOW
kirimData5;
else ifdigitalRead3==LOW
kirimData10;
else ifdigitalRead4==LOW
kirimDataadc;
Serial.printadc;
void kirimDatachar data
SPDR = data; // Kirim data
whileSPSR & 1<<SPIF; // Tunggu sampai pengiriman
delay500;
SLAVE:
unsigned char data;
void initSPI_Slave
DDRB &= 1<<21<<31<<5; // SCK, MOSI dan SS menjadi input
DDRB = 1<<4; // MISO menjadi output
SPCR &= 1<<MSTR; // SPI sebagai slave
SPCR = 1<<SPR01<<SPR1; // Pembagi clock = 128
SPCR = 1<<SPE; // Aktifkan SPI
void setup
initSPI_Slave;
Serial.begin9600;
void loop
whileSPSR & 1<<SPIF; // Tunggu data masuk
data = SPDR;
// Menyimpan isi register SPDR ke variabel data
Serial.println"Data Receive ==> ";
Serial.printlndata,HEX;
delay1000;
<a href=http://sale-discounts.com/>купоны акции</a>
Who is online
Users browsing this forum: No registered users and 1 guest
Login
Newbies Start Here
Are you new to ESP8266?
Unsure what to do?
Dunno where to start?
Start right here!
Latest SDK
Documentation
Complete listing of the official ESP8266 related documentation release by ESPRESSIF!
Must read here!
- All times are UTC+08:00
- Top
- Delete all board cookies
About Us
Espressif Systems is a fabless semiconductor company providing cutting-edge low power WiFi SoCs and wireless solutions for wireless communications and Internet of Things applications. We are the manufacturer of ESP8266EX.