This time we are in the NUCLEO-F412ZG test analog input acquisition. Our analog inputs are based on Adi's AD7705, a 16-bit, two-way, differential-input ad capture chip. With SPI interface, we will use the SPI interface to communicate with the AD7705. Two inputs all the way to the oxygen sensor, a hydrogen sensor is connected.
There are two kinds of oxygen sensor, one is paramagnetic oxygen sensor, the output signal is 4-20ma. Therefore, a 250 ohm resistor is then received on the output side and then connected to the AD7705 's collecting board. The Gray line and the white line are positive and negative poles respectively. The style is as follows:
Another oxygen sensor is electrochemical, because the electrochemical sensor output is a millivolt signal (0-60MV), in order to comply with the AD7705 signal acquisition range, I built a magnifying circuit on the breadboard for testing, the millivolt signal amplification 50 times times, The signal of the Xincheng 0-3VDC is acceptable for the AD7705 Collection board.
These two sensors are exposed to air because the oxygen content in the air is about 21%. The value of the oxygen sensor is a relatively large value. It may not be around 21% because there is no calibration.
The hydrogen sensor is a 0-5VDC signal. The signal of the hydrogen sensor has been complied with the requirements of the AD7705 collecting board, which can be directly:
AD7705 Acquisition Board and the external connection is the SPI interface, in the experiment we use the stm32f412 SPI1, the corresponding PIN is:
40 |
PA4 |
Spi1_nss |
Cn7_17 |
41 |
PA5 |
Spi1_sck |
Cn7_10 |
42 |
PA6 |
Spi1_miso |
Cn7_12 |
43 |
PA7 |
Spi1_mosi |
Cn7_14 |
The following red box section:
To configure the SPI1 in Stm32cubemx, first configure the parameters of the SPI interface:
Then we can configure the pin according to our usage habits:
SPI1 and AD7705, AD5663 related GPIO configurations
void Spi1_gpio_configuration (void)
{
Gpio_inittypedef gpio_initstructure;
Configuring SPI1 Sck and Mosi (PA5, PA7)
Gpio_initstructure.gpio_pin = Gpio_pin_5 | gpio_pin_7;
Gpio_initstructure.gpio_mode = gpio_mode_af_pp; multiplexed push-Pull output
Gpio_initstructure.gpio_speed = Gpio_speed_50mhz;
Gpio_init (Gpioa, &gpio_initstructure);
Configuring the SPI1 Miso (PA6)
Gpio_initstructure.gpio_pin = Gpio_pin_6;
Gpio_initstructure.gpio_mode = Gpio_mode_ipu;
Gpio_initstructure.gpio_mode = gpio_mode_af_pp; multiplexed push-Pull output
Gpio_init (Gpioa, &gpio_initstructure);
Configuring AD Chip selection signals (PA4)
Gpio_initstructure.gpio_pin = Gpio_pin_4;
Gpio_initstructure.gpio_mode = gpio_mode_out_pp;
Gpio_init (GPIOC, &gpio_initstructure);
Spi_ad7705_cs_high ();
}
Configuring the SPI
void Spi1_configuration (void)
{
Spi_inittypedef spi_initstructure;
SPI1 Configuration
Spi_initstructure.spi_direction = Spi_direction_2lines_fullduplex; Set SPI unidirectional or bidirectional data mode: SPI set to double-line bidirectional full duplex
Spi_initstructure.spi_mode = Spi_mode_master; Set SPI operating mode: set to Primary SPI
Spi_initstructure.spi_datasize = spi_datasize_8b; Setting the data size of the SPI: SPI send receive 8-bit frame structure
Spi_initstructure.spi_cpol = Spi_cpol_low; The steady state of the serial clock is selected: Idle status remains low
Spi_initstructure.spi_cpha = Spi_cpha_1edge; Data capture on second clock edge
Spi_initstructure.spi_nss = Spi_nss_soft; NSS signals are managed by hardware (NSS pins) or software (using SSI bits): internal NSS signal with SSI bit control
Spi_initstructure.spi_baudrateprescaler = spi_baudrateprescaler_64;//Defines the value of the baud rate Prescaler: The baud rate Prescaler value is 256
Spi_initstructure.spi_firstbit = SPI_FIRSTBIT_MSB; Specify whether the data transfer begins with the MSB bit or the LSB bit: data transfer starts with the MSB bit
Spi_initstructure.spi_crcpolynomial = 7; Polynomial of CRC value calculation
Spi_init (SPI1, &spi_initstructure); Initializes the peripheral Spix register according to the parameters specified in the Spi_initstruct
Enable SPI Peripherals
Spi_ssoutputcmd (SPI1, ENABLE);
Spi_cmd (SPI1, ENABLE);
}
After the configuration is complete, the data can be read using AD7705 's operation functions (which we have already written and standardized on other projects). The software is debugged online as follows:
Through the IAR IO Terminal can easily view the data display, about the IAR IO terminal configuration can be viewed on the Internet, my blog Park also has a piece of article records the use of methods. The results viewed in the IO terminal are as follows:
Because it is exposed to air, so the oxygen data is relatively large (because the sensor is calibrated, calibration should be around 21%, calibration needs to write another program), but the hydrogen data is almost 0.
STM32F412 Application Development Note III: SPI bus communication and AD acquisition