1

I am using the pigpio C interface to drive an OLED, and cannot send transfers of over 128 bytes using the spi_write command. Apart from this spi_write works, as well as all other GPIO pin use for D/C and RES flags.

I can confirm this is not a hardware or OLED issue as I have a logic analyzer hooked up and increasing the transfer amount over 128 bytes results in nothing being sent, so it is likely a PIGPIO / SPIDEV / RPi issue.

Initialisation of the pigpio daemon:

initNewGPIO = pigpio_start(NULL, NULL); // Initialise pigpio

Opening SPI interface:

portNewWrite = spi_open(initNewGPIO, 0, 1000000, 0); // Channel, Baud, Flags

Regular call of the spi_write function (preceded by setting D/C flag and filling buffer with desired data):

spi_write(initNewGPIO, portNewWrite, data, count); // where data[] is a char* array of 8192 bytes, and count is a sizeof(data)

The previous initialisation and calls have no output on the SPI lines at all when sending more than 128 bytes at a time. The initialisation happens, followed by no activity on the MOSI line. Sending 128 bytes outputs normally:

WORKS CORRECTLY

spi_write(initNewGPIO, portNewWrite, data, 128); // data[] is a char* array of 128 bytes

NO SPI OUTPUT

spi_write(initNewGPIO, portNewWrite, data, 8192); // data[] is a char* array of 8192 bytes

(Logic Analyzer output)

I am relatively new to pigpio and spi-dev and would appreciate any troubleshooting tips to be able to better understand what's going on here. Is this an issue with my baud rate, or the SPI mode that I am using?

Please let me know if I should provide additional information to make the issue more clear.

Thanks, H

EDIT 1: A more complete code example for context, showing the SPI write function which is used to send the framebuffer to the display.

// We're using Braodcom pin numbers
unsigned int BUSY = 24;
unsigned int RESET = 25;

char *fb = (char *) calloc(8192, sizeof(char));

int status, portRead, initGPIO;

void fillBuffer()
{
    for (int n = 0; n < sizeof(fb); n++){
      fb[n] = 0xF;
    }
}

void initPort() 
{
    initGPIO = pigpio_start(NULL, NULL); // Initialise pigpio
    if (initGPIO < 0) 
    {
        printf("Failed to initialise GPIO for OLED... [pigpio]\n");
        printf("PIGPIO error code: %d\n", initGPIO);
    } 
    else
    { 
        printf("Initialised GPIO for OLED [pigpio]\n");
    }

    set_mode(initGPIO, RESET, PI_OUTPUT); // SET 25 (RESET) to input
    gpio_write(initGPIO, RESET, 1); // Raise RESET

    portRead = spi_open(initGPIO, 0, 1000000, 0); // Channel, Baud, Flags
    
}

void writePort(char data[], uint8_t count) 
{
    status = spi_write(initGPIO, portRead, data, count);

    if (status != count) 
    {
        printf("Status: %d", status); // print simultaneous SPI transfer result
    }
}

int main(void)
{
    initPort();
    fillBuffer();
    writePort(fb, sizeof(fb));

    return 0;
}
2
  • Could you add a small but complete program which can be run to show the problem?
    – joan
    Commented Nov 29, 2022 at 13:45
  • Sorry about the delay, I have added a simplified version of my code to the post.
    – hal
    Commented Nov 30, 2022 at 11:01

1 Answer 1

0

The code does not compile.

In future please provide a complete example with build instructions.

One problem, perhaps the problem, is the count is constrained to fit in a uint8_t (maximum 255). Perhaps change that to a uint.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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