Hardware SPI (HSPI) Driver Code / Library
Posted: Sat Apr 11, 2015 6:57 am
https://github.com/MetalPhreak/ESP8266_SPI_Driver
Currently supports sending data packets up to 32bits in length.
There's a few setup functions but if you just want to get cracking try the following code:
spi_init function sets it up for 4MHz clock and swaps the write byte order. What you put in is exactly what gets clocked out, regardless of the number of bits.
You can change the clock frequency by modifying the defines at the top of spi.c
SPI_CLK_CNTDIV must always be 2 or higher.
Reading in data is very similar, but I have yet to write and test the functions for it. Hopefully will be coming soon but I'm travelling interstate for a bit.
Each of the above tx commands actual output:
Currently supports sending data packets up to 32bits in length.
There's a few setup functions but if you just want to get cracking try the following code:
Code: Select all
spi_init(HSPI);
spi_tx8(HSPI, 0x7A); //send 8 bits of data
spi_tx16(HSPI, 0x7A43); //send 16 bits of data
spi_tx32(HSPI, 0xCAFEFEED); //send 32 bits of data
spi_txd(HSPI, 9, 0b101101110); //send 9 bits of data (useful for driving LCDs with 9bit commands).
spi_txd(HSPI, 28, 0x1337CAD);
spi_init function sets it up for 4MHz clock and swaps the write byte order. What you put in is exactly what gets clocked out, regardless of the number of bits.
You can change the clock frequency by modifying the defines at the top of spi.c
SPI_CLK_CNTDIV must always be 2 or higher.
Reading in data is very similar, but I have yet to write and test the functions for it. Hopefully will be coming soon but I'm travelling interstate for a bit.
Each of the above tx commands actual output: