0503-06 MCP3202 ADC
Example Projects > 0503 Generic SPI Communication > 0503-06 MCP3202 ADC
Reading MCP3202 ADC via SPI bus
This folder contains the source files for reading ADC data from the MCP3202 dual-channel 12-bit ADC via SPI bus, which is available e.g. on the Raspberry Pi minicomputer. The example is based on the REXLANG user-programmable function block of REXYGEN.
The 12-bit data obtained from the ADC chip are converted to voltage reading using the LIN function block. The y2 parameters of LINx function blocks must be changed according to the supplied voltage reference.
The time plot of the measured data can be displayed in the REXYGEN Diagnostics diagnostic program.
Timing of the project
The algorithm runs each 100 milliseconds (0.1 s). See the EXEC function block,
tick x ntick0 = 0.01 x 10 = 0.1
- REXYGEN Runtime Core must be installed and running on the target device (Raspberry Pi).
- SPI bus must be enabled and available (e.g. /dev/spidev0.0 on the Raspberry Pi)
- The wiring must comply with the attached datasheet.
Running the example
- The *exec.mdl file is the project main file.
- Open it with REXYGEN Studio.
- Specify the SPI bus by the "p0" parameter of the REXLANG function block.
- Compile and download it to the target device.
- Switch to Watch mode and observe the algorithm.
- Enable online monitoring of the REXLANG block (Target->Watch Selection).
- Apply external voltage to the ADC pins and observe the received data.
- Press F1 for help on the selected function block in the REXYGEN Studio.
- Getting started with REXYGEN on the Raspberry Pi minicomputer
- Function blocks of REXYGEN
- MCP3201 datasheet (attached)
- REXYGEN Studio User Guide
- Complete documentation of REXYGEN