Your new topic does not fit any of the above??? Check first. Then post here. Thanks.

Moderator: igrr

User avatar
By frischevollmilch
#42022 Hello,

I have to connect a TLC5947 with SPI and can't quite get it to work right on the ESP8266. My first attempt was bit banging which works fine at low frequencies but as soon as it gets a little too high the ESP8266 crashes. I think that's because the loop doesn't give its internals enough time for all the other stuff it has to do. Here is the bit banging code:

Code: Select allvoid init() {
   system_timer_reinit();
   os_timer_setfn(&myTimer, timer_callback, NULL);
   ets_timer_arm_new(&myTimer, 25, true, 0);
   pinMode(LATCH_WIRE, OUTPUT);
   pinMode(DATA_WIRE, OUTPUT);
   pinMode(CLOCK_WIRE, OUTPUT);
}

void timer_callback(void *pArg)
{
   // some data calculations...
   uint8_t data = ...;

   digitalWrite(LATCH_WIRE, 1);

   // send bits 7..0
   for (uint8_t i = 0; i < 8; i++)
   {
      // consider leftmost bit
      // set line high if bit is 1, low if bit is 0
      if (data & 0b10000000)
         digitalWrite(DATA_WIRE, 1);
      else
         digitalWrite(DATA_WIRE, 0);
      
      // pulse clock to indicate that bit value should be read
      digitalWrite(CLOCK_WIRE, 0);
      digitalWrite(CLOCK_WIRE, 1);

      // shift byte left so next bit will be leftmost
      data <<= 1;
   }

   digitalWrite(LATCH_WIRE, 0);
}


Then I tried this example from espressif: http://bbs.espressif.com/viewtopic.php?t=85
everything compiles fine but the LEDs don't light up the way I expect them to so there must be some error while transmitting the data. Here is the relevant part of the code I am running:

Code: Select allvoid init() {
   system_timer_reinit();
   os_timer_setfn(&myTimer, timer_callback, NULL);
   ets_timer_arm_new(&myTimer, 25, true, 0);
   spi_master_init(HSPI);
   pinMode(LATCH_WIRE, OUTPUT);
}

void timer_callback(void *pArg)
{
   // some data calculations...
   uint8_t data = ...;

   digitalWrite(LATCH_WIRE, 1);
   spi_mast_byte_write(HSPI, data);
   digitalWrite(LATCH_WIRE, 0);
}


spi_mast_byte_write should transmit one byte (data) with HSPI but it just doesn't seem to do so. I defined the pins for both bit banging and HSPI like this:

Code: Select all#define LATCH_WIRE 12
#define DATA_WIRE 13
#define CLOCK_WIRE 14


Can you help me there and find my mistake? Maybe I should use something else for handling SPI? I have been researching for days now and couldn't find a way to make it work without crashing the ESP8266. Thanks in advance!
User avatar
By bbx10node
#42073 The Arduino ESP8266 IDE includes a built-in SPI library which uses hardware SPI. The API is identical to the Arduino SPI library.

The following display library was modified to work on the ESP8266. See SPI.* function calls.

https://github.com/bbx10/Adafruit-PCD85 ... ee/esp8266