Blue pill with external EEPROM

All about boards manufactured by ST
Green77
Posts: 11
Joined: Mon Aug 15, 2022 7:28 am

Blue pill with external EEPROM

Post by Green77 »

Hello all,

I'm really new to the STM32 world and have a problem with external EEPROM.

I have portet a Arduino Due program for controlling a audio dac (ESS 9028pro) to STM32 (blue pill). It have been some challenge but overall it seems ok now.
Except for store settings in a external EEPROM.
In Due program store setting working fine.

I use a external EEPROM (AT24c256) over i2c bus. I have checked memory with i2c scanner and device is found at 0X50.

In due i use libary extEEPROM.h and i use the same with stm32. Is that ok? Can't fin if it's ok but i have no problem compile.
Problem is that value doesn't get stored or i can "load" them on start up with STM32.
So all values are zero.

Program is over 5000 rows but i will past code surronding eeprom.

Code:

Defines etc:

#include "extEEPROM.h" // Library for the I2C EEPROM
extEEPROM myEEPROM(kbits_256, 1, 64, 0x50); // myEEPROM object, 256kbit, 1 device on the bus, 64 bytes page size, 0x50

//Setup EEPROM
int eeAddress=0; // EEPROM address
int eeAddress1=0; // EEPROM address of Input 1 memory
int eeAddress2=128; // EEPROM address of Input 2 memory
int eeAddress3=256; // EEPROM address of Input 3 memory
int eeAddress4=384; // EEPROM address of Input 4 memory
int eeAddressS=1920; // EEPROM address of Settings memory
int eeAddressT=2048; // EEPROM address of test data


Startup:

// Load Settings1 from EEPROM
eeAddress = eeAddressS;
byte *pSettings = (byte*)&Settings1;
myEEPROM.read(eeAddress, pSettings, sizeof(DAC_Settings));

Save settings:

void savetoEEPROM()
eeAddress=eeAddressS; // Address of Settings1
Settings1.variable=preamp; // Store default variable setting to EEPROM
Settings1.preamp_def_vol=preamp_def_vol; // Store default preamp volume setting to EEPROM
Settings1.backlight=backlight; // Store default TFT backlight setting to EEPROM
myEEPROM.write(eeAddress, (byte *)&Settings1, sizeof(DAC_Settings)); // write to EEPROM

Anyone know if i can do it like this? Works fine with Arduino Due.

BR// Daniel
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: Blue pill with external EEPROM

Post by GonzoG »

I use I2C_EEPROM by Rob Tillaart.
Green77
Posts: 11
Joined: Mon Aug 15, 2022 7:28 am

Re: Blue pill with external EEPROM

Post by Green77 »

Aha, Thanks.
Will have a look at it.

BR// Daniel
Green77
Posts: 11
Joined: Mon Aug 15, 2022 7:28 am

Re: Blue pill with external EEPROM

Post by Green77 »

Hello again,

I've tried I2C_EPPROM by Rob that was suggested from GnozoG (Thanks).
Still doesn't fly for me. I have the same problem as with extEEPROM.

I run a example code from I2C_EEPROM that scanned the memory and all seems fine, addres 0X50, 32K, 1 device....

But in my program i download fine and programs start. But when it tries to read the settings program hangs.
I have a tft so i can see that the program hangs here, if i take away the part where settings are loaded it works fine (with default settings).

I've tried to use eewriteByte: ee.writeByte(eeAddress, (byte *)&Input[0], sizeof(DAC_Input));
but that didn't download. So i changed ee.writeByte to ee.writeBlock and now download is ok.


Code (in parts):

//DEFINES:

I2C_eeprom ee(0x50, I2C_DEVICESIZE_24LC256);

//Setup EEPROM adress
int eeAddress=0; // EEPROM address
int eeAddress1=0; // EEPROM address of Input 1 memory
int eeAddress2=128; // EEPROM address of Input 2 memory
int eeAddress3=256; // EEPROM address of Input 3 memory
int eeAddress4=384; // EEPROM address of Input 4 memory
int eeAddressS=1920; // EEPROM address of Settings memory

int EEPROM_STATUS=1;

