-->
Page 14 of 16

Re: SPI Slave with Arduino libs ?

PostPosted: Wed Jan 18, 2017 2:54 am
by JohanS
Vicne wrote:The first issue I had was that when booting the ESP with the generator already running, the SS (SPIO15) is high, causing the ESP to boot in a wrong mode. For the time being, I solved this by connecting the SS only after the ESP has booted. I'll make that automatic later on.


My use case is having the esp listen in on an existing SPI interface, acting as a slave in disguise. So i only want to read. I have the SPISlave example (https://github.com/esp8266/Arduino/tree/master/libraries/SPISlave) working part from the GPIO15 / SS pin issue. Any solution for this boot time / changing pin functionality? Can we use another GPIO as SS, or how do you guys manage?

    I only listen on the SPI as a slave, i never send.
    I need the solution to be Esp.Deepsleep() safe, since i'm gonna wake up every hour and get a reading, then sleep again.
    I really like the SPISlave approach, and rather use that than bit banging my own solution.

I've been trying to get a solution from http://www.forward.com.au/pfod/ESP8266/GPIOpins/index.html, where they show for the ESP01 how to reuse GPIO 0 & 2 after boot time, but i can't figure out how to do it for GPIO 15. I've also found solutions using a NPN and a PNP transistor to manage this, but my electrical know-how is not enough to design that by myself.

Also, if there is a bit-banging solution for *reading*, can anyone point me in a direction to a implementation?

I'm just hoping someone else have solved the issue.

Thanks,
/Johan

Re: SPI Slave with Arduino libs ?

PostPosted: Wed Jan 18, 2017 3:07 pm
by Vicne
Hi,
Any solution for this boot time / changing pin functionality? Can we use another GPIO as SS, or how do you guys manage?


For this aspect, I solved the problem externally by using one GPIO (I chose GPIO5) as a "SS enable" signal, so I can "toggle" the SS signal on and off programmatically.
The schema I used is as follows :

2017-01-18_2040.png

By default, like all GPIO's, GPIO5 it is configured as input upon boot (high impedance, so it has no effect), so the 10k resistor keeps GPIO15 to GND.

But in setup, I put this code:
Code: Select allpinMode(5, OUTPUT);
digitalWrite(5, HIGH);

(edited) When the PNP transistor has a high level on its base (original SS signal), it is blocking. R1 and R3 create a 1:10 voltage divider which pulls GPIO15 high. When the transistor has a low level on its base, it lets current flow, which short-cuts the 10k resistor and pulls GPIO15 low.
(end edited)
So basically, when SS_EN (GPIO5) is high, the transistor is just a pass-through buffer, while when SS_EN is low or not asserted, the GPIO is tied to GND and the ESP can boot as desired.

Hope it helps.

Kind regards,

Vicne

PS: as for
Also, if there is a bit-banging solution for *reading*, can anyone point me in a direction to a implementation?

I think "bitbanging" always means generating a signal "by hand" using simple pin toggling. This approach obviously only works for output.
The opposite (handling an input signal "by hand") would be either to poll (bad) the input signal or to configure an interrupt (not so bad) to trigger upon a change of input signal. In this case, that signal should be the clock I guess, and the interrupt handler should read the SS, MOSI and MISO and rebuild the messages bit by bit. That approach can work in theory, but only with a very slow clock - not possible in my case. KR. Vicne

Re: SPI Slave with Arduino libs ?

PostPosted: Wed Jan 18, 2017 4:03 pm
by JohanS
Thanks for the quick reply!

Re: SPI Slave with Arduino libs ?

PostPosted: Thu Feb 23, 2017 12:49 am
by supriono
i want to cek data SPI from device like this (esp is slave)
Image

how to print uint8_t * data (biner) to scope
Code: Select all
    SPISlave.onData([](uint8_t * data, size_t len) {
        Serial.println(data,BIN);
    }
    );

i have this error

exit status 1
call of overloaded 'println(uint8_t*&, int)' is ambiguous