Hi,
I’m trying to communication between spi0 bus as a master and spi1 bus as a slave :
i need to send data from core0 to core1 by using spi bus ,
core0 have a spi0 as a master bus and core1 have a spi1 as a slave bus.
i'm using RP2040 .
this my MacrosThis my code for core1:I have no idea why he doesn't give me results.
can someone explain this issue?
I’m trying to communication between spi0 bus as a master and spi1 bus as a slave :
i need to send data from core0 to core1 by using spi bus ,
core0 have a spi0 as a master bus and core1 have a spi1 as a slave bus.
i'm using RP2040 .
this my Macros
This my code for core0:#define BAUDRATE (1000*1000)
#define BUF_LEN 0x100
// GPIO Pins for SPI0
#define PICO_SPI0_SCK0_PIN 2
#define PICO_SPI0_TX0_PIN 3
#define PICO_SPI0_RX0_PIN 4
#define PICO_SPI0_CSN0_PIN 5
// GPIO Pins for SPI1
#define PICO_SPI1_SCK1_PIN 10
#define PICO_SPI1_TX1_PIN 11
#define PICO_SPI1_RX1_PIN 12
#define PICO_SPI1_CSN1_PIN 13
Code:
int main(){ stdio_init_all(); uint8_t out_buf = 1 ; multicore_reset_core1(); //initalise core1 multicore_launch_core1(spi_slave); //start core1 //Master SPI0 //make GPIO work as SPI0 spi_init(spi0 , BAUDRATE); //initalise spi0 gpio_set_function(PICO_SPI0_RX0_PIN, GPIO_FUNC_SPI); //make gpio work as spi-rx gpio_set_function(PICO_SPI0_TX0_PIN, GPIO_FUNC_SPI); //make gpio work as spi-clk gpio_set_function(PICO_SPI0_SCK0_PIN, GPIO_FUNC_SPI); //make gpio work as spi-tx gpio_set_function(PICO_SPI0_CSN0_PIN, GPIO_FUNC_SPI); //make gpio work as spi-cs // Make the SPI pins available to picotool bi_decl(bi_4pins_with_func(PICO_SPI0_RX0_PIN, PICO_SPI0_TX0_PIN, PICO_SPI0_SCK0_PIN, PICO_SPI0_CSN0_PIN,GPIO_FUNC_SPI )); while (true) { spi_write_blocking(spi0, &out_buf,BUF_LEN); printf("Data sent from core 0 = %u\n", out_buf); out_buf++; sleep_ms(10000); }}
Code:
void spi_slave(){ uint8_t in_buf , read ; //Slave SPI1 spi_init(spi1 , BAUDRATE); //initalise spi1 spi_set_slave(spi1 , true); //make spi1 a slave //make GPIO work as SPI1 gpio_set_function(PICO_SPI1_RX1_PIN, GPIO_FUNC_SPI); gpio_set_function(PICO_SPI1_SCK1_PIN, GPIO_FUNC_SPI); gpio_set_function(PICO_SPI1_TX1_PIN, GPIO_FUNC_SPI); gpio_set_function(PICO_SPI1_CSN1_PIN, GPIO_FUNC_SPI); while (true) { read = spi_read_blocking(spi1, 1, &in_buf, BUF_LEN); printf("Data come from core 0 = %u\n", read); printf("===============================================\n"); }}
can someone explain this issue?
Statistics: Posted by T_king — Tue Nov 26, 2024 10:58 am