Exemple #1
0
        public void ReadADC()
        {
            byte[] readBuffer  = new byte[3]; /* Buffer to hold read data*/
            byte[] writeBuffer = new byte[3] {
                0x00, 0x00, 0x00
            };

            /* Setup the appropriate ADC configuration byte */
            switch (ADC_DEVICE)
            {
            case AdcDevice.MCP3002:
                writeBuffer[0] = MCP3002_CONFIG;
                break;

            case AdcDevice.MCP3208:
                writeBuffer[0] = MCP3208_CONFIG;
                break;

            case AdcDevice.MCP3008:
                writeBuffer[0] = MCP3008_CONFIG[0];
                writeBuffer[1] = MCP3008_CONFIG[1];
                break;
            }

            SpiADC.TransferFullDuplex(writeBuffer, readBuffer); /* Read data from the ADC                           */
            adcValue = convertToInt(readBuffer);                /* Convert the returned bytes into an integer value */

            /* UI updates must be invoked on the UI thread */
            var task = this.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                textPlaceHolder.Text = adcValue.ToString();         /* Display the value on screen                      */
            });
        }
Exemple #2
0
        public int ReadADC()
        {
            byte[] readBuffer  = new byte[3]; /* Buffer to hold read data*/
            byte[] writeBuffer = new byte[3] {
                0x00, 0x00, 0x00
            };

            writeBuffer[0] = MCP3008_CONFIG[0];
            writeBuffer[1] = MCP3008_CONFIG[1];

            SpiADC.TransferFullDuplex(writeBuffer, readBuffer); /* Read data from the ADC                           */
            return(convertToInt(readBuffer));                   /* Convert the returned bytes into an integer value */
        }
        public int ReadADC(byte channel)
        {
            byte[] readBuffer  = new byte[3]; /* Buffer to hold read data*/
            byte[] writeBuffer = new byte[3] {
                0x00, 0x00, 0x00
            };

            /* Setup the appropriate ADC configuration byte */
            writeBuffer[0] = (byte)(6 + ((channel & 4) >> 2));
            writeBuffer[1] = (byte)((channel & 3) << 6);
            writeBuffer[2] = 0;

            SpiADC.TransferFullDuplex(writeBuffer, readBuffer);  /* Read data from the ADC                           */
            return(((readBuffer[1] & 15) << 8) + readBuffer[2]); /* Convert the returned bytes into an integer value */
        }
Exemple #4
0
        public void  async(byte whichChannel)//SPI取值
        {
            //whichChannel=0
            byte command = whichChannel;

            command  |= 0x08; //command跟0x08(00001000)進行OR運算
            command <<= 4;    //向左移位4位元
            byte[] readBuffer  = new byte[3];
            byte[] writeBuffer = new byte[3] {
                0x01, command, 0x00
            };

            SpiADC.TransferFullDuplex(writeBuffer, readBuffer);//rpi3和mcp3008傳輸(全雙工)

            adcValue = convertToInt(readBuffer);
        }