struct DAC_Input
{
int filter_val; // Filter number.
int IIR_val; // IIR filter number.
int DPLLPCM1; // DPLL value for 768KHz.
int DPLLPCM2; // DPLL value for 705.6KHz.
int DPLLPCM3; // DPLL value for 384KHz.
int DPLLPCM4; // DPLL value for 352.8KHz or DoP 128.
int DPLLPCM5; // DPLL value for 192KHz.
int DPLLPCM6; // DPLL value for 176.4KHz or DoP 64.
int DPLLPCM7; // DPLL value for 96KHz.
int DPLLPCM8; // DPLL value for 88.2KHz.
int DPLLPCM9; // DPLL value for 48KHz.
int DPLLPCM10; // DPLL value for 44.1KHz.
int DPLLPCM11; // DPLL value for 32KHz.
int DPLLDSD1; // DPLL value for native DSD1024.
int DPLLDSD2; // DPLL value for native DSD512.
int DPLLDSD3; // DPLL value for native DSD256.
int DPLLDSD4; // DPLL value for native DSD128.
int DPLLDSD5; // DPLL value for native DSD64.
int lockspeed_val; // Lock speed setting.
bool dither_val; // Dither enabled or disabled.
bool jitter_elim_val; // Jitter Eliminator enabled or disabled.
bool bypass_osf_val; // GAIN +18db
bool deemph_bypass_val; // De-emphasis enabled or disabled.
bool auto_deemph_val; // Auto de-emphasis enabled or disabled.
int deemph_sel_val; // De-emphasis filter selection.
};

// Structure that holds the DAC's general settings.
struct DAC_Settings
{
bool variable; // Variable or fixed output.
int preamp_def_vol; //Ta bort 70 Default power-on volume when set for variable output.
int backlight; // TFT backlight value.
};


//SETUP:

Wire.begin(); // Join The I2C Bus As A Master

// Start communication with the I2C EEPROM chip
ee.begin();
if (! ee.isConnected())
{
EEPROM_STATUS=0;
}


HERE THE CODE HANG... IF ALL LOAD INPUT IS REMOVED PROGRAMS RUNS!!!

// Load Input_1 settings from EEPROM
eeAddress = eeAddress1;
byte *pData = (byte*)&Input[0];
ee.readBlock(eeAddress, pData, sizeof(DAC_Input));


// Load Input_2 settings from EEPROM
eeAddress = eeAddress2;
byte *pData2 = (byte*)&Input[1];
ee.readBlock(eeAddress, pData2, sizeof(DAC_Input));


// Load Input_3 settings from EEPROM
eeAddress = eeAddress3;
byte *pData3 = (byte*)&Input[2];
ee.readBlock(eeAddress, pData3, sizeof(DAC_Input));

// Load Input_4 settings from EEPROM
eeAddress = eeAddress4;
byte *pData4 = (byte*)&Input[3];
ee.readBlock(eeAddress, pData4, sizeof(DAC_Input));


// Load Settings1 from EEPROM
eeAddress = eeAddressS;
byte *pSettings = (byte*)&Settings1;
ee.readBlock(eeAddress, pSettings, sizeof(DAC_Settings));

Void savetoEEPROM()
{
if ((input == 0) && ((select1Mode==true) || (do_select_filter == true) || (selectDPLLMode==true))) // If saving Input 1
{
eeAddress=eeAddress1; // Address of Input 1 settings
Input[0].filter_val=filter;
Input[0].IIR_val=IIR;
Input[0].lockspeed_val=LockSpeed;
Input[0].dither_val=Dither;
Input[0].jitter_elim_val=JitterElim;
Input[0].bypass_osf_val=bypass_osf;
Input[0].deemph_bypass_val=deemph_bypass;
Input[0].auto_deemph_val=auto_deemph;
Input[0].deemph_sel_val=deemph_sel;
ee.writeBlock(eeAddress, (byte *)&Input[0], sizeof(DAC_Input)); // write to EEPROM

}

else if ((input == 1) && ((select1Mode==true) || (do_select_filter == true) || (selectDPLLMode==true))) // If saving Input 2
{
eeAddress=eeAddress2; // Address of Input 2 settings
Input[1].filter_val=filter;
Input[1].IIR_val=IIR;
Input[1].lockspeed_val=LockSpeed;
Input[1].dither_val=Dither;
Input[1].jitter_elim_val=JitterElim;
Input[1].bypass_osf_val=bypass_osf;
Input[1].deemph_bypass_val=deemph_bypass;
Input[1].auto_deemph_val=auto_deemph;
Input[1].deemph_sel_val=deemph_sel;
ee.writeBlock(eeAddress, (byte *)&Input[1], sizeof(DAC_Input)); // write to EEPROM

}

else if ((input == 2) && ((select1Mode==true) || (do_select_filter == true) || (selectDPLLMode==true))) // If saving Input 3
{
eeAddress=eeAddress3; // Address of Input 3 settings
Input[2].filter_val=filter;
Input[2].IIR_val=IIR;
Input[2].lockspeed_val=LockSpeed;
Input[2].dither_val=Dither;
Input[2].jitter_elim_val=JitterElim;
Input[2].bypass_osf_val=bypass_osf;
Input[2].deemph_bypass_val=deemph_bypass;
Input[2].auto_deemph_val=auto_deemph;
Input[2].deemph_sel_val=deemph_sel;
ee.writeBlock(eeAddress, (byte *)&Input[2], sizeof(DAC_Input)); // write to EEPROM

}
else if ((input == 3) && ((select1Mode==true) || (do_select_filter == true) || (selectDPLLMode==true))) // If saving Input 4
{
eeAddress=eeAddress4; // Address of Input 4 settings
Input[3].filter_val=filter;
Input[3].IIR_val=IIR;
Input[3].lockspeed_val=LockSpeed;
Input[3].dither_val=Dither;
Input[3].jitter_elim_val=JitterElim;
Input[3].bypass_osf_val=bypass_osf;
Input[3].deemph_bypass_val=deemph_bypass;
Input[3].auto_deemph_val=auto_deemph;
Input[3].deemph_sel_val=deemph_sel;
ee.writeBlock(eeAddress, (byte *)&Input[3], sizeof(DAC_Input)); // write to EEPROM

}
else if (select2Mode==true) // If saving Settings
{
eeAddress=eeAddressS; // Address of Settings1

Settings1.variable=preamp; // Store default variable setting to EEPROM

Settings1.preamp_def_vol=preamp_def_vol; // Store default preamp volume setting to EEPROM

Settings1.backlight=backlight; // Store default TFT backlight setting to EEPROM
ee.writeBlock(eeAddress, (byte *)&Settings1, sizeof(DAC_Settings)); // write to EEPROM

}

}

Anyone have any ide how to solve it?

BR// Daniel
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: Blue pill with external EEPROM

Post by GonzoG »

1. use [ code][ /code] for posting code.
2. post full code as without it it's hard or impossible to tell where you made a mistake.
Green77
Posts: 11
Joined: Mon Aug 15, 2022 7:28 am

Re: Blue pill with external EEPROM

Post by Green77 »

Hello and thanks for the help.

I did try to paste code here but prog to big.

@GonzoG Can i send a link to you with PM?

BR// Daniel
ozcar
Posts: 143
Joined: Wed Apr 29, 2020 9:07 pm
Answers: 5

Re: Blue pill with external EEPROM

Post by ozcar »

Green77 wrote: Fri Aug 19, 2022 5:05 am I did try to paste code here but prog to big.
That is probably a clue that you should try to recreate the problem with something much smaller. Just try to write something to the EEPROM and read it back maybe.
GonzoG
Posts: 403
Joined: Wed Jan 15, 2020 11:30 am
Answers: 27
Location: Prudnik, Poland

Re: Blue pill with external EEPROM

Post by GonzoG »

Green77 wrote: Fri Aug 19, 2022 5:05 am @GonzoG Can i send a link to you with PM?
I think you can... It it's not that hard... (;
User avatar
fpiSTM
Posts: 1738
Joined: Wed Dec 11, 2019 7:11 pm
Answers: 91
Location: Le Mans
Contact:

Re: Blue pill with external EEPROM

Post by fpiSTM »

Do you have pullup on each I2C lines?
Green77
Posts: 11
Joined: Mon Aug 15, 2022 7:28 am

Re: Blue pill with external EEPROM

Post by Green77 »

Hello.

Yes i have pullups on both lines.

I did as you adviced and made a small program just to store a value in eeprom. I used extEEPROM.h.
Worked perfectly so now i know that extEEPROM can be used.

When i think about it both I2C_EEPROM and extEEPROM hangs at the same time in program. That’s when setting are to be loaded.

BR// Daniel
Post Reply

Return to “STM boards (Discovery, Eval, Nucleo, ...)”