2

I am trying to pull a few bytes per second from a microchip board attached to a temperature sensor and a photodiode, using Windows 10 IoT on a Dragonboard 410c. It seems like there's either interference when I attempt to read from more than one GPIO at a time. How can I get input from these GPIOs without messing up my clock signal?

namespace DashWall
{
    public sealed partial class MainPage : Page
    {
        private const int CLOCK_PIN = 12;
        private const int TEMP_PIN = 34;
        private const int PHOTO_PIN = 33;
        private const int START_PIN = 36;

        private GpioPin clockPin;
        private GpioPinValue clockPinValue;
        private GpioPin tempPin;
        private GpioPinValue tempPinValue;
        private GpioPin photoPin;
        private GpioPinValue photoPinValue;
        private GpioPin startPin;
        private GpioPinValue startPinValue;

        private DispatcherTimer timer;

        private GpioController gpio;

        public MainPage()
        {
            InitializeComponent();

            timer = new DispatcherTimer();
            timer.Interval = TimeSpan.FromMilliseconds(10);
            timer.Tick += Timer_Tick;

            InitGpio();
            timer.Start();
        }

        private void InitGpio()
        {
            gpio = GpioController.GetDefault();

            clockPin = gpio.OpenPin(CLOCK_PIN);
            tempPin = gpio.OpenPin(TEMP_PIN);
            photoPin = gpio.OpenPin(PHOTO_PIN);
            startPin = gpio.OpenPin(START_PIN);

            clockPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            tempPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            photoPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
            startPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
        }

        bool isReading = false;
        bool bitRead = false;
        uint curPhoto;
        uint curTemp;
        uint bitCount = 0;
        bool start;
        bool clock;
        bool photo;
        bool temp;
        private void Timer_Tick(object sender, object e)
        {
            handleInput();
            Time.Text = "" + clock;
            Temp.Text = "" + temp;

            if (start && clock && !isReading)
            {
                Temp.Text = "" + start;
                isReading = true;
                curPhoto = 0;
                curTemp = 0;
            }

            if (isReading)
            {
                if (clock && !bitRead)
                {
                    ReadBit();
                    bitRead = true;
                }
                if (!clock)
                {
                    bitRead = false;
                }
            }
        }

        private void ReadBit()
        {
            uint photoBit = 0;
            uint tempBit = 0;
            if (photo) { photoBit = 1; }
            if (temp) { tempBit = 1; }
            curPhoto = curPhoto << 1;
            curPhoto = curPhoto + photoBit;

            curTemp = curTemp << 1;
            curTemp = curTemp + tempBit;

            bitCount++;

            if (bitCount >= 8)
            {
                isReading = false;
                bitCount = 0;

                //Time.Text = "" + Convert.ToString(curPhoto, 2);
                //Temp.Text = "" + curTemp;
            }
        }

        private void handleInput()
        {
            clockPinValue = clockPin.Read();
            clock = clockPinValue == GpioPinValue.High;

            startPinValue = startPin.Read();
            start = startPinValue == GpioPinValue.High;

            photoPinValue = photoPin.Read();
            photo = photoPinValue == GpioPinValue.High;

            tempPinValue = tempPin.Read();
            temp = tempPinValue == GpioPinValue.High;
        }

    }
}
1
  • 1
    Welcome to the site, Somnacin7! For clarity's sake, what is it currently doing to your clock?
    – anonymous2
    Commented Mar 4, 2018 at 13:12

1 Answer 1

5

Turns out that the ground cable between the two microcontrollers had been dislodged. Putting that back in place fixed my problem.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.