![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
EEPROMTEST
Fork of Test_nucleo_MCUUU by
main.cpp
- Committer:
- MockyBirdTwo
- Date:
- 2018-05-09
- Revision:
- 9:cc559f905411
- Parent:
- 8:2875bb7a4e67
- Child:
- 10:5a0bad3fb422
File content as of revision 9:cc559f905411:
#include "mbed.h" // Include files and define parameters. #include "Adafruit_ADS1015.h" #include <vector> #include <string> using namespace std; 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 DigitalOut myled(LED1); //Check whether any sensor values are zero void checkzero (vector<int>& sendat, int size){ usb_serial.printf("Zero:"); for(int i=0;i<size;++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);} } } //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(){ vector<int> S_data(8); 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"); piezo_resistive_adc1.setGain(GAIN_TWOTHIRDS); // Set ranges of ADC to +/-6.144V (end is marked with #): piezo_resistive_adc2.setGain(GAIN_TWOTHIRDS); usb_serial.printf("Gains set.\n"); timer.start(); while(1){ while(timer.read_us() < 2000){}; timer.reset(); //Set readout frequency myled = !myled; //usb_serial.printf("Piezo electric 0_1 dif %d \n", piezo_electric_adc.readADC_Differential_0_1()); // First PE readout. // usb_serial.printf("Piezo electric 2_3 dif %d \n", piezo_electric_adc.readADC_Differential_2_3()); for (uint8_t t=0; t<4; ++t){ //Save sensor data into array S_data[t] = (int16_t) piezo_resistive_adc1.readADC_SingleEnded(t); //Put first 4 PR sensor data into first 4 S_data array 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()); //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. } } }