0

I've been trying to change the TLC5940NT library for Arduino that can be found here https://sites.google.com/site/artcfox/demystifying-the-tlc5940 so that I can use it on Raspberry Pi, but I keep getting the error

   wiringPiSetup: mmap (PADS) failed: Cannot allocate memory

I am not sure what I am doing wrong, and I would very much appreciate your help :)

Here is my code:

#include <wiringPi.h>
#include <errno.h>
#include<stdint.h>
#define GSCLK_PIN       0

#define SIN_PIN         1

#define SCLK_PIN        3

#define BLANK_PIN       4 

#define DCPRG_PIN       5
//#define DC

#define VPRG_PIN        6

#define XLAT_PIN        7
#define TLC594          1



void pulse(pin) {
        wiringPiSetup();
        pinMode(pin, OUTPUT);
        digitalWrite(pin, LOW);
        digitalWrite(pin, HIGH);
                }
//#define outputState(port, pin) ((port) & (1 << (pin)))

/*uint8_t dcData[96 * TLC594] = {
// MSB            LSB
        1, 1, 1, 1, 1, 1,                       // Channel 15
        1, 1, 1, 1, 1, 1,                       // Channel 14
        1, 1, 1, 1, 1, 1,                       // Channel 13
        1, 1, 1, 1, 1, 1,                       // Channel 12
        1, 1, 1, 1, 1, 1,                       // Channel 11
        1, 1, 1, 1, 1, 1,                       // Channel 10
        1, 1, 1, 1, 1, 1,                       // Channel 9
        1, 1, 1, 1, 1, 1,                       // Channel 8
        1, 1, 1, 1, 1, 1,                       // Channel 7
        1, 1, 1, 1, 1, 1,                       // Channel 6
        1, 1, 1, 1, 1, 1,                       // Channel 5
        1, 1, 1, 1, 1, 1,                       // Channel 4
        1, 1, 1, 1, 1, 1,                       // Channel 3
        1, 1, 1, 1, 1, 1,                       // Channel 2
        1, 1, 1, 1, 1, 1,                       // Channel 1
        1, 1, 1, 1, 1, 1,                       // Channel 0
}; */

uint8_t gsData[192 * TLC594] = {
// MSB                              LSB
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,             // Channel 15
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                     // Channel 14
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                     // Channel 13
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,                     // Channel 12
        0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0,                     // Channel 11
        0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0,                     // Channel 10
        0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0,                     // Channel 9
        0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0,                     // Channel 8
        0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0,                     // Channel 7
        0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0,                     // Channel 6
        0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,                     // Channel 5
        0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0,                     // Channel 5
        0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0,                     // Channel 4
        0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0,                     // Channel 3
        0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                     // Channel 2
        1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,                     // Channel 1
        1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,                     // Channel 0
};

void TLC5940_Init(void) {
        wiringPiSetup();
        pinMode(GSCLK_PIN, OUTPUT);
        pinMode(SCLK_PIN, OUTPUT);
        pinMode(DCPRG_PIN, OUTPUT);
        pinMode(VPRG_PIN, OUTPUT);
        pinMode(XLAT_PIN, OUTPUT);
        pinMode(BLANK_PIN, OUTPUT);
        pinMode(SIN_PIN, OUTPUT);

        digitalWrite(GSCLK_PIN, LOW);
        digitalWrite(SCLK_PIN, LOW);
        digitalWrite(DCPRG_PIN, LOW);
        digitalWrite(VPRG_PIN, LOW);
        digitalWrite(XLAT_PIN, LOW);
        digitalWrite(BLANK_PIN, LOW);
}

/*void TLC5940_ClockInDC(void) {
        wiringPiSetup();
        digitalWrite(DCPRG_PIN, HIGH);
        digitalWrite(VPRG_PIN, HIGH);

        uint8_t Counter = 0;
        uint8_t Counter = 0;

        for (;;) {
                if (Counter > TLC594 * 96 - 1) {
                        pulse(XLAT_PIN);
                        break;
                } else {
                        if (dcData[Counter])
                                digitalWrite(SIN_PIN, 1);
                        else
                                digitalWrite(SIN_PIN, 0);
                        pulse(SCLK_PIN);
                        Counter++;
                }
        }
} */

void TLC5940_SetGS_And_GS_PWM(void) {
        wiringPiSetup();
        uint8_t firstCycleFlag = 0;

        if (digitalRead(VPRG_PIN)) {

                digitalWrite(VPRG_PIN, 0);
                firstCycleFlag = 1;
        }

        uint16_t GSCLK_Counter = 0;
        uint8_t Data_Counter = 0;

        digitalWrite(BLANK_PIN, 0);
        for (;;) {
                if (GSCLK_Counter > 4095) {
                        digitalWrite(BLANK_PIN, 1);
                        pulse(XLAT_PIN);
                        if (firstCycleFlag) {
                                pulse(SCLK_PIN);
                                firstCycleFlag = 0;
                        }
                        break;
                } else {
                        if (!(Data_Counter > TLC594 * 192 - 1)) {
                                if (gsData[Data_Counter]){
                                        digitalWrite(SIN_PIN, 1);
                                        else {
                                        digitalWrite(SIN_PIN, 0);
                                pulse(SCLK_PIN);
                                Data_Counter++;
                                        }
                }
}
                pulse(GSCLK_PIN);
                GSCLK_Counter++;
        }
}

int main(void) {
        TLC5940_Init();
//      TLC5940_ClockInDC();    // try it both with and without this line

        for (;;) {
                TLC5940_SetGS_And_GS_PWM();

        }
        return 0;
}
0

The wiringPi library should be initialised ONCE in your program.

Calling the initialisation function wiringPiSetup repeatedly is probably causing the problem.

  • Thank you. I am not getting the error anymore, although I can't communicate with the chip. – Mika Jan 27 '16 at 18:10
  • You will need to check that the software is using the same GPIO as the hardware. wiringPi can uses its own GPIO numbering scheme or the Broadcom GPIO numbering scheme. I'm not sure which one will be used when you initialise the library with wiringPiSetup. – joan Jan 27 '16 at 18:15
  • The wiringPiSetup uses the wiringPi numbering. This is from their website: "This initialises wiringPi and assumes that the calling program is going to be using the wiringPi pin numbering scheme. This is a simplified numbering scheme which provides a mapping from virtual pin numbers 0 through 16 to the real underlying Broadcom GPIO pin numbers. See the pins page for a table which maps the wiringPi pin number to the Broadcom GPIO pin number to the physical location on the edge connector." – Mika Jan 27 '16 at 18:18
  • Another thing to check is the pulse function. The pulse length may be less than a microsecond, will that be long enough? – joan Jan 27 '16 at 18:21
  • added a delay between low and high (10, then 100) - still no change... – Mika Jan 27 '16 at 18:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.