Closed
Description
Basic Infos
- [ x] This issue complies with the issue POLICY doc.
- [ x] I have read the documentation at readthedocs and the issue is not addressed there.
- [x ] I have tested that the issue is present in current master branch (aka latest git).
- [x ] I have searched the issue tracker for a similar issue.
- If there is a stack dump, I have decoded it.
- [x ] I have filled out all fields below.
Platform
- Hardware: [ESP-8266-wroom2]
- Core Version: [latest git]
- Development Env: [Arduino IDE]
- Operating System: [Ubuntu]
Settings in IDE
- Module: [Generic ESP8266 Module]
- Flash Size: [2MB]
- lwip Variant: [v2 Lower Memory]
- Reset Method: [ck|nodemcu]
- Flash Frequency: [40Mhz]
- CPU Frequency: [80Mhz]
- Upload Using: [SERIAL]
- Upload Speed: [115200] (serial upload only)
Problem Description
Hi all,
We try to get the spi in slave mode working without crash and we cannot get it. We use 2 esp8266 (one in master and one in slave). We use only the read status command to simplify the setup. Here the Master code. We use the Example SPI Safe Master Demo and modify it to only use the readStatus method.
#include <SPI.h>
class ESPSafeMaster {
private:
uint8_t _ss_pin;
void _pulseSS() {
digitalWrite(_ss_pin, HIGH);
delayMicroseconds(5);
digitalWrite(_ss_pin, LOW);
}
public:
ESPSafeMaster(uint8_t pin): _ss_pin(pin) {}
void begin() {
pinMode(_ss_pin, OUTPUT);
_pulseSS();
}
uint32_t readStatus() {
_pulseSS();
SPI.transfer(0x04);
uint32_t status = (SPI.transfer(0) | ((uint32_t)(SPI.transfer(0)) << 8) | ((uint32_t)(SPI.transfer(0)) << 16) | ((uint32_t)(SPI.transfer(0)) << 24));
_pulseSS();
return status;
}
void writeStatus(uint32_t status) {
_pulseSS();
SPI.transfer(0x01);
SPI.transfer(status & 0xFF);
SPI.transfer((status >> 8) & 0xFF);
SPI.transfer((status >> 16) & 0xFF);
SPI.transfer((status >> 24) & 0xFF);
_pulseSS();
}
void readData(uint8_t * data) {
_pulseSS();
SPI.transfer(0x03);
SPI.transfer(0x00);
for (uint8_t i = 0; i < 32; i++) {
data[i] = SPI.transfer(0);
}
_pulseSS();
}
void writeData(uint8_t * data, size_t len) {
uint8_t i = 0;
_pulseSS();
SPI.transfer(0x02);
SPI.transfer(0x00);
while (len-- && i < 32) {
SPI.transfer(data[i++]);
}
while (i++ < 32) {
SPI.transfer(0);
}
_pulseSS();
}
String readData() {
char data[33];
data[32] = 0;
readData((uint8_t *)data);
return String(data);
}
void writeData(const char * data) {
writeData((uint8_t *)data, strlen(data));
}
};
ESPSafeMaster esp(SS);
void setup() {
Serial.begin(115200);
SPI.begin();
esp.begin();
delay(1000);
}
uint32_t status;
void loop() {
esp.readStatus();
}
On the slave we use this code.
#include <Arduino.h>
#include <SPISlave.h>
#include <ESP8266WiFi.h>
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
WiFi.mode(WIFI_STA);
WiFi.begin("MySSID","MyPassword");
delay(10000); //delay to not crash the ESP. If this delay is not there, the ESP will crash in sys context
SPISlave.begin();
SPISlave.setStatus(0xAA);
}
void loop() {
}
With this configuration, the data of the status is 0x55 (checked with an MSO) and as soon as the WiFi is connected, the data of the status is 0x00. No more 0x55 is returned.
Does anyone can try the same setup and give feedback ? We have been able to have a reliable communication in SPI mode.
Jonathan
Metadata
Metadata
Assignees
Labels
No labels