Re: Multiplexing a LED matrix using ESP8266 hardware
Posted: Sun Jul 16, 2017 5:33 pm
TX only is indeed no problem, since I want to use it as output...
However, UART is HIGH on idle, which is not okay for my LED signal...
However, I now want to concentrate on the Serial Data and RCK signal first.
I want to use SPI to send the 36+1 bytes of serial data per multiplexed row and the hardware CS pin of the SPI interface (GPIO 15) as RCK signal. Since CS is active low for SPI it should give me a rising edge on RCK after serial data is transferred.
What I don't know is... How do I send the 36+1 bytes of data in a non blocking way?
By investigating the spi.cpp of the arduino library I found that I will have to write my data into the registers SPI1W0 to SPI1W15. It also looks like SPI1CMD |= SPIBUSY starts the transfer... However, only one byte gets transferred. I haven't found a register to write the fifo size into...
However, UART is HIGH on idle, which is not okay for my LED signal...
However, I now want to concentrate on the Serial Data and RCK signal first.
I want to use SPI to send the 36+1 bytes of serial data per multiplexed row and the hardware CS pin of the SPI interface (GPIO 15) as RCK signal. Since CS is active low for SPI it should give me a rising edge on RCK after serial data is transferred.
What I don't know is... How do I send the 36+1 bytes of data in a non blocking way?
By investigating the spi.cpp of the arduino library I found that I will have to write my data into the registers SPI1W0 to SPI1W15. It also looks like SPI1CMD |= SPIBUSY starts the transfer... However, only one byte gets transferred. I haven't found a register to write the fifo size into...
Code: Select all
#include <SPI.h>
void setup()
{
SPI.begin();
SPI.setHwCs(true); // Enable Select ActiveLow on D8 / IO15 / CS / HSPI_CS used for RCK
SPI.setFrequency(1e6);
pinMode(D0, OUTPUT);
}
uint8_t buf[5];
void loop()
{
digitalWrite(D0, HIGH);
//SPI.writePattern(buf, 4, 3);
spiSendNoBlock(); // non blocking SPI test
digitalWrite(D0, LOW);
delay(100);
}
void spiSendNoBlock() {
// see https://github.com/esp8266/Arduino/blob/40c159fcf5c5ecf9edec8e7ada49c82ece19e6d0/libraries/SPI/SPI.cpp#L421
uint32_t buffer[16]; // 16x32bit Buffer 4 HW FIFO
uint8_t *bufferPtr = (uint8_t *)&buffer; // 64x8bit Buffer pointer
volatile uint32_t * fifoPtr = &SPI1W0; // SPI1W0 - SPI1W15 32bit FIFO Buffer registers
for(uint8_t i=0; i<64; i++) bufferPtr[i] = i+1; // Fill buffer with dummy data 0-63
// fill FIFO with Buffer data
for (uint8_t i = 0; i<16; i++) {
*fifoPtr = buffer[i];
fifoPtr++;
}
//SPI1U = SPIUMOSI | SPIUSSE; // removes delay on CS before/after SPI Clock
SPI1CMD |= SPIBUSY; // Sends first byte from FIFO
}