Skip to main content
Apill
Associate III
Aug 24, 2019 10:54 AM UTC
Solved

how to read a data array from EEPROM AT24C256B

I have configured my ADC to convert an analog value every 100 milli seconds using timer 2 , I could able to write data to EEPROM but while reading it back i could only see 20 variables in array.

As below mentioned in code, I could able to switch on my LED .

But my question is why I could not able to display/read all the 50 variables in my array in my watch windows of keil MDK?

However, i can only read till 20 variables (data_read[20])!

what could be the possible reasons?? I couldnt able to comprehend. is it because of the capabilities of Keil / ST link V2 debugging or because of the functions i am using to read EEPROM.

As per the below code and output i.e, I could set( switch on My led) I am with a hypothesis that, data is written into EEPROM , I am only facing problem of reading all the 50 variables in array because of debugging capabilities of software and hardware ? Am I correct or wrong? Could some one please validate?

code ( I have kept only the essential lines):

uint8_t data_read[50], data_write[50];

uint8_t adc_value[60],inc=0;

while (1)

 {

  /* USER CODE END WHILE */

if(inc==50)

{

for(int i=0;i<=51;i++)

{

data_write[i]=adc_value[i];

}

HAL_I2C_Mem_Write(&hi2c1,0xA0, 0x1AAA,I2C_MEMADD_SIZE_16BIT,data_write,50,HAL_MAX_DELAY);

while(HAL_I2C_IsDeviceReady(&hi2c1, 0xA0, 1, HAL_MAX_DELAY) != HAL_OK);

if((HAL_I2C_Mem_Read(&hi2c1,0xA1, 0x1AAA,I2C_MEMADD_SIZE_16BIT,data_read, 50, HAL_MAX_DELAY))== HAL_OK)

{

HAL_GPIO_WritePin(GPIOC,GPIO_PIN_9,GPIO_PIN_SET);

}

}

void HAL_ADC_ConvCpltCallback(ADC_HandleTypeDef* hadc)

{

 /* Prevent unused argument(s) compilation warning */

 UNUSED(hadc);

adc_value[inc]=HAL_ADC_GetValue(hadc);

inc++;

if(inc==70)

{

HAL_ADC_Stop_IT(hadc);

}

    This topic has been closed for replies.
    Apill
    ApillBest answer
    Associate III
    Aug 25, 2019 5:30 AM UTC

    I solved it, I tried to write and read starting from 0x1AAA memory location, after i have changed the memory location to 0x0000 i could able to read/display all the values in my watch windows. I guess i have tried to read from two different "Pages" so it couldnt able to display data from other pages!

    4 replies

    Tesla DeLorean
    Guru
    Aug 24, 2019 11:19 AM UTC

    Don't copy 52 elements into a 50 element array.

    Check content, and printf diagnostic data or dump.​

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Apill
    ApillAuthorBest answer
    Associate III
    Aug 25, 2019 5:30 AM UTC

    I solved it, I tried to write and read starting from 0x1AAA memory location, after i have changed the memory location to 0x0000 i could able to read/display all the values in my watch windows. I guess i have tried to read from two different "Pages" so it couldnt able to display data from other pages!

    S.Ma
    Principal
    Aug 25, 2019 2:53 AM UTC

    Watch window = debugger settings.

    It's usually adjustable. If not, slice your buffer in 2 dimension array. Get creative in workarounds to go on rather than wait long for help, if time is of the essence.

    Piranha
    Principal III
    Aug 25, 2019 7:13 AM UTC

    And also You've been here for at least almost a year - learn to use Code Snippet button when posting code!