Tu Hoang
/
Test_nucleo_MCUUU_EEPROMTEST
EEPROMTEST
Fork of Test_nucleo_MCUUU by
Diff: main.cpp
- Revision:
- 14:be6538b80545
- Parent:
- 13:9bd3083f02d4
- Child:
- 15:44d291c21362
diff -r 9bd3083f02d4 -r be6538b80545 main.cpp --- a/main.cpp Thu May 17 08:48:49 2018 +0000 +++ b/main.cpp Fri May 18 10:44:44 2018 +0000 @@ -8,14 +8,14 @@ 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=0xa0;//8Bit address for I2C to EEPROM -const int EE_len =1; //Length EEprom vector to be sent +const int EEPROM_adr=0xA0 ;//8Bit address for I2C to EEPROM +const int EE_len = 2; Timer timer; // array to save sensor data @@ -40,27 +40,76 @@ //Device Select 1 0 1 0 E2 E1 E0 RW // E0,E1 and E2 are to identify device //Writing EEPROM through I2C -void EEPROM_write(char EEPROM_dat,int len){ - i2c.write(EEPROM_adr,&EEPROM_dat,len); +void EEPROM_write(){ + int ack; + uint8_t EEPROM_dat[2]; + EEPROM_dat[0] = (uint8_t) 0; + EEPROM_dat[1] = (uint8_t) 100; + + ack=i2c.write(EEPROM_adr,(char*)EEPROM_dat,sizeof(EEPROM_dat)); + if(ack != 0) { + usb_serial.printf("ERRORwrite\n"); + } } //Reading EEPROM through I2C, returns vector -string EEPROM_read(){ - char EEPROM_dat[EE_len]; - i2c.read(EEPROM_adr,EEPROM_dat,EE_len); - for (uint8_t k = 0; k < EE_len; ++k) { - usb_serial.printf("EEPROMdata %d = %d\n",k, EEPROM_dat[k]); +void EEPROM_read(){ + int ack; + uint8_t cmd[1]; + uint8_t EEPROM_dat[EE_len]; + + cmd[0] = (uint8_t) 0; + ack = i2c.write(EEPROM_adr,(char*)cmd,1,true); + if(ack != 0) { + usb_serial.printf("ERRORwriter\n"); + } + ack=i2c.read(EEPROM_adr,(char*)&EEPROM_dat,EE_len); + if(ack != 0) { + usb_serial.printf("ERRORread\n"); + } + + +// int len = 2; +// uint8_t cmd[2]; +// char EEPROM_dat[len]; +// // First word address (MSB) +// cmd[0] = (uint8_t) (9 >> 8); +// +// // Second word address (LSB) +// cmd[1] = (uint8_t)8; +// +// // Write command +// ack = i2c.write((int)EEPROM_adr,(char *)cmd,len,true); +// if(ack != 0) { +// usb_serial.printf("ERRORwriteR\n"); +// } +// +// // Read data +// ack = i2c.read((int)EEPROM_adr,(char *)&EEPROM_dat,sizeof(EEPROM_dat)); +// if(ack != 0) { +// usb_serial.printf("ERRORread\n"); +// } + for (uint8_t k = 0; k < sizeof(EEPROM_dat); ++k) { + usb_serial.printf("EEPROMdata %d = %d\n",k,((int) EEPROM_dat[k])); } - 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"); -// + usb_serial.baud(baud_rate); // Set serial USB connection baud rate (variable is declared in config part). + +// vector<int> S_data(8); +// char EEPROM_dat[2]={0}; +// EEPROM_dat[0] = (uint8_t) 5; +// EEPROM_dat[1] = (uint8_t) 8; + + usb_serial.printf("MCUs rule the World !\n"); + myled = !myled; + EEPROM_write(); + EEPROM_read(); + + // piezo_resistive_adc1.setGain(GAIN_TWOTHIRDS); // Set ranges of ADC to +/-6.144V (end is marked with #): // piezo_resistive_adc2.setGain(GAIN_TWOTHIRDS); // @@ -70,7 +119,7 @@ // 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()); //