Post topics, source code that relate to the Arduino Platform

User avatar
By ficeto
#9682 Hello yall!
What follows is my take on ESP8266's non-wifi portion. There is little documented and for a guy coming from AVR, the register manipulations looked really unreadable... Anyway :) I managed to put together a C library that has all things necessary to get UART0RX/TX, UART1TX, HSPI Master, HSPI Slave, I2C Master, analogRead, digitalRead/Write, pinMode, attachInterrupt and more with the all familiar APIs for us.
Tings you need to pay attention to:
    GPIOs from 6 to 11 are used for the flash chip so do not touch those! I have left out the SPI APIs (register definitions are there), but have not protected any of the pin modification functions to prevent you from halting the chip all together.
    GPIO16 does not have pullup (but is the only one with pulldown) and can not be an interrupt source.
    TOUT (A0) is 10 bit analog input with range of 1.023 volts (as far as I have measured)
    GPIO15 needs to be pulled down so you can boot and because of that there is an issue with SPI slave implementation if you want to have more than one slave on the same data lines, but having just the ESP will save you from needing a SS line on the Master side
    There is no PWM(analogWrite) implementation but there is a very good one for the available timer, so you can make your own software PWM/Servo control
    Since it's all C and not C++, Stream and Print are nowhere to be found. I have provided a few simple functions to cover the basics, but I'm sure a better implementation can be done.

Things you should be happy about:
    Well... you can do just about anything with a model that has all pins
    Almost no changes are needed to convert most Arduino libraries for ESP8266
    SPI Slave has no issues at 8MHz (should not be any above either) so full speed AVR communication is here
    SPI Master has speeds to up to 80MHz (tested successfully to 20 MHz for lack of hardware that supports higher)
    I2C Master is all software implemented and is really neatly tuned to work at 100,200,300,370 and 450 KHz (tested)
    90% of the registers and bits I have found are put in a new file, have new shorter names and are accessed like on an AVR
    You can use GPIO2 to have just a debug console and hook up a GPS to the UART0 or spare a pin if you will not receive data from the UART.
    An example is provided that is actually my working copy so it has it all in there (commented things work also)

More things to note:
SPI Master does not have a mode where you read and write at the same time... wait! I just got an idea! will check it later
So what I have done instead is when you hspi_transfer(0) you are actually reading and when you are transferring a byte that is not 0, you are writing to the bus.
SPI Slave is another interesting thing... there are 4 commands that you can execute from the AVR/other-type side.
    Read Status: 1-4 bytes status register that can be used for communicating small pieces of data, like bytes available/wifi status, etc
    Write Status: same 1-4 bytes as above but in the other direction. Can be used to relate register changes/pin changes/etc
    Read Buffer: The master can read 32 bytes from a pre filled buffer (can use the status commands to communicate the total amount for example)
    Write Buffer: Send 32 bytes at a time to the Slave (same option for the status)

I hope to have a I2C Slave implementation done as well to complete the options for inter-mcu communication.
Enough said :) source is on https://github.com/ficeto/espino
User avatar
By jimD
#13149 Hi I'd like to learn more about the SPI slave interface. The UART is really slow and not really living up to the potential of wifi.

What pins do you use for spi slave?
Can you access the same AT interface as UART?
What data speeds are you getting?

Thanks