G120 SPI issue


I am experiencing a problem with an external ADC connected through SPI. The values are coming in perfectly, however after some random time, evrytime the G120 controller freezes and the USB interface also becomes unavailable. No exception information is coming in the serial debug interface as well.

I am using a G120 with tinyCLR 1.0. I am stuck with a current PCB design where a ADC is connected to the SPI2 bus.

I know it is more or less reserved voor ethernet, but former design team has connected it to a MCP3301-BI/SN ADC and used P1_31 as chip select.

I have tried lots of things, reduced clock frequency of the device etc. nothing seems to help. I noticed also, when I put in a delay of 1 second after reading out the device, it takes longer for the G120 to freeze and become unresponsive.

The goal is to read out the analogue cyclically every 200ms. Can anybody give me some tips or point me in the right direction? Thanks in advance, this is how my code looks approximately:

using System;
using System.Diagnostics;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading;
using GHIElectronics.TinyCLR.IO;
using GHIElectronics.TinyCLR.Devices.Gpio;
using GHIElectronics.TinyCLR.Devices.Pwm;
using GHIElectronics.TinyCLR.Devices.Adc;
using GHIElectronics.TinyCLR.Devices.Can;
using GHIElectronics.TinyCLR.Native;
using GHIElectronics.TinyCLR.Pins;
using GHIElectronics.TinyCLR.Devices.Spi;

//ChipSelectLine = G120.GpioPin.P1_31

    //SPI bus
    static SpiConnectionSettings connectionSettings = new SpiConnectionSettings()
        ChipSelectType = SpiChipSelectType.Gpio,
        ChipSelectLine = G120.GpioPin.P1_31,
        Mode = SpiMode.Mode1,
        ClockFrequency = 125_000,
        DataBitLength = 8,

    //SPI1 = actually SPI2 in the datasheet
    static SpiController controller = SpiController.FromName(G120.SpiBus.Spi1);        
    static SpiDevice device = controller.GetDevice(connectionSettings);

    static void Cyclic200ms(object o)

byte[] writeBuffer = new byte[2];
byte[] readBuffer = new byte[2];

        writeBuffer[0] = 0x00; //Initialise write buffer to make sure no random number gets written
        writeBuffer[1] = 0x00;

        int value = 0;

        device.TransferSequential(writeBuffer, readBuffer);

        value = (readBuffer[0] & 0x0F);           //4 bits masking
        value <<= 8;
        value |= readBuffer[1];

        if ((readBuffer[0] & 0x10) == 0x10)  //signbit = 1, value is negative
            value = 0;

        //Debug.WriteLine("Value: " + value.ToString());

        //double dWaarde = Convert.ToDouble(value.ToString());
        double offsetCorrection = 0.0248;

        measuredPressure = ((value / 4096.0) * Config.MaxSensPressure) - offsetCorrection;


static void Main()
int CyclicTime3 = 200; //200 ms

        Timer CyclicInterrupt3 = new Timer(Cyclic200ms, null, 0, CyclicTime3); //Cyclic interrupt for pressure control


while (!_exitProgram) {


just a question, is there any reason you’ve moved away from netmf for the G120? That’s by far the most supported platform for that age of device…

It would be very difficult to fix anything on TinyCLR 1.0.

We recommend using using netmf if you must use G120 not the best option is SITCore with TinyCLR 2.0 and soon 2.1.

Hi Brett, thank you for your quick reply. No reason from my side, my predecessor upgraded to TinyCLR v1.0 for no apparent reason from my side, and I am still working things out.

I was given this to work with… But your replies are an eye opener. I will try to downgrade the code so far and try to and make it work nevertheless. I had no idea that tinyCLR 1.0 was incompatible, or at least not supported, but learning every step of the way.

FYI, the client has a significant amount of these G120 soM’s in stock which I have to work with. Now I am starting to wonder, should I spent more time or convince the client to migrate to sitcore.



Worth the switch for sure

I’m not sure the sitcore switch would fly, because of their stock of modules, but probably worth looking at features and making sure that netmf isn’t going to limit future capabilities that you know the client will need. Newer SSL ciphers and modern security are key requirements for web enablement these days, and honestly the SSL options in netmf are not up to it. If there’s web, then I’d be seriously talking up security as a key concern and the move to sitcore would be a smart future-proofing one.

Hi Brett, Gus,

Apparently, it was my misunderstanding that the client had all large batch of the older modules in stock. Given the advantages of upgrading to sitcore, the hardware engineer is now looking in to it.

It seems that the drop-in replacemnt module consumes more power, so the power supply needs to be modified on the board. On the other hand, the ADC is way better than the one on the G120, so we can probably omit the external ADC.

Just for my information, I have one question, though. From the available information I could not determine quickly what the differnce is and benefit of using the SOM instead of the SOC? Is it only the available external memory?

Thanks, Remco

We are adding a new mode in next release that runs the process at half speed to reduce power consumption.

Three module is simply a chipset with external memory, which is nice for graphics and complete in field update.

Thank you for your quick reply Gus. So if I understand correctly, if we do not use a lot of memory (maybe a handful of settings to be stored to EEPROM) we do not need this SoM at all, and we can go for the SoC version? That would be quite beneficial for the limited space on the board at this time. I think the sitcore chip is a little bit overdone for our application, but I can understand why my predecessor choose to go with this, using the .NET environment and the simplicity is a breeze.

The mode you are referring to would also be a very welcome feature, when do you think this feature will be available? We have some time, since I found out the new sitcore components are not widely available with Digi-Key and/or Mouser oppossed to the 8000+ old G120 modules…

Thanks again, Remco

These parts are brand new and we’re just getting them to distributors. They will be as popular as the old product and they will replace them at some point.

Depending on what you’re doing you may not need external memory I think the best way is to try it out. Oh you can give us a call and we can discuss your needs and give you an advice on external memory.

Thanks, I might just do that. When is good time to call you to discuss?

We are here … just call or email to schedule a time.

We have just checked and at 480mhz it id about 190mA and at 240Mhz it is about 100mA.

Thanks, we will uograde the power supply so we can benefit the full speed. We will await the feature in the next release.Thanks.

1 Like