revised code
Embed:
(wiki syntax)
Show/hide line numbers
SPI_Outputs.cpp
00001 /**---------------------------------------------------------------------------- 00002 * 00003 * \file frequency_detector.cpp 00004 -- -- 00005 -- ECEN 5803 Mastering Embedded System Architecture -- 00006 -- Project 1 Module 4 -- 00007 -- Microcontroller Firmware -- 00008 -- frequency_detector.cpp -- 00009 -- -- 00010 ------------------------------------------------------------------------------- 00011 -- 00012 -- Designed for: University of Colorado at Boulder 00013 -- 00014 -- 00015 -- Designed by: Tim Scherr 00016 -- Revised by: Naved Maududi and Bryan Cisneros 00017 -- 00018 -- Version: 2.1 00019 -- Date of current revision: 2017-09-25 00020 -- Target Microcontroller: Freescale MKL25ZVMT4 00021 -- Tools used: ARM mbed compiler 00022 -- ARM mbed SDK 00023 -- Freescale FRDM-KL25Z Freedom Board 00024 -- 00025 -- 00026 Functional Description: 00027 This file contains code that takes in quasi-sine wave ADC inputs from the flow meter 00028 From the ADC inputs, it calculates the frequency of that sine wave. The frequency is 00029 important in determining the flow rate and velocity for the flowmeter that are outputed 00030 to the display. 00031 -- 00032 -- Copyright (c) 2015 Tim Scherr All rights reserved. 00033 */ 00034 00035 00036 #include "shared.h" 00037 #include "MKL25Z4.h" 00038 #define SPI_bit_length 16 // bit length for the spi port 00039 #define SPI_mode 3 // clock is set to trigger at high and in phase 00040 #define SPIx_C1 (SPI0->C1) 00041 #define SPIx_C2 (SPI0->C2) 00042 #define SPIx_BR (SPI0->BR) 00043 #define SPIx_S (SPI0->S) 00044 00045 /**********************/ 00046 00047 PinName const SPI_MOSI = PTC6; // Master out slave in signal for SPI to feed into LCD 00048 PinName const SPI_MISO = PTC7; // Master in slave out, reading signal from LCD back to the controller 00049 PinName const SPI_SCK = PTC5; // clock signal to synchronize the data for SPI communication 00050 //PinName const SPI_CS = PTC4; // Chip select if you have muliple slaves 00051 00052 void LCD_Display(void){ 00053 00054 SPIx_C1= (0x54); 00055 SPIx_C2= (0x00); 00056 SPIx_BR = (0x00); 00057 00058 00059 SPI LCD(SPI_MOSI, SPI_MISO, SPI_SCK); 00060 LCD.lock(); // Acquire exclusive access to this SPI bus. 00061 LCD.format(SPI_bit_length, SPI_mode); // select correct mode and bits to transfer to the LDC monitor 00062 // while(SPIx_S & SPI_S_SPTEF_MASK); // wait for the value equal tot 1 00063 LCD.write(flow); // write the value of flow to slave device, which is the peripheral LCD display 00064 //while(SPIx_S & SPI_S_SPTEF_MASK); // wait for the value equal tot 1 00065 LCD.write(freq_value); // write the value of frequency to slave device, which is the peripheral LCD display 00066 // while(SPIx_S & SPI_S_SPTEF_MASK); // wait for the value equal tot 1 00067 LCD.write(temperature); // write the value of temperature to slave device, which is the peripheral LCD display 00068 } 00069 00070
Generated on Tue Jul 12 2022 20:46:01 by
1.7.2