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

General • Unable to transmit data from SPI0 on rp2040 (pico).

$
0
0
I am trying to get SPI to work on bare metal without the SDK. I have gotten it to seemingly be able to read (if i tie RX high i can receive 0xFF), but when sending, i can see it if i enable internal loopback, but nothing ever makes it out of the pin. It is set to output, its configured for function 1 (SPI), the peripheral clock is set to 12MHz, and the divider on the spi clock is 32 so its ~375KHz. Here is my initialization and writing/reading code.

Code:

void spi_init(void) {    SPI0_SSPCR1 |= (1 << 0);    SPI0_SSPCR0 = (0x7 << 0); //set data size to 8bit    //frame format is motorola SPI by default    //assume SPI mode 0    //SPI0_SSPCR0 &= ~((1 << 6) | (1 << 7)); //SPO = 0, SPH = 0    SPI0_SSCPSR = 32;    //we will want to change this afterwards to 2 to get a 6mhz clock    //device is master by default    //SPI0_SSPCR1 &= ~(1 << 2);    //SPI0_SSPDR = 0xFFFF; //prime    SPI0_SSPCR1 |= (1 << 1); //enable SSP    //SOD is only relevant in slave mode        //setup pins    IO_BANK0_GPIO04_CTRL = 1; //function 1 SPI MISO    IO_BANK0_GPIO05_CTRL = 1; //CS    IO_BANK0_GPIO06_CTRL = 1; //SCK    IO_BANK0_GPIO07_CTRL = 1; //MOSI    //set direction for pins 6 and 7    SIO_GPIO_OE_SET = (1 << 6);    SIO_GPIO_OE_SET = (1 << 7);    PADS_BANK0_GPIO06 = 0; //disable input and drive strenght, output disable is 0 by default    PADS_BANK0_GPIO07 = 0;    }

Code:

void spi_rw_blocking(char *data, unsigned int len) {    unsigned int i;    char str[3];    for (i = 0; i < len; i++) {        while (!(SPI0_SSPSR & (1 << 1))); //wait untill FIFO is not full        SPI0_SSPDR = 0xFFFF;        while (SPI0_SSPSR & (1 << 4)); //wait untill its not busy        while (!(SPI0_SSPSR & (1 << 2))) {} //if receive FIFO is not empty            data[i] = SPI0_SSPDR;    }}

Statistics: Posted by VaporGame — Tue Jul 01, 2025 7:26 pm — Replies 0 — Views 22



Viewing all articles
Browse latest Browse all 7523

Trending Articles