I am trying to use lib_spi 3.0.2 with 2 peripherals. It works with only 1. Using sw usb audio v 8.1.0 on 316-mc dev board
in main.xc:
Code: Select all
/* These ports are used for the SPI master */
out buffered port:32 p_sclk = on tile[1]: XS1_PORT_1L;
out port p_ss[2] = on tile[1]: {XS1_PORT_1I, XS1_PORT_1F};
in buffered port:32 p_miso = on tile[1]: XS1_PORT_1K;
out buffered port:32 p_mosi = on tile[1]: XS1_PORT_1J;
/* Main for USB Audio Applications */
int main()
{
interface spi_master_if i_spi[2];
USER_MAIN_DECLARATIONS
par
{
USER_MAIN_CORES
on tile[1]: spi_master(i_spi, 1, p_sclk, p_mosi, p_miso, p_ss, 2, null);
on tile[1]: peripheral_1_setup(i_spi[0]);
on tile[1]: peripheral_2_setup(i_spi[1]);
...
It runs. I see the ss pin for peripheral 1 (1I) goes low and then the clock pin toggles and it works for the 1st peripheral. But the ss pin for 2nd peripheral is always high, it never toggles. Its like peripheral_2_setup() never even runs.
Inside peripheral_1_setup():
Code: Select all
//spi.begin_transaction(device_index, speed_in_khz, mode)
spi.begin_transaction(0, 100, SPI_MODE_1);
rv = spi.transfer8(buf[0]);
rv = spi.transfer8(buf[1]);
rv = spi.transfer8(buf[2]);
spi.end_transaction(100);
And inside peripheral_2_setup():
Code: Select all
//spi.begin_transaction(device_index, speed_in_khz, mode)
spi.begin_transaction(1, 100, SPI_MODE_1);
rv = spi.transfer8(buf[0]);
rv = spi.transfer8(buf[1]);
rv = spi.transfer8(buf[2]);
spi.end_transaction(100);
What am I doing wrong? If I change peripheral_1_setup() like this:
Code: Select all
//spi.begin_transaction(device_index, speed_in_khz, mode)
spi.begin_transaction(1, 100, SPI_MODE_1);
rv = spi.transfer8(buf[0]);
rv = spi.transfer8(buf[1]);
rv = spi.transfer8(buf[2]);
spi.end_transaction(100);