Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 6824

General • SPI baremetal

$
0
0
Has anyone got baremetal code for the SPI on the Pico?

I am bit bashing using this code and it works fine out to LCD screen but .... slowwwwww

Code:

#define SPI_DELAY 10static void write_data (uint8_t data){    PUT32(SIO_GPIO_OUT_CLR, 1<<17);             // Take CS low    PUT32(SIO_GPIO_OUT_SET, 1<<16);        // Take DC high    for (int i = 0; i < 8; i++)    {        PUT32(SIO_GPIO_OUT_CLR, 1<<18);// Take clk down    if ((data & 0x80) == 0x80)             PUT32(SIO_GPIO_OUT_SET, 1<<19);    else PUT32(SIO_GPIO_OUT_CLR, 1<<19); // Output bit 8        __delay_us(SPI_DELAY);        PUT32(SIO_GPIO_OUT_SET, 1<<18);// Take clk up        __delay_us(SPI_DELAY);data = data << 1;    }    __delay_us(SPI_DELAY);    PUT32(SIO_GPIO_OUT_SET, 1<<17);             // Take CS high    PUT32(SIO_GPIO_OUT_SET, 1<<16);        // Take DC high}static void write_command (uint8_t data){    PUT32(SIO_GPIO_OUT_CLR, 1<<17);             // Take CS low    PUT32(SIO_GPIO_OUT_CLR, 1<<16);             // Take DC Low    for (int i = 0; i < 8; i++)    {        PUT32(SIO_GPIO_OUT_CLR, 1<<18);// Take clk down    if ((data & 0x80) == 0x80)             PUT32(SIO_GPIO_OUT_SET, 1<<19);    else PUT32(SIO_GPIO_OUT_CLR, 1<<19); // Output bit 8        __delay_us(SPI_DELAY);        PUT32(SIO_GPIO_OUT_SET, 1<<18);// Take clk up        __delay_us(SPI_DELAY);data = data << 1;    }    __delay_us(SPI_DELAY);    PUT32(SIO_GPIO_OUT_SET, 1<<17);             // Take CS high    PUT32(SIO_GPIO_OUT_SET, 1<<16);        // Take DC high}
Image
https://filebin.net/zo0evql62fukbune/20 ... 111849.jpg

Statistics: Posted by LdB — Fri Oct 24, 2025 3:35 am — Replies 2 — Views 35



Viewing all articles
Browse latest Browse all 6824

Trending Articles