Arduino core for the tinyAVR 0/1/2-series - Ones's digit 2,4,5,7 (pincount, 8,14,20,24), tens digit 0, 1, or 2 (featureset), preceded by flash in kb. Library maintainers: porting help available!
Hi,
I can send data from ATtiny3216 (SPI master) to ESP8266 on ESP12F module (SPI slave).
But I do not understand why some first characters of string is bypass.
With MPLABXIDE-my coding it by pass 2 first characters.
With my Arduino coding, it by pass 7 first characters.
With Arduino example SPI coding, at first try, it can show first character, but after that, I do not understand why it by pass. Now it never give me the first character anymore.
I test with setting clock SPI DIV128, I try change internal clock ATtiny3216 from 20MHz to 1MHz, result is the same. I try to send "1234567abcdefghijklmnopqrstuvwyz12345!" It alway by pass first character, the serial print output of ESP8266 is shown below:
Question: abcdefghijklmnopqrstuvwyz12345!
Status: 892613426
Answer Sent
Question: abcdefghijklmnopqrstuvwyz12345!
Status: 892613426
Answer Sent
I connect directly 5V SPI pin to ESP-12F, because, if I connect SS pin of ESP8266 to level shifter IC TXS0108E, it can not boot, try set pin Low by ATtiny 3216 when start up, but it still not boot(I rechecked TXS0108E it still work OK when I control level of SS pin of ESP8266 3V3 by ATtiny3216 5V pin). Recheck information on Arduino forum, I directly connect SPI to ESP8266.
Now I can send data via SPI OK, but I must add some unnecessary first characters, so, I add here for more information.
Please share after check coding:
Arduino coding of ATtiny3216 - SPI master:
For SPI slave Arduino coding of ESP12F, I use example code SPISlave_Test. Just re-up here for more convenient. Please check:
/*
SPI Slave Demo Sketch
Connect the SPI Master device to the following pins on the esp8266:
GPIO NodeMCU Name | Uno
===================================
15 D8 SS | D10
13 D7 MOSI | D11
12 D6 MISO | D12
14 D5 SCK | D13
Note: If the ESP is booting at a moment when the SPI Master has the Select line HIGH (deselected)
the ESP8266 WILL FAIL to boot!
See SPISlave_SafeMaster example for possible workaround
*/
#include "SPISlave.h"
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
// data has been received from the master. Beware that len is always 32
// and the buffer is autofilled with zeroes if data is less than 32 bytes long
// It's up to the user to implement protocol for handling data length
SPISlave.onData([](uint8_t *data, size_t len) {
String message = String((char *)data);
(void)len;
if (message.equals("Hello Slave!")) {
SPISlave.setData("Hello Master!");
} else if (message.equals("Are you alive?")) {
char answer[33];
sprintf(answer, "Alive for %lu seconds!", millis() / 1000);
SPISlave.setData(answer);
} else {
SPISlave.setData("Say what?");
}
Serial.printf("Question: %s\n", (char *)data);
});
// The master has read out outgoing data buffer
// that buffer can be set with SPISlave.setData
SPISlave.onDataSent([]() {
Serial.println("Answer Sent");
});
// status has been received from the master.
// The status register is a special register that bot the slave and the master can write to and read from.
// Can be used to exchange small data or status information
SPISlave.onStatus([](uint32_t data) {
Serial.printf("Status: %u\n", data);
SPISlave.setStatus(millis()); // set next status
});
// The master has read the status register
SPISlave.onStatusSent([]() {
Serial.println("Status Sent");
});
// Setup SPI Slave registers and pins
SPISlave.begin();
// Set the status register (if the master reads it, it will read this value)
SPISlave.setStatus(millis());
// Sets the data registers. Limited to 32 bytes at a time.
// SPISlave.setData(uint8_t * data, size_t len); is also available with the same limitation
SPISlave.setData("Ask me a question!");
Serial.println("on");
}
void loop() {}
Hi, I can send data from ATtiny3216 (SPI master) to ESP8266 on ESP12F module (SPI slave). But I do not understand why some first characters of string is bypass. With MPLABXIDE-my coding it by pass 2 first characters. With my Arduino coding, it by pass 7 first characters. With Arduino example SPI coding, at first try, it can show first character, but after that, I do not understand why it by pass. Now it never give me the first character anymore. I test with setting clock SPI DIV128, I try change internal clock ATtiny3216 from 20MHz to 1MHz, result is the same. I try to send "1234567abcdefghijklmnopqrstuvwyz12345!" It alway by pass first character, the serial print output of ESP8266 is shown below:
I connect directly 5V SPI pin to ESP-12F, because, if I connect SS pin of ESP8266 to level shifter IC TXS0108E, it can not boot, try set pin Low by ATtiny 3216 when start up, but it still not boot(I rechecked TXS0108E it still work OK when I control level of SS pin of ESP8266 3V3 by ATtiny3216 5V pin). Recheck information on Arduino forum, I directly connect SPI to ESP8266. Now I can send data via SPI OK, but I must add some unnecessary first characters, so, I add here for more information. Please share after check coding: Arduino coding of ATtiny3216 - SPI master:
For SPI slave Arduino coding of ESP12F, I use example code SPISlave_Test. Just re-up here for more convenient. Please check: