![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
EEPROMTEST
Fork of Test_nucleo_MCUUU by
Diff: main.cpp
- Revision:
- 9:cc559f905411
- Parent:
- 8:2875bb7a4e67
- Child:
- 10:5a0bad3fb422
--- a/main.cpp Wed May 09 11:13:21 2018 +0000 +++ b/main.cpp Wed May 09 15:00:54 2018 +0000 @@ -1,16 +1,21 @@ #include "mbed.h" // Include files and define parameters. #include "Adafruit_ADS1015.h" #include <vector> +#include <string> +using namespace std; -I2C i2c_sensorplate_adc(PB_9, PB_8); // I2C for sensorplate. -Adafruit_ADS1115 piezo_resistive_adc1(&i2c_sensorplate_adc, 0x48); // i2c pins, i2c address. -Adafruit_ADS1115 piezo_resistive_adc2(&i2c_sensorplate_adc, 0x49); // i2c pins, i2c address. -Adafruit_ADS1115 piezo_electric_adc(&i2c_sensorplate_adc, 0x4B); // i2c pins, i2c address. +I2C i2c(PB_9, PB_8); // I2C for sensorplate. +Adafruit_ADS1115 piezo_resistive_adc1(&i2c, 0x48); // i2c pins, i2c address. +Adafruit_ADS1115 piezo_resistive_adc2(&i2c, 0x49); // i2c pins, i2c address. +Adafruit_ADS1115 piezo_electric_adc(&i2c, 0x4B); // i2c pins, i2c address. +//I2C for EEEEEEEPROM eeprom_mod(&i2, ?adres?) + Serial usb_serial(SERIAL_TX, SERIAL_RX); // tx, rx int i2c__frequency = 100000; // I2C Frequency. int baud_rate = 115200; // Baud rate. - +const int EEPROM_adr=0x00;//8Bit address for I2C to EEPROM +const int EE_len =1; //Length EEprom vector to be sent Timer timer; // array to save sensor data @@ -18,22 +23,32 @@ DigitalOut myled(LED1); //Check whether any sensor values are zero -void checkzero (std::vector<int>& sendat, int size){ +void checkzero (vector<int>& sendat, int size){ + usb_serial.printf("Zero:"); for(int i=0;i<size;++i){ - if(sendat[i]!= 0) - usb_serial.printf("Sensor %d is not zero\n", i); - else - usb_serial.printf("Sensor %d is zero\n", i); + if(sendat[i]> -5 & sendat[i] < 5){ + sendat[i]=0;} + if(sendat[i]!= 0){ + usb_serial.printf("%d\n", i);} + else{ + usb_serial.printf("%d\n", i);} } } - -//-------------FLASH FLASH----------------- -//Only 16 bits data may be written. +//Writing EEPROM through I2C +void EEPROM_write(char *EEPROM_dat,int len){ + i2c.write(EEPROM_adr,EEPROM_dat,len); +} +//Reading EEPROM through I2C, returns vector +string EEPROM_read(){ + char EEPROM_dat[EE_len]; + i2c.read(EEPROM_adr,EEPROM_dat,EE_len); + return EEPROM_dat; +} int main(){ - std::vector<int> S_data(8); + vector<int> S_data(8); - i2c_sensorplate_adc.frequency(i2c__frequency); // Set frequency for i2c connection to sensorplate (variable is declared in config part). + i2c.frequency(i2c__frequency); // Set frequency for i2c connection to sensorplate (variable is declared in config part). usb_serial.baud(baud_rate); // Set serial USB connection baud rate (variable is declared in config part). usb_serial.printf("MCUs rule the World !\n"); @@ -56,7 +71,7 @@ S_data[t+4]= (int16_t) piezo_resistive_adc2.readADC_SingleEnded(t); //Put next 4 PR sensor data into first 4 S_data array } - //checkzero(S_data,S_data.size()); + checkzero(S_data,S_data.size()); //Check whether any sensor values are zero for (uint8_t k = 0; k < 4; ++k) { usb_serial.printf("R %d Ar %d: %d\n", k, 1, S_data[k]); // First 4 PR readout. usb_serial.printf("R %d Ar %d: %d\n", k, 2, S_data[k+4]); // Next 4 PR readout.