ErikNatanael File /sys/devices/platform/ocp/ocp😛2_8_pinmux/state could not be opened and the transfers are closed
That should be P2_08, not P2_8. If it fails it means its pinmux hasn't changed. Also, it doesn't look like P2.08 contains any SPI1 CS signals. When using a GPIO as a chip select line, you should set it to gpio
instead (which is the default anyhow). If using a GPIO, it becomes complicated to use one of Bela's 16 digital I/O as they are handled in the audio thread and cannot be used in the same thread as the SPI transaction. For that you'd need to use "synchronous" GPIOs (probably a bad name, see here and here. I was going to suggest something like this:. Do config-pin P2.31 gpio
- instead of spi_cs
; now you can address the corresponding GPIO (19) via the Gpio
class.
At the top of the file:
#include <Gpio.h>
Gpio cs;
in setup()"
:
cs.open(19);
Then readSpi()
could have:
{
...
cs.clear();
usleep(1000); // wait between start of chip select and start of transmission.
int ret = spiDevice.transfer(tx_buf, rx_buf, transmissionLength);
usleep(1000); // wait between end of transmission and end of chip select
if(ret)
{...} else {...}
}
Then you can tweak the sleep values as needed. Note that you won't have a lot of accuracy on the sleep times, as that's governed by the kernel scheduler and note that usleep(0)
is different from (longer than) no call to usleep()
at all. Also, a compliant SPI implementation on the device side should not care about long chip select times.
Oh, another way you'd be able to monitor if this (or the original) chip select code is behaving as expected you could wire that pin back to one of the Bela digital inputs and visualise it on the Bela scope.