You have reached the legacy GHI Electronics, LLC website, for the new website please visit here. For the new forum please visit here.

This legacy website will be taken offline at the end of this year. If there is anything that you would like to archive and save for future reference please do so.

You must be logged in to reply.

Page 1 of 1 out of 4 messages.

TINYCLR - How to use more than one SPI device on a bus ?

Posted 9mth ago
by Bec a Fuel | King | 34,301 exp
Posted 9mth ago
by Bec a Fuel | King | 34,301 exp
I have two SPI devices on the same bus on a Quail (STM32F427) and I get an exception on spi2 declaration when I run the following code :
private static void TestSPI()
        {
            var spiConfig1 = new SpiConnectionSettings(3)
            {
                ClockFrequency = 12000000,
                DataBitLength = 8,
                Mode = SpiMode.Mode0,
                SharingMode = SpiSharingMode.Shared
            };
            var spi1 = SpiDevice.FromId("GHIElectronics.TinyCLR.NativeApis.STM32F4.SpiProvider\\0", spiConfig1);

            var spiConfig2 = new SpiConnectionSettings(65)
            {
                ClockFrequency = 12000000,
                DataBitLength = 8,
                Mode = SpiMode.Mode0,
                SharingMode = SpiSharingMode.Shared
            };
            var spi2 = SpiDevice.FromId("GHIElectronics.TinyCLR.NativeApis.STM32F4.SpiProvider\\0", spiConfig2);
        }

The thread '<No Name>' (0x2) has exited with code 0 (0x0).
    #### Exception System.Exception - CLR_E_FAIL (1) ####
    #### Message: 
    #### GHIElectronics.TinyCLR.Devices.Spi.Provider.DefaultSpiDeviceProvider::InitNative [IP: 0000] ####
    #### GHIElectronics.TinyCLR.Devices.Spi.Provider.DefaultSpiDeviceProvider::.ctor [IP: 0029] ####
    #### GHIElectronics.TinyCLR.Devices.Spi.Provider.DefaultSpiControllerProvider::GetDeviceProvider [IP: 0008] ####
    #### GHIElectronics.TinyCLR.Devices.Spi.SpiDevice::FromId [IP: 004c] ####
    #### TinyCLRApplication1.Program::TestSPI [IP: 0053] ####
    #### TinyCLRApplication1.Program::Main [IP: 0004] ####
Exception thrown: 'System.Exception' in GHIElectronics.TinyCLR.Devices.dll

Each one is running fine alone and both are running fine as well when the second one is on another bus.

I thought that SpiSharingMode.Shared would allow that. Am I wrong ?
Reply #1 — Posted 9mth ago
by Gus_ghielectroncs | Employee
Reply #1 — Posted 9mth ago
by Gus_ghielectroncs | Employee
then it may be a bug on our end. Any suggestions for a setup with a simple example code?
Reply #2 — Posted 9mth ago
by Bec a Fuel | King | 34,301 exp
Reply #2 — Posted 9mth ago
by Bec a Fuel | King | 34,301 exp
Gus_ghielectroncs says:
then it may be a bug on our end. Any suggestions for a setup with a simple example code?

An empty Quail board and the above code is the simplest setup you can use to reproduce the issue, in fact. As it does not pass the second SPI device creation.


By the way, how is data sent to the device when you select 16 bits length ? MSB or LSB first ?
Reply #3 — Posted 9mth ago
by John_ghielectroncs | Employee
Reply #3 — Posted 9mth ago
by John_ghielectroncs | Employee
@Bec a Fuel - It's a known issue in the current release. MSB/LSB is determined by the specific SPI provider. So for STM32F4, the order is whichever the datasheet for the specific processor specifies. The HAL driver in the ports repo just writes/reads the entire 8/16 bit value to/from the DR register.

Page 1 of 1 out of 4 messages.

You must be logged in to reply